mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 12:42:30 +04:00
Updated Button Panel (#4119)
* 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>
This commit is contained in:
@@ -13,11 +13,13 @@ typedef union {
|
|||||||
} InfraredSceneState;
|
} InfraredSceneState;
|
||||||
#pragma pack(pop)
|
#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;
|
InfraredApp* infrared = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
uint32_t event = infrared_custom_event_pack(InfraredCustomEventTypeButtonSelected, index);
|
uint32_t event = infrared_custom_event_pack(InfraredCustomEventTypeButtonSelected, index);
|
||||||
view_dispatcher_send_custom_event(infrared->view_dispatcher, event);
|
view_dispatcher_send_custom_event(infrared->view_dispatcher, event);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void infrared_scene_universal_common_progress_input_callback(
|
static void infrared_scene_universal_common_progress_input_callback(
|
||||||
void* context,
|
void* context,
|
||||||
|
|||||||
@@ -5,4 +5,4 @@
|
|||||||
void infrared_scene_universal_common_on_enter(void* context);
|
void infrared_scene_universal_common_on_enter(void* context);
|
||||||
bool infrared_scene_universal_common_on_event(void* context, SceneManagerEvent event);
|
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_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);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <gui/canvas.h>
|
#include <gui/canvas.h>
|
||||||
#include <gui/elements.h>
|
#include <gui/elements.h>
|
||||||
|
#include <input/input.h>
|
||||||
|
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <furi_hal_resources.h>
|
#include <furi_hal_resources.h>
|
||||||
@@ -46,6 +47,7 @@ ARRAY_DEF(ButtonMatrix, ButtonArray_t);
|
|||||||
|
|
||||||
struct ButtonPanel {
|
struct ButtonPanel {
|
||||||
View* view;
|
View* view;
|
||||||
|
bool freeze_input;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -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_down(ButtonPanel* button_panel);
|
||||||
static void button_panel_process_left(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_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 void button_panel_view_draw_callback(Canvas* canvas, void* _model);
|
||||||
static bool button_panel_view_input_callback(InputEvent* event, void* context);
|
static bool button_panel_view_input_callback(InputEvent* event, void* context);
|
||||||
|
|
||||||
@@ -347,7 +349,7 @@ static void button_panel_process_right(ButtonPanel* button_panel) {
|
|||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void button_panel_process_ok(ButtonPanel* button_panel) {
|
void button_panel_process_ok(ButtonPanel* button_panel, InputType type) {
|
||||||
ButtonItem* button_item = NULL;
|
ButtonItem* button_item = NULL;
|
||||||
|
|
||||||
with_view_model(
|
with_view_model(
|
||||||
@@ -360,7 +362,7 @@ void button_panel_process_ok(ButtonPanel* button_panel) {
|
|||||||
true);
|
true);
|
||||||
|
|
||||||
if(button_item && button_item->callback) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,8 +370,15 @@ static bool button_panel_view_input_callback(InputEvent* event, void* context) {
|
|||||||
ButtonPanel* button_panel = context;
|
ButtonPanel* button_panel = context;
|
||||||
furi_assert(button_panel);
|
furi_assert(button_panel);
|
||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
|
if(event->key == InputKeyOk) {
|
||||||
if(event->type == InputTypeShort) {
|
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) {
|
switch(event->key) {
|
||||||
case InputKeyUp:
|
case InputKeyUp:
|
||||||
consumed = true;
|
consumed = true;
|
||||||
@@ -387,10 +396,6 @@ static bool button_panel_view_input_callback(InputEvent* event, void* context) {
|
|||||||
consumed = true;
|
consumed = true;
|
||||||
button_panel_process_right(button_panel);
|
button_panel_process_right(button_panel);
|
||||||
break;
|
break;
|
||||||
case InputKeyOk:
|
|
||||||
consumed = true;
|
|
||||||
button_panel_process_ok(button_panel);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ extern "C" {
|
|||||||
typedef struct ButtonPanel ButtonPanel;
|
typedef struct ButtonPanel ButtonPanel;
|
||||||
|
|
||||||
/** Callback type to call for handling selecting button_panel items */
|
/** 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.
|
/** Allocate new button_panel module.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user