Skip to content

Commit 101f962

Browse files
SteveAmorJF002
authored andcommitted
Refactor pageindicator
1 parent e33a83a commit 101f962

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

src/displayapp/widgets/PageIndicator.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ void PageIndicator::Create() {
1616
lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
1717
lv_obj_set_style_local_line_color(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, Colors::bgDark);
1818
lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints, 2);
19+
SetPageIndicatorPosition(nCurrentScreen);
20+
}
1921

22+
void PageIndicator::SetPageIndicatorPosition(uint8_t position) {
2023
const int16_t indicatorSize = LV_VER_RES / nScreens;
21-
const int16_t indicatorPos = indicatorSize * nCurrentScreen;
24+
const int16_t indicatorPos = indicatorSize * position;
2225

2326
pageIndicatorPoints[0].x = LV_HOR_RES - 1;
2427
pageIndicatorPoints[0].y = indicatorPos;
@@ -31,13 +34,7 @@ void PageIndicator::Create() {
3134
lv_line_set_points(pageIndicator, pageIndicatorPoints, 2);
3235
}
3336

34-
void PageIndicator::Delete() {
35-
lv_obj_del(pageIndicatorBase);
36-
lv_obj_del(pageIndicator);
37-
}
38-
3937
void PageIndicator::SetCurrentScreen(uint8_t nScreen) {
40-
Delete();
41-
nCurrentScreen = nScreen;
42-
Create();
38+
lv_obj_del(pageIndicator);
39+
SetPageIndicatorPosition(nScreen);
4340
}

src/displayapp/widgets/PageIndicator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ namespace Pinetime {
88
public:
99
PageIndicator(uint8_t nCurrentScreen, uint8_t nScreens);
1010
void Create();
11-
void Delete();
1211
void SetCurrentScreen(uint8_t nScreen);
1312

1413
private:
14+
void SetPageIndicatorPosition(uint8_t position);
1515
uint8_t nCurrentScreen;
1616
uint8_t nScreens;
1717

0 commit comments

Comments
 (0)