Counter: add show and hide controls functions

This commit is contained in:
Riku Isokoski 2022-05-19 12:08:23 +03:00 committed by JF
parent 41c461d1f6
commit 4a40d29279
2 changed files with 21 additions and 2 deletions

View file

@ -40,6 +40,21 @@ void Counter::SetValue(int newValue) {
UpdateLabel();
}
void Counter::HideControls() {
lv_obj_set_hidden(upBtn, true);
lv_obj_set_hidden(downBtn, true);
lv_obj_set_hidden(upperLine, true);
lv_obj_set_hidden(lowerLine, true);
lv_obj_set_style_local_bg_opa(counterContainer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
}
void Counter::ShowControls() {
lv_obj_set_hidden(upBtn, false);
lv_obj_set_hidden(downBtn, false);
lv_obj_set_hidden(upperLine, false);
lv_obj_set_hidden(lowerLine, false);
lv_obj_set_style_local_bg_opa(counterContainer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER);
}
void Counter::UpdateLabel() {
lv_label_set_text_fmt(number, "%.2i", value);
}
@ -92,14 +107,14 @@ void Counter::Create() {
linePoints[0] = {0, 0};
linePoints[1] = {width, 0};
lv_obj_t* upperLine = lv_line_create(counterContainer, nullptr);
upperLine = lv_line_create(counterContainer, nullptr);
lv_line_set_points(upperLine, linePoints, 2);
lv_obj_set_style_local_line_width(upperLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 1);
lv_obj_set_style_local_line_color(upperLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_line_opa(upperLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20);
lv_obj_align(upperLine, upBtn, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
lv_obj_t* lowerLine = lv_line_create(counterContainer, nullptr);
lowerLine = lv_line_create(counterContainer, nullptr);
lv_line_set_points(lowerLine, linePoints, 2);
lv_obj_set_style_local_line_width(lowerLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 1);
lv_obj_set_style_local_line_color(lowerLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);

View file

@ -14,6 +14,8 @@ namespace Pinetime {
void Increment();
void Decrement();
void SetValue(int newValue);
void HideControls();
void ShowControls();
int GetValue() const {
return value;
@ -30,6 +32,8 @@ namespace Pinetime {
lv_obj_t* upBtn;
lv_obj_t* downBtn;
lv_obj_t* number;
lv_obj_t* upperLine;
lv_obj_t* lowerLine;
lv_point_t linePoints[2];
int value = 0;
int min;