Skip to content

Commit

Permalink
Updated Button Panel (#4119)
Browse files Browse the repository at this point in the history
* updated button panel
* fixed mismateched .c and .h files
* Gui: extra events for ok button handling in button_panel
* Gui: extra events for other buttons handling in button_panel

Co-authored-by: あく <alleteam@gmail.com>
  • Loading branch information
Akiva-Cohen and skotopes authored Feb 20, 2025
1 parent 7c5c5d4 commit 4e9aa38
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ typedef union {
} InfraredSceneState;
#pragma pack(pop)

void infrared_scene_universal_common_item_callback(void* context, uint32_t index) {
void infrared_scene_universal_common_item_callback(void* context, uint32_t index, InputType type) {
InfraredApp* infrared = context;
uint32_t event = infrared_custom_event_pack(InfraredCustomEventTypeButtonSelected, index);
view_dispatcher_send_custom_event(infrared->view_dispatcher, event);
if(type == InputTypeShort) {
uint32_t event = infrared_custom_event_pack(InfraredCustomEventTypeButtonSelected, index);
view_dispatcher_send_custom_event(infrared->view_dispatcher, event);
}
}

static void infrared_scene_universal_common_progress_input_callback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
void infrared_scene_universal_common_on_enter(void* context);
bool infrared_scene_universal_common_on_event(void* context, SceneManagerEvent event);
void infrared_scene_universal_common_on_exit(void* context);
void infrared_scene_universal_common_item_callback(void* context, uint32_t index);
void infrared_scene_universal_common_item_callback(void* context, uint32_t index, InputType type);
23 changes: 14 additions & 9 deletions applications/services/gui/modules/button_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <gui/canvas.h>
#include <gui/elements.h>
#include <input/input.h>

#include <furi.h>
#include <furi_hal_resources.h>
Expand Down Expand Up @@ -46,6 +47,7 @@ ARRAY_DEF(ButtonMatrix, ButtonArray_t);

struct ButtonPanel {
View* view;
bool freeze_input;
};

typedef struct {
Expand All @@ -63,7 +65,7 @@ static void button_panel_process_up(ButtonPanel* button_panel);
static void button_panel_process_down(ButtonPanel* button_panel);
static void button_panel_process_left(ButtonPanel* button_panel);
static void button_panel_process_right(ButtonPanel* button_panel);
static void button_panel_process_ok(ButtonPanel* button_panel);
static void button_panel_process_ok(ButtonPanel* button_panel, InputType input);
static void button_panel_view_draw_callback(Canvas* canvas, void* _model);
static bool button_panel_view_input_callback(InputEvent* event, void* context);

Expand Down Expand Up @@ -347,7 +349,7 @@ static void button_panel_process_right(ButtonPanel* button_panel) {
true);
}

void button_panel_process_ok(ButtonPanel* button_panel) {
void button_panel_process_ok(ButtonPanel* button_panel, InputType type) {
ButtonItem* button_item = NULL;

with_view_model(
Expand All @@ -360,16 +362,23 @@ void button_panel_process_ok(ButtonPanel* button_panel) {
true);

if(button_item && button_item->callback) {
button_item->callback(button_item->callback_context, button_item->index);
button_item->callback(button_item->callback_context, button_item->index, type);
}
}

static bool button_panel_view_input_callback(InputEvent* event, void* context) {
ButtonPanel* button_panel = context;
furi_assert(button_panel);
bool consumed = false;

if(event->type == InputTypeShort) {
if(event->key == InputKeyOk) {
if((event->type == InputTypePress) || (event->type == InputTypeRelease)) {
button_panel->freeze_input = (event->type == InputTypePress);
}
consumed = true;
button_panel_process_ok(button_panel, event->type);
}
if(!button_panel->freeze_input &&
(!(event->type == InputTypePress) && !(event->type == InputTypeRelease))) {
switch(event->key) {
case InputKeyUp:
consumed = true;
Expand All @@ -387,10 +396,6 @@ static bool button_panel_view_input_callback(InputEvent* event, void* context) {
consumed = true;
button_panel_process_right(button_panel);
break;
case InputKeyOk:
consumed = true;
button_panel_process_ok(button_panel);
break;
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion applications/services/gui/modules/button_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern "C" {
typedef struct ButtonPanel ButtonPanel;

/** Callback type to call for handling selecting button_panel items */
typedef void (*ButtonItemCallback)(void* context, uint32_t index);
typedef void (*ButtonItemCallback)(void* context, uint32_t index, InputType type);

/** Allocate new button_panel module.
*
Expand Down

0 comments on commit 4e9aa38

Please sign in to comment.