Skip to content

Conversation

@SteveAmor
Copy link
Contributor

Fixes #1391

@github-actions
Copy link

github-actions bot commented Oct 4, 2023

Build size and comparison to main:

Section Size Difference
text 380180B 48B
data 944B 0B
bss 22544B 0B

Run in InfiniEmu

@SteveAmor
Copy link
Contributor Author

InfiniSim_2023-10-04_202308

@minacode
Copy link
Contributor

minacode commented Oct 4, 2023

I imagine it could look a little better with a little margin around the buttons. What do you think?

@SteveAmor
Copy link
Contributor Author

The page indicator is 2px wide.
However, if I move the buttons 3px, it conveniently has a 3px space between the play/pause button too, making it nice and symmetrical.
What do people think?

InfiniSim_2023-10-05_080028

For comparison, here are the buttons moved 2px

2px

@minacode
Copy link
Contributor

minacode commented Oct 5, 2023

I like the first image where the bar is not touching the button.

@SteveAmor
Copy link
Contributor Author

PR updated to move the buttons 3px.

@SteveAmor
Copy link
Contributor Author

I experimented with hiding or deleting the page indicator object when you switch pages. According to the simulator, hiding the object used more lvgl memory than deleting and creating. So I went with deleting. I guess it used more memory as you actually had more objects at any one time, with one of them hidden.

@LinuxinaBit LinuxinaBit mentioned this pull request Nov 9, 2023
@SteveAmor SteveAmor force-pushed the musicpageindicator branch 2 times, most recently from b3b9a27 to 72bc736 Compare December 1, 2024 20:23
@SteveAmor SteveAmor changed the title Adds scroll bar to music app Adds page indicator to music app Dec 1, 2024
@mark9064 mark9064 added this to the 1.16.0 milestone Dec 2, 2024
@mark9064 mark9064 added the enhancement Enhancement to an existing app/feature label Dec 2, 2024
@mark9064
Copy link
Member

mark9064 commented Jul 5, 2025

I experimented with hiding or deleting the page indicator object when you switch pages. According to the simulator, hiding the object used more lvgl memory than deleting and creating. So I went with deleting. I guess it used more memory as you actually had more objects at any one time, with one of them hidden.

Just thinking, would it make more sense to have a SetCurrentScreen() method for pageindicator so that you only need to store one instance of the pageindicator object too?

@SteveAmor SteveAmor force-pushed the musicpageindicator branch from 12637b1 to 90601f6 Compare July 6, 2025 13:33
@SteveAmor
Copy link
Contributor Author

SteveAmor commented Jul 8, 2025

I remember now. Music.cpp doesn't have more than one page. It has a single page and hides/unhides buttons to make it look like two pages. This is the reason I went down this route. Perhaps the best thing to do (which is what I did originally) is to hide and unhide two page indicators?

@SteveAmor
Copy link
Contributor Author

I experimented with hiding or deleting the page indicator object when you switch pages. According to the simulator, hiding the object used more lvgl memory than deleting and creating. So I went with deleting. I guess it used more memory as you actually had more objects at any one time, with one of them hidden.

Just thinking, would it make more sense to have a SetCurrentScreen() method for pageindicator so that you only need to store one instance of the pageindicator object too?

I think that already exists:

PageIndicator(uint8_t nCurrentScreen, uint8_t nScreens)

But won't work for Music.cpp single page with hidden buttons for the "second page".

@mark9064
Copy link
Member

mark9064 commented Jul 10, 2025

What I'm suggesting is a new method for PageIndicator that tears down the existing one and redraws at a different position. This way you'd only have one page indicator as a member of the app and you could do pageIndicator.SetCurrentScreen(x) whenever you wanted to move it, rather than having two and having to create/delete or hide/unhide

@SteveAmor
Copy link
Contributor Author

@mark9064 hopefully this implementation of SetCurrentScreen is what you had in mind? Please let me know :-)

@minacode
Copy link
Contributor

Inside it, LVGL objects are created and dropped. Is that a good idea? Would it be better to create a function Refresh which can reset some of the properties of those objects based on the widgets attributes and call that instead and never use Delete? I imagine that this may take some work off the LVGL heap, but am not perfectly sure how it works internally.

@SteveAmor
Copy link
Contributor Author

Inside it, LVGL objects are created and dropped. Is that a good idea? Would it be better to create a function Refresh which can reset some of the properties of those objects based on the widgets attributes and call that instead and never use Delete? I imagine that this may take some work off the LVGL heap, but am not perfectly sure how it works internally.

I'm certainly no expert but having looked at the pageindicator code, I can't see an easy way to update some of the properties. If not all of them. Any guidance would be much appreciated.
I've tried to ballance the additional code space required with the functionality of a page indicator.
To fit in with the pattern the Music page(s) uses, I'm very much tending towards my original thought (and test) of having two page indicators and hiding/unhiding them.
From a UI point of view, I hadn't realised that you can also skip tracks back and forwards by swiping left and right!

@mark9064
Copy link
Member

Well I think the current implementation is pretty fine

But if you wanted to be more efficient, pull out

  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;
  
  lv_line_set_points(pageIndicator, pageIndicatorPoints, 2);

to a different method (eg SetPageIndicatorPosition(u8 position)) and then call that at the end of Create, and directly from the code here.

This works as you can leave the background stripe, and only want to move the highlight (current position indicator) stripe.

@SteveAmor SteveAmor force-pushed the musicpageindicator branch 2 times, most recently from 9cfe584 to 2ac8a00 Compare July 18, 2025 17:44
@SteveAmor SteveAmor force-pushed the musicpageindicator branch from 2ac8a00 to d7370ab Compare July 18, 2025 17:46
@SteveAmor
Copy link
Contributor Author

Well I think the current implementation is pretty fine

But if you wanted to be more efficient, pull out

  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;
  
  lv_line_set_points(pageIndicator, pageIndicatorPoints, 2);

to a different method (eg SetPageIndicatorPosition(u8 position)) and then call that at the end of Create, and directly from the code here.

This works as you can leave the background stripe, and only want to move the highlight (current position indicator) stripe.

All done :-)

@mark9064
Copy link
Member

If you move

  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, Colors::lightGray);

to Create(), then you don't need an extra method at all as you won't be deleting the existing page indicator, instead it'll only be moved

@SteveAmor
Copy link
Contributor Author

If you move

  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, Colors::lightGray);

to Create(), then you don't need an extra method at all as you won't be deleting the existing page indicator, instead it'll only be moved

My bad, I should have noticed that in your earlier message. This (hopefully final) commit is the most efficient in terms of additional program memory required and it certainly (looks to me) cleaner than previous commits.

@SteveAmor
Copy link
Contributor Author

@mark9064 could you please double check that I have declared everything that I need to, correctly, in PageIndicator.h

Copy link
Member

@mark9064 mark9064 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All LGTM :)

@tituscmd
Copy link
Contributor

Would be superseded by #2337 if merged

@minacode
Copy link
Contributor

I would argue that we still merge this, because it's ready and easy to do. And then we discuss your version 2 on top of that. Do you agree, @mark9064?

@mark9064
Copy link
Member

Yep, sounds good to me. Once this has a second review I'm happy to merge :)

Copy link
Collaborator

@JF002 JF002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Contributor

@NeroBurner NeroBurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JF002 JF002 merged commit 04afd22 into InfiniTimeOrg:main Nov 4, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement to an existing app/feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Scroll Bar to the Music App

6 participants