From 72bc73606d042f83497e680ce79f28ac02532892 Mon Sep 17 00:00:00 2001 From: Steve Amor Date: Sun, 1 Dec 2024 20:17:02 +0000 Subject: [PATCH] Adds page indicator to music app --- src/displayapp/screens/Music.cpp | 14 ++++++++++---- src/displayapp/screens/Music.h | 4 ++++ src/displayapp/widgets/PageIndicator.cpp | 5 +++++ src/displayapp/widgets/PageIndicator.h | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/displayapp/screens/Music.cpp b/src/displayapp/screens/Music.cpp index 0763da0fe3..bf642aedb9 100644 --- a/src/displayapp/screens/Music.cpp +++ b/src/displayapp/screens/Music.cpp @@ -59,7 +59,7 @@ Music::Music(Pinetime::Controllers::MusicService& music) : musicService(music) { btnVolDown->user_data = this; lv_obj_set_event_cb(btnVolDown, event_handler); lv_obj_set_size(btnVolDown, 76, 76); - lv_obj_align(btnVolDown, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + lv_obj_align(btnVolDown, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 3, 0); lv_obj_add_style(btnVolDown, LV_STATE_DEFAULT, &btn_style); label = lv_label_create(btnVolDown, nullptr); lv_label_set_text_static(label, Symbols::volumDown); @@ -69,7 +69,7 @@ Music::Music(Pinetime::Controllers::MusicService& music) : musicService(music) { btnVolUp->user_data = this; lv_obj_set_event_cb(btnVolUp, event_handler); lv_obj_set_size(btnVolUp, 76, 76); - lv_obj_align(btnVolUp, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + lv_obj_align(btnVolUp, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, -3, 0); lv_obj_add_style(btnVolUp, LV_STATE_DEFAULT, &btn_style); label = lv_label_create(btnVolUp, nullptr); lv_label_set_text_static(label, Symbols::volumUp); @@ -79,7 +79,7 @@ Music::Music(Pinetime::Controllers::MusicService& music) : musicService(music) { btnPrev->user_data = this; lv_obj_set_event_cb(btnPrev, event_handler); lv_obj_set_size(btnPrev, 76, 76); - lv_obj_align(btnPrev, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + lv_obj_align(btnPrev, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 3, 0); lv_obj_add_style(btnPrev, LV_STATE_DEFAULT, &btn_style); label = lv_label_create(btnPrev, nullptr); lv_label_set_text_static(label, Symbols::stepBackward); @@ -88,7 +88,7 @@ Music::Music(Pinetime::Controllers::MusicService& music) : musicService(music) { btnNext->user_data = this; lv_obj_set_event_cb(btnNext, event_handler); lv_obj_set_size(btnNext, 76, 76); - lv_obj_align(btnNext, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + lv_obj_align(btnNext, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, -3, 0); lv_obj_add_style(btnNext, LV_STATE_DEFAULT, &btn_style); label = lv_label_create(btnNext, nullptr); lv_label_set_text_static(label, Symbols::stepForward); @@ -127,6 +127,8 @@ Music::Music(Pinetime::Controllers::MusicService& music) : musicService(music) { lv_obj_set_width(txtTrack, LV_HOR_RES - 12); lv_label_set_text_static(txtTrack, "This is a very long getTrack name"); + page1Indicator.Create(); + /** Init animation */ imgDisc = lv_img_create(lv_scr_act(), nullptr); lv_img_set_src_arr(imgDisc, &disc); @@ -256,6 +258,8 @@ bool Music::OnTouchEvent(Pinetime::Applications::TouchEvents event) { lv_obj_set_hidden(btnNext, true); lv_obj_set_hidden(btnPrev, true); + page1Indicator.Delete(); + page2Indicator.Create(); return true; } case TouchEvents::SwipeDown: { @@ -264,6 +268,8 @@ bool Music::OnTouchEvent(Pinetime::Applications::TouchEvents event) { lv_obj_set_hidden(btnPrev, false); lv_obj_set_hidden(btnVolDown, true); lv_obj_set_hidden(btnVolUp, true); + page2Indicator.Delete(); + page1Indicator.Create(); return true; } return false; diff --git a/src/displayapp/screens/Music.h b/src/displayapp/screens/Music.h index 522533215b..cc4a37459b 100644 --- a/src/displayapp/screens/Music.h +++ b/src/displayapp/screens/Music.h @@ -21,6 +21,7 @@ #include #include #include "displayapp/screens/Screen.h" +#include "displayapp/widgets/PageIndicator.h" #include "displayapp/apps/Apps.h" #include "displayapp/Controllers.h" #include "Symbols.h" @@ -82,6 +83,9 @@ namespace Pinetime { lv_task_t* taskRefresh; + Widgets::PageIndicator page1Indicator = Widgets::PageIndicator(0, 2); + Widgets::PageIndicator page2Indicator = Widgets::PageIndicator(1, 2); + /** Watchapp */ }; } diff --git a/src/displayapp/widgets/PageIndicator.cpp b/src/displayapp/widgets/PageIndicator.cpp index 84d03e7ed0..a7bcc53fd3 100644 --- a/src/displayapp/widgets/PageIndicator.cpp +++ b/src/displayapp/widgets/PageIndicator.cpp @@ -30,3 +30,8 @@ void PageIndicator::Create() { lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); lv_line_set_points(pageIndicator, pageIndicatorPoints, 2); } + +void PageIndicator::Delete() { + lv_obj_del(pageIndicatorBase); + lv_obj_del(pageIndicator); +} diff --git a/src/displayapp/widgets/PageIndicator.h b/src/displayapp/widgets/PageIndicator.h index 8484735e58..cc9d2088ba 100644 --- a/src/displayapp/widgets/PageIndicator.h +++ b/src/displayapp/widgets/PageIndicator.h @@ -8,6 +8,7 @@ namespace Pinetime { public: PageIndicator(uint8_t nCurrentScreen, uint8_t nScreens); void Create(); + void Delete(); private: uint8_t nCurrentScreen;