Refactor main menu functionality and state handling#205
Open
Refactor main menu functionality and state handling#205
Conversation
Contributor
|
I have been experimenting with multiple ways to simplify menus, I have nothing nearly "done" but I think this is a step forward.
|
khenderick
approved these changes
Jan 2, 2023
Contributor
khenderick
left a comment
There was a problem hiding this comment.
Works fine, and I think it's a step in the right direction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is my proposal how to refactor/reimplement the main menu functionality and state handling.
The aim is to simplify the code structure, avoid duplicate code and allow better extensibility. But also, to make menu flows easier to follow and isolate state handling within certain menu rather than handling all possible states at
handleButtonPress().Main changes:
showMenu()andshowFastMenu()are replaced byshowMainMenu()andgetMenuSelection()methods. InshowMainMenu()we define the elements needed for the main menu and handle its flow based on the user selection.getMenuSelection()serves as a generic method for creating menus and can be easily used for creating new submenus etc. Button inputs and menu specific timeout value are handled insidegetMenuSelection(). In case of main menu, at timeout we get out of the menu and handle flow after inshowMainMenu().handleButtonPress()isn't handling states anymore, for now we only wake up from menu button and go to main menu.Going into apps sets
APP_STATE, which also defines how the flow after the app goes. InshowMainMenu()we go back to main menu fromAPP_STATEor toWATCHFACE_STATEif going back because of timeout or back button. SinceAPP_STATEdefines the flow after the app is done, we don't have to callshowMainMenu()every time we should go back to main menu from app.Term
menuused in global variables is changed tomainMenuto be more clear and not to confuse with other menus in the future.State
FW_UPDATE_STATEis removed sinceAPP_STATEcan be used as well.Firmware update app shows example of submenu flow where button inputs inside a menu define what happens next, e.g. do we go forward within the app or go back to main menu.
RTC alarm wakeup handles only
WATCHFACE_STATEsince we never stay in the main menu because of timeout.Global
MENU_LENGTHis removed since menu length is menu specific and has to be given togetMenuSelection()as an argument.This is fairly big change but I haven't noticed anything being broken, any feedback is welcome! :)