Add PageIndicator widget to reduce code duplication (#1218)

* Move PageIndicator widget to its own files to reduce code duplication
* Use uint8_t in PageIndicator
This commit is contained in:
Riku Isokoski
2022-07-05 08:41:09 +03:00
committed by GitHub
parent c0770cde8a
commit ec8a845052
9 changed files with 70 additions and 90 deletions

View File

@@ -0,0 +1,31 @@
#include "displayapp/widgets/PageIndicator.h"
using namespace Pinetime::Applications::Widgets;
PageIndicator::PageIndicator(uint8_t nCurrentScreen, uint8_t nScreens) : nCurrentScreen {nCurrentScreen}, nScreens {nScreens} {
}
void PageIndicator::Create() {
pageIndicatorBasePoints[0].x = LV_HOR_RES - 1;
pageIndicatorBasePoints[0].y = 0;
pageIndicatorBasePoints[1].x = LV_HOR_RES - 1;
pageIndicatorBasePoints[1].y = LV_VER_RES;
pageIndicatorBase = lv_line_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
lv_obj_set_style_local_line_color(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111));
lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints, 2);
const int16_t indicatorSize = LV_VER_RES / nScreens;
const int16_t indicatorPos = indicatorSize * nCurrentScreen;
pageIndicatorPoints[0].x = LV_HOR_RES - 1;
pageIndicatorPoints[0].y = indicatorPos;
pageIndicatorPoints[1].x = LV_HOR_RES - 1;
pageIndicatorPoints[1].y = indicatorPos + indicatorSize;
pageIndicator = lv_line_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_line_width(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0));
lv_line_set_points(pageIndicator, pageIndicatorPoints, 2);
}

View File

@@ -0,0 +1,23 @@
#pragma once
#include <lvgl/lvgl.h>
namespace Pinetime {
namespace Applications {
namespace Widgets {
class PageIndicator {
public:
PageIndicator(uint8_t nCurrentScreen, uint8_t nScreens);
void Create();
private:
uint8_t nCurrentScreen;
uint8_t nScreens;
lv_point_t pageIndicatorBasePoints[2];
lv_point_t pageIndicatorPoints[2];
lv_obj_t* pageIndicatorBase;
lv_obj_t* pageIndicator;
};
}
}
}