Skip to content

Commit

Permalink
Fixed selected item on back
Browse files Browse the repository at this point in the history
  • Loading branch information
ERSUCC committed Aug 8, 2024
1 parent 098eab4 commit 5222f2d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
14 changes: 14 additions & 0 deletions scenes/insults_scene_saved.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ void insults_scene_saved_on_enter(void* context) {
insults_app);
}

unsigned int index =
scene_manager_get_scene_state(insults_app->scene_manager, InsultsSceneSaved);

if(index >= insults_app->saved_lines->num_lines) {
submenu_set_selected_item(
insults_app->saved_menu, insults_app->saved_lines->num_lines - 1);
}

else {
submenu_set_selected_item(insults_app->saved_menu, index);
}

view_dispatcher_switch_to_view(insults_app->view_dispatcher, InsultsViewSaved);
}

Expand All @@ -26,6 +38,8 @@ bool insults_scene_saved_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
insults_app->insult_string = strdup(insults_app->saved_lines->lines[event.event]);

scene_manager_set_scene_state(insults_app->scene_manager, InsultsSceneSaved, event.event);

scene_manager_next_scene(insults_app->scene_manager, InsultsSceneSavedDetail);

return true;
Expand Down
3 changes: 2 additions & 1 deletion scenes/insults_scene_saved_detail.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ void insults_scene_saved_detail_dialog_callback(DialogExResult result, void* con

if(result == DialogExResultLeft) {
insults_files_delete_insult(
insults_app->insults_files, submenu_get_selected_item(insults_app->saved_menu));
insults_app->insults_files,
scene_manager_get_scene_state(insults_app->scene_manager, InsultsSceneSaved));

scene_manager_handle_back_event(insults_app->scene_manager);
}
Expand Down
1 change: 0 additions & 1 deletion scenes/insults_scene_saved_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <gui/scene_manager.h>
#include <gui/view_dispatcher.h>
#include <gui/modules/dialog_ex.h>
#include <gui/modules/submenu.h>
#include <storage/storage.h>

#include "../insults_app.h"
Expand Down
7 changes: 7 additions & 0 deletions scenes/insults_scene_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ bool insults_scene_start_on_event(void* context, SceneManagerEvent event) {

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == InsultsSceneStartIndexNew) {
scene_manager_set_scene_state(
insults_app->scene_manager, InsultsSceneStart, event.event);

scene_manager_next_scene(insults_app->scene_manager, InsultsSceneInsult);

return true;
}

if(event.event == InsultsSceneStartIndexSaved) {
scene_manager_set_scene_state(
insults_app->scene_manager, InsultsSceneStart, event.event);
scene_manager_set_scene_state(insults_app->scene_manager, InsultsSceneSaved, 0);

scene_manager_next_scene(insults_app->scene_manager, InsultsSceneSaved);

return true;
Expand Down

0 comments on commit 5222f2d

Please sign in to comment.