-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
119 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
#include <furi.h> | ||
#include <gui/gui.h> | ||
#include <dialogs/dialogs.h> | ||
|
||
typedef struct { | ||
Gui* gui; | ||
ViewPort* view_port; | ||
Canvas* canvas; | ||
FuriPubSub* input_event_queue; | ||
FuriPubSubSubscription* input_event; | ||
DialogMessage* dialog_message; | ||
const char* dialog_message_button_left; | ||
const char* dialog_message_button_center; | ||
const char* dialog_message_button_right; | ||
} mp_flipper_context_t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
lib/micropython-port/mp_flipper_modflipperzero_dialog.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#include <dialogs/dialogs.h> | ||
|
||
#include <mp_flipper_modflipperzero.h> | ||
#include <mp_flipper_runtime.h> | ||
|
||
#include "mp_flipper_context.h" | ||
|
||
void mp_flipper_dialog_message_set_text( | ||
const char* text, | ||
uint8_t x, | ||
uint8_t y, | ||
uint8_t h, | ||
uint8_t v) { | ||
mp_flipper_context_t* ctx = mp_flipper_context; | ||
|
||
Align align_x = x == MP_FLIPPER_ALIGN_BEGIN ? AlignLeft : AlignRight; | ||
Align align_y = y == MP_FLIPPER_ALIGN_BEGIN ? AlignTop : AlignBottom; | ||
|
||
align_x = x == MP_FLIPPER_ALIGN_CENTER ? AlignCenter : align_x; | ||
align_y = y == MP_FLIPPER_ALIGN_CENTER ? AlignCenter : align_y; | ||
|
||
dialog_message_set_text(ctx->dialog_message, text, x, y, align_x, align_y); | ||
} | ||
|
||
void mp_flipper_dialog_message_set_header( | ||
const char* text, | ||
uint8_t x, | ||
uint8_t y, | ||
uint8_t h, | ||
uint8_t v) { | ||
mp_flipper_context_t* ctx = mp_flipper_context; | ||
|
||
Align align_x = x == MP_FLIPPER_ALIGN_BEGIN ? AlignLeft : AlignRight; | ||
Align align_y = y == MP_FLIPPER_ALIGN_BEGIN ? AlignTop : AlignBottom; | ||
|
||
align_x = x == MP_FLIPPER_ALIGN_CENTER ? AlignCenter : align_x; | ||
align_y = y == MP_FLIPPER_ALIGN_CENTER ? AlignCenter : align_y; | ||
|
||
dialog_message_set_header(ctx->dialog_message, text, x, y, align_x, align_y); | ||
} | ||
|
||
void mp_flipper_dialog_message_set_button(const char* text, uint8_t button) { | ||
mp_flipper_context_t* ctx = mp_flipper_context; | ||
|
||
// left button | ||
if(button == MP_FLIPPER_INPUT_BUTTON_LEFT) { | ||
ctx->dialog_message_button_left = text; | ||
} | ||
// center button | ||
else if(button == MP_FLIPPER_INPUT_BUTTON_OK) { | ||
ctx->dialog_message_button_center = text; | ||
} | ||
// right button | ||
else if(button == MP_FLIPPER_INPUT_BUTTON_RIGHT) { | ||
ctx->dialog_message_button_right = text; | ||
} | ||
|
||
dialog_message_set_buttons( | ||
ctx->dialog_message, | ||
ctx->dialog_message_button_left, | ||
ctx->dialog_message_button_center, | ||
ctx->dialog_message_button_right); | ||
} | ||
|
||
uint8_t mp_flipper_dialog_message_show() { | ||
mp_flipper_context_t* ctx = mp_flipper_context; | ||
|
||
gui_direct_draw_release(ctx->gui); | ||
|
||
DialogsApp* dialog = furi_record_open(RECORD_DIALOGS); | ||
|
||
uint8_t button = dialog_message_show(dialog, ctx->dialog_message); | ||
|
||
furi_record_close(RECORD_DIALOGS); | ||
|
||
ctx->canvas = gui_direct_draw_acquire(ctx->gui); | ||
|
||
switch(button) { | ||
case DialogMessageButtonLeft: | ||
return MP_FLIPPER_INPUT_BUTTON_LEFT; | ||
case DialogMessageButtonCenter: | ||
return MP_FLIPPER_INPUT_BUTTON_OK; | ||
case DialogMessageButtonRight: | ||
return MP_FLIPPER_INPUT_BUTTON_RIGHT; | ||
case DialogMessageButtonBack: | ||
default: | ||
return MP_FLIPPER_INPUT_BUTTON_BACK; | ||
} | ||
} | ||
|
||
void mp_flipper_dialog_message_clear() { | ||
mp_flipper_context_t* ctx = mp_flipper_context; | ||
|
||
dialog_message_free(ctx->dialog_message); | ||
|
||
ctx->dialog_message = dialog_message_alloc(); | ||
|
||
ctx->dialog_message_button_left = NULL; | ||
ctx->dialog_message_button_center = NULL; | ||
ctx->dialog_message_button_right = NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters