Skip to content

Commit

Permalink
Merge pull request #25 from leedave/feature/addTextNumberInputs
Browse files Browse the repository at this point in the history
Feature/add text number inputs
  • Loading branch information
leedave authored Aug 22, 2024
2 parents d2cdc43 + d198b9b commit 994f979
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Use this code as a foundation for developing Flipper Zero Applications, change t
- Menu
- Button Menu
- File Browser
- Text Input
- Number Input
- Different Scenes / Views
- Settings Page (On/Off for haptics, sound, led)
- Handling of Button Inputs
Expand Down
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ App(
fap_icon="icons/boilerplate_10px.png",
fap_icon_assets="icons",
fap_category="Misc",
fap_version="1.2",
fap_version="1.3",
)
18 changes: 18 additions & 0 deletions boilerplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ Boilerplate* boilerplate_app_alloc() {
BoilerplateViewIdSettings,
variable_item_list_get_view(app->variable_item_list));

app->text_input = text_input_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
BoilerplateViewIdTextInput,
text_input_get_view(app->text_input));

app->number_input = number_input_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
BoilerplateViewIdNumberInput,
number_input_get_view(app->number_input));

//End Scene Additions

return app;
Expand All @@ -105,6 +117,12 @@ void boilerplate_app_free(Boilerplate* app) {
boilerplate_scene_2_free(app->boilerplate_scene_2);
boilerplate_startscreen_free(app->boilerplate_startscreen);

view_dispatcher_remove_view(app->view_dispatcher, BoilerplateViewIdNumberInput);
number_input_free(app->number_input);

view_dispatcher_remove_view(app->view_dispatcher, BoilerplateViewIdTextInput);
text_input_free(app->text_input);

view_dispatcher_free(app->view_dispatcher);

furi_record_close(RECORD_GUI);
Expand Down
15 changes: 11 additions & 4 deletions boilerplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include <gui/scene_manager.h>
#include <gui/modules/variable_item_list.h>
#include <gui/modules/button_menu.h>
#include <gui/modules/dialog_ex.h>
#include <gui/modules/number_input.h>
#include <gui/modules/text_input.h>
#include "scenes/boilerplate_scene.h"
#include "views/boilerplate_startscreen.h"
#include "views/boilerplate_scene_1.h"
Expand All @@ -24,7 +25,9 @@

#define SUBGHZ_APP_EXTENSION ".sub"
#define SUBGHZ_APP_FOLDER ANY_PATH("subghz")
#define BOILERPLATE_VERSION "1.2"
#define BOILERPLATE_VERSION "1.3"
#define BOILERPLATE_TEXT_STORE_SIZE 128
#define BOILERPLATE_TEXT_STORE_COUNT 3

typedef struct {
Gui* gui;
Expand All @@ -43,6 +46,10 @@ typedef struct {
uint32_t led;
uint32_t save_settings;
ButtonMenu* button_menu; // Button Menu
NumberInput* number_input;
int32_t current_number;
TextInput* text_input;
char text_store[BOILERPLATE_TEXT_STORE_COUNT][BOILERPLATE_TEXT_STORE_SIZE + 1];
} Boilerplate;

typedef enum {
Expand All @@ -51,8 +58,8 @@ typedef enum {
BoilerplateViewIdScene1,
BoilerplateViewIdScene2,
BoilerplateViewIdScene3,
BoilerplateViewIdScene4,
BoilerplateViewIdScene5,
BoilerplateViewIdTextInput,
BoilerplateViewIdNumberInput,
BoilerplateViewIdSettings,
} BoilerplateViewId;

Expand Down
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Boilerplate for a Flipper Zero application, you can use this code as a starting
- Menu
- Button Menu
- File Browser
- Text Input
- Number Input
- Different Scenes / Views
- Settings Page (On/Off for haptics, sound, led)
- Handling of Button Inputs
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.3
- Requires version 0.105.0 or higher (or fw based on version)
- Added Text Input Example
- Added Number Input Example

## 1.2
- Added fixed to clear furi_string on storage if things fail (found by derskythe)

Expand Down
2 changes: 2 additions & 0 deletions scenes/boilerplate_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ ADD_SCENE(boilerplate, scene_1, Scene_1)
ADD_SCENE(boilerplate, scene_2, Scene_2)
ADD_SCENE(boilerplate, scene_3, Scene_3)
ADD_SCENE(boilerplate, scene_4, Scene_4)
ADD_SCENE(boilerplate, scene_5, Scene_5)
ADD_SCENE(boilerplate, scene_6, Scene_6)
ADD_SCENE(boilerplate, settings, Settings)
31 changes: 26 additions & 5 deletions scenes/boilerplate_scene_menu.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "../boilerplate.h"

enum SubmenuIndex {
SubmenuIndexScene1 = 10,
SubmenuIndexScene2,
SubmenuIndexScene3,
SubmenuIndexScene4,
SubmenuIndexScene5,
SubmenuIndexScene1 = 10, // static view
SubmenuIndexScene2, // static view with effects
SubmenuIndexScene3, // Button Menu
SubmenuIndexScene4, // file browser
SubmenuIndexScene5, // text input
SubmenuIndexScene6, // number input
SubmenuIndexSettings,
};

Expand Down Expand Up @@ -41,6 +42,18 @@ void boilerplate_scene_menu_on_enter(void* context) {
SubmenuIndexScene4,
boilerplate_scene_menu_submenu_callback,
app);
submenu_add_item(
app->submenu,
"Scene 5 (Text Input)",
SubmenuIndexScene5,
boilerplate_scene_menu_submenu_callback,
app);
submenu_add_item(
app->submenu,
"Scene 6 (Number Input)",
SubmenuIndexScene6,
boilerplate_scene_menu_submenu_callback,
app);
submenu_add_item(
app->submenu,
"Settings",
Expand Down Expand Up @@ -81,6 +94,14 @@ bool boilerplate_scene_menu_on_event(void* context, SceneManagerEvent event) {
scene_manager_set_scene_state(
app->scene_manager, BoilerplateSceneMenu, SubmenuIndexScene4);
scene_manager_next_scene(app->scene_manager, BoilerplateSceneScene_4);
} else if(event.event == SubmenuIndexScene5) {
scene_manager_set_scene_state(
app->scene_manager, BoilerplateSceneMenu, SubmenuIndexScene5);
scene_manager_next_scene(app->scene_manager, BoilerplateSceneScene_5);
} else if(event.event == SubmenuIndexScene6) {
scene_manager_set_scene_state(
app->scene_manager, BoilerplateSceneMenu, SubmenuIndexScene6);
scene_manager_next_scene(app->scene_manager, BoilerplateSceneScene_6);
} else if(event.event == SubmenuIndexSettings) {
scene_manager_set_scene_state(
app->scene_manager, BoilerplateSceneMenu, SubmenuIndexSettings);
Expand Down
40 changes: 40 additions & 0 deletions scenes/boilerplate_scene_scene_5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "../boilerplate.h"

void boilerplate_scene_scene_5_text_input_callback(void* context) {
furi_assert(context);
Boilerplate* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, 0);
}

void boilerplate_scene_scene_5_on_enter(void* context) {
Boilerplate* app = context;
TextInput* text_input = app->text_input;

text_input_set_header_text(text_input, "This is a custom text");

size_t enter_name_length = 32;
text_input_set_result_callback(
text_input,
boilerplate_scene_scene_5_text_input_callback,
context,
app->text_store[0],
enter_name_length,
false);

view_dispatcher_switch_to_view(app->view_dispatcher, BoilerplateViewIdTextInput);
}

bool boilerplate_scene_scene_5_on_event(void* context, SceneManagerEvent event) {
Boilerplate* app = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) { //Back button pressed
scene_manager_previous_scene(app->scene_manager);
return true;
}
return consumed;
}

void boilerplate_scene_scene_5_on_exit(void* context) {
UNUSED(context);
}
44 changes: 44 additions & 0 deletions scenes/boilerplate_scene_scene_6.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "../boilerplate.h"

void boilerplate_scene_6_callback(void* context, int32_t number) {
Boilerplate* app = context;
app->current_number = number;
view_dispatcher_send_custom_event(app->view_dispatcher, 0);
}

void boilerplate_scene_scene_6_on_enter(void* context) {
furi_assert(context);
Boilerplate* app = context;
NumberInput* number_input = app->number_input;

char str[50];
int32_t min_value = -128;
int32_t max_value = 2048;
snprintf(str, sizeof(str), "Set Number (%ld - %ld)", min_value, max_value);

number_input_set_header_text(number_input, str);
number_input_set_result_callback(
number_input,
boilerplate_scene_6_callback,
context,
app->current_number,
min_value,
max_value);

view_dispatcher_switch_to_view(app->view_dispatcher, BoilerplateViewIdNumberInput);
}

bool boilerplate_scene_scene_6_on_event(void* context, SceneManagerEvent event) {
Boilerplate* app = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) { //Back button pressed
scene_manager_previous_scene(app->scene_manager);
return true;
}
return consumed;
}

void boilerplate_scene_scene_6_on_exit(void* context) {
UNUSED(context);
}

0 comments on commit 994f979

Please sign in to comment.