-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gui: Submenu and VarItemList API additions and improvements #3621
base: dev
Are you sure you want to change the base?
Conversation
API additions: - `submenu_add_lockable_item()`: based on flipperdevices#2289 which was rejected, CFWs merged it and improved it over time, theres a few apps that use it by now (example usecase: highlighting that some features are not available in current configuration / state) - `submenu_set_orientation()`: can have vertical submenu (user's preference for ux, same concept works great in infrared app, could be reused there to make more of the app vertical instead of having to keep switching) - `variable_item_list_get()`: get and allow editing an item after creation (example usecase: editing one option changes state of other entries in the list, like if they are locked due to incompatible settings or if they have different labels or values) - `variable_item_list_set_header()`: feature parity with `submenu` widget (example usecase: headers are pretty but want editable options not just a list) - `variable_item_set_item_label()`: allow changing label after adding item (example usecase: want to show index of item, can have value shown and put (1/10) in label dynamically, also probably more, allows more creativity) - `variable_item_set_locked()`: same as above for `submenu`, based on same code but ported to varitemlist by me. also allows setting locked state after the fact, remembers locked message so after creation you can toggle with `set_locked(item, false/true, NULL)` (example usecase, some settings combinations in this screen are incompatible, like GPIO pins overlapping when configuring) General improvements: - Can have header in Variable Item List - Can have a vertical Submenu - Can lock items in Variable Item List and Submenu - Variable Item List label and value scroll if too long - Variable Item List value arrows shrink if value is < 4 characters - More freedom and usefulness in Variable Item List API - Cleaned up some parts of the code and some magic numbers are now defined Acknowlegments: - Original submenu lockable items code by @giacomoferretti in flipperdevices#2289 - Vertical submenu and some code improvements by Unleashed CFW team - Most other edits by me @Willy-JL - Hope I'm not forgetting someone else that was involved
This is in response to developer frustration with inconsistent APIs first-hand from @zacharyweiss when recently updating his Magspoof app, as well as discussion with @skotopes about differences between forks' APIs. As the lead maintainer of one such fork I've developed a decent amount for Flipper in the last year, some of which resides in additional APIs which I deemed useful. My past with the great people of OFW has been rocky to say the least but I wish to help the community and this wonderful project in whatever way I can, and while backporting all of the custom features would mean my fork wouldn't have a purpose anymore, I think (and aku seems to agree) that atleast having a consistent API would be a great start. This is some of that, but I'm planning to go through the rest too. One step at a time ) That being said, I'm aware of the comments made for example in #2289 about wanting a small and simple toolkit, and some (if not all) the changes in this PR would go against that wish. I simply ported and cleaned up the most developed submenu and varitemlist implementations that I'm aware of, then we can discuss here which parts (if any) would fit OFW's philosophy. I also just realized that there's a few more things that could be added, namely:
|
I noticed that I had ported without the centering for varitemlist value text, so it was messed up. Added the extra elements APIs, one of which was needed for centered scrolling text in varitemlist value text. Again, this is to port over APIs in hopes of making them consistent across forks, but I totally understand if you don't think these belong in OFW |
Is it possible to split it into separate features? I'm ready to merge some parts immediately and some I'd like to discuss more. |
@skotopes sure I can do that, which parts should I split? |
FuriString* string, | ||
size_t scroll, | ||
bool ellipsis, | ||
bool centered) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about calling it elements_scrollable_text_line_centered
and instead of bool centered
accept Align?
if(ellipsis) { | ||
width -= canvas_string_width(canvas, "..."); | ||
} | ||
|
||
// Calculate scroll size | ||
size_t scroll_size = furi_string_size(line); | ||
size_t right_width = 0; | ||
for(size_t i = scroll_size; i > 0; i--) { | ||
for(size_t i = scroll_size - 1; i > 0; i--) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and if line is empty?
submenu_add_lockable_item(submenu, label, index, callback, callback_context, false, NULL); | ||
} | ||
|
||
void submenu_add_lockable_item( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not to have setter to lock item? in that way there will be no need for special constructor?
@@ -391,3 +490,45 @@ void submenu_set_header(Submenu* submenu, const char* header) { | |||
}, | |||
true); | |||
} | |||
|
|||
void submenu_set_orientation(Submenu* submenu, ViewOrientation orientation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally orientation is controlled by underlying view. Basically you can change view orientation and then use canvas info to match orientation.
Sorry for keeping you waiting. I've left some comments regarding APIs. Other than that I'd like to see this PR being split:
|
What's new
General improvements:
API additions (no removals, fully backwards compatible):
submenu_add_lockable_item()
:submenu_set_orientation()
:variable_item_list_get()
:---
when hopping is enabled, by storing the item pointer in scene state, this is also quite error prone, with varitemlist get() it would be safer and clearervariable_item_list_set_header()
:submenu
widgetvariable_item_set_item_label()
:get()
variable_item_set_locked()
:submenu
, based on same code but ported to varitemlist by meset_locked(item, false/true, NULL)
Acknowlegments:
Verification
Check apps that use variable item list and submenu to be working correctly
No dedicated example app for additional APIs but some apps do use them, for example:
Checklist (For Reviewer)