flipperzero-rs / flipperzero

Rust on the Flipper Zero
MIT License
499 stars 32 forks source link

Scene Management & Menu's example #136

Closed ASoldo closed 6 months ago

ASoldo commented 6 months ago

Hi,

I'm currently working on a project using FZ sample apps as a reference, and I've encountered a challenge with scene management and creating menus. Despite studying the source code of these apps written in C, I'm having difficulty understanding how scenes are structured, how menus are implemented, and how to manage the flow between different scenes.

My goal is to develop an application with four distinct screens:

HomeScreen: Contains an "Ok" button that transitions to the next screen. Menu Screen: Features two buttons, each leading to a separate scene. Scene1: Displays the simple text "Scene1". Scene2: Displays the simple text "Scene2".

I'm familiar with creating a single scene, but I'm unsure about how to expand this into full scene management to allow for seamless navigation through the app. Specifically, I want to enable users to move between screens using "OK" and "back" buttons, with the ability to exit the application only from the HomeScreen. Any other screen should return the user to the previous screen.

In the C examples I've reviewed, there's typically a scenes/ folder containing separate .c and .h files for each scene. I'd like to adopt a similar structure for my project, which is in Rust, something like:

src/
- scenes/
  -- home-screen.rs
  -- main-menu.rs 
  -- scene1.rs
  -- scene2.rs
  -- mod.rs
- main.rs

Although I've seen examples covering scene management and menus/submenus, they are often deeply intertwined with complex C code, making it hard for me to extract the parts relevant to my needs.

Could anyone provide a simplified example or guidance on how to handle scene management and menus for my project in Rust? Any help would be greatly appreciated as it would significantly aid my learning process.