mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-25 22:10:21 +00:00
bf6c6c231f
* Abstract primitive type from main logic in FuriEventLoop * Remove message_queue_i.h * Add stream buffer support for event loop * Add semaphore support for event loop * Add temporary unit test workaround * Make the linter happy * Add mutex support for event loop * Implement event subscription and unsubscription while the event loop is running * Implement edge events * Fix leftover logical errors * Add event loop timer example application * Implement flag-based edge trigger and one-shot mode * Add event loop mutex example application * Only notify the event loop if stream buffer is at or above its trigger level * Reformat comments * Add event loop stream buffer example application * Add event loop multiple elements example application * Improve event loop flag names * Remove redundant signal handler as it is already handled by the event loop * Refactor Power service, improve ViewHolder * Use ViewHolder instead of ViewDispatcher in About app * Enable ViewDispatcher queue on construction, deprecate view_dispatcher_enable_queue() * Remove all invocations of view_dispatcher_enable_queue() * Remove app-scened-template * Remove missing library from target.json * Port Accessor app to ViewHolder * Make the linter happy * Add example_view_holder application, update ViewHolder docs * Add example_view_dispatcher application, update ViewDispatcher docs * Replace FuriSemaphore with FuriApiLock, remove workaround delay * Fix logical error * Fix another logical error * Use the sources directive to speed up compilation * Use constant define macro * Improve FuriEventLoop documentation * Improve FuriEventLoop documentation once more * Bump API Version * Gui: remove redundant checks from ViewDispatcher * Gui: remove dead ifs from ViewDispatcher Co-authored-by: Silent <CookiePLMonster@users.noreply.github.com> Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: あく <alleteam@gmail.com>
165 lines
4.8 KiB
C
165 lines
4.8 KiB
C
#include "dialogs.h"
|
|
#include "dialogs_message.h"
|
|
#include <gui/view_holder.h>
|
|
#include <toolbox/api_lock.h>
|
|
#include <gui/modules/dialog_ex.h>
|
|
|
|
typedef struct {
|
|
FuriApiLock lock;
|
|
DialogMessageButton result;
|
|
} DialogsAppMessageContext;
|
|
|
|
struct DialogMessage {
|
|
const char* header_text;
|
|
uint8_t header_text_x;
|
|
uint8_t header_text_y;
|
|
Align header_horizontal;
|
|
Align header_vertical;
|
|
const char* dialog_text;
|
|
uint8_t dialog_text_x;
|
|
uint8_t dialog_text_y;
|
|
Align dialog_text_horizontal;
|
|
Align dialog_text_vertical;
|
|
const Icon* icon;
|
|
uint8_t icon_x;
|
|
uint8_t icon_y;
|
|
const char* left_button_text;
|
|
const char* center_button_text;
|
|
const char* right_button_text;
|
|
};
|
|
|
|
static void dialogs_app_message_back_callback(void* context) {
|
|
furi_assert(context);
|
|
DialogsAppMessageContext* message_context = context;
|
|
message_context->result = DialogMessageButtonBack;
|
|
api_lock_unlock(message_context->lock);
|
|
}
|
|
|
|
static void dialogs_app_message_callback(DialogExResult result, void* context) {
|
|
furi_assert(context);
|
|
DialogsAppMessageContext* message_context = context;
|
|
switch(result) {
|
|
case DialogExResultLeft:
|
|
message_context->result = DialogMessageButtonLeft;
|
|
break;
|
|
case DialogExResultRight:
|
|
message_context->result = DialogMessageButtonRight;
|
|
break;
|
|
case DialogExResultCenter:
|
|
message_context->result = DialogMessageButtonCenter;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
api_lock_unlock(message_context->lock);
|
|
}
|
|
|
|
DialogMessageButton dialogs_app_process_module_message(const DialogsAppMessageDataDialog* data) {
|
|
DialogMessageButton ret = DialogMessageButtonBack;
|
|
Gui* gui = furi_record_open(RECORD_GUI);
|
|
const DialogMessage* message = data->message;
|
|
DialogsAppMessageContext* message_context = malloc(sizeof(DialogsAppMessageContext));
|
|
message_context->lock = api_lock_alloc_locked();
|
|
|
|
ViewHolder* view_holder = view_holder_alloc();
|
|
view_holder_attach_to_gui(view_holder, gui);
|
|
view_holder_set_back_callback(view_holder, dialogs_app_message_back_callback, message_context);
|
|
|
|
DialogEx* dialog_ex = dialog_ex_alloc();
|
|
dialog_ex_set_result_callback(dialog_ex, dialogs_app_message_callback);
|
|
dialog_ex_set_context(dialog_ex, message_context);
|
|
dialog_ex_set_header(
|
|
dialog_ex,
|
|
message->header_text,
|
|
message->header_text_x,
|
|
message->header_text_y,
|
|
message->header_horizontal,
|
|
message->header_vertical);
|
|
dialog_ex_set_text(
|
|
dialog_ex,
|
|
message->dialog_text,
|
|
message->dialog_text_x,
|
|
message->dialog_text_y,
|
|
message->dialog_text_horizontal,
|
|
message->dialog_text_vertical);
|
|
dialog_ex_set_icon(dialog_ex, message->icon_x, message->icon_y, message->icon);
|
|
dialog_ex_set_left_button_text(dialog_ex, message->left_button_text);
|
|
dialog_ex_set_center_button_text(dialog_ex, message->center_button_text);
|
|
dialog_ex_set_right_button_text(dialog_ex, message->right_button_text);
|
|
|
|
view_holder_set_view(view_holder, dialog_ex_get_view(dialog_ex));
|
|
api_lock_wait_unlock(message_context->lock);
|
|
|
|
ret = message_context->result;
|
|
|
|
view_holder_set_view(view_holder, NULL);
|
|
view_holder_free(view_holder);
|
|
dialog_ex_free(dialog_ex);
|
|
api_lock_free(message_context->lock);
|
|
free(message_context);
|
|
furi_record_close(RECORD_GUI);
|
|
|
|
return ret;
|
|
}
|
|
|
|
DialogMessage* dialog_message_alloc(void) {
|
|
DialogMessage* message = malloc(sizeof(DialogMessage));
|
|
return message;
|
|
}
|
|
|
|
void dialog_message_free(DialogMessage* message) {
|
|
furi_check(message);
|
|
free(message);
|
|
}
|
|
|
|
void dialog_message_set_text(
|
|
DialogMessage* message,
|
|
const char* text,
|
|
uint8_t x,
|
|
uint8_t y,
|
|
Align horizontal,
|
|
Align vertical) {
|
|
furi_check(message);
|
|
|
|
message->dialog_text = text;
|
|
message->dialog_text_x = x;
|
|
message->dialog_text_y = y;
|
|
message->dialog_text_horizontal = horizontal;
|
|
message->dialog_text_vertical = vertical;
|
|
}
|
|
|
|
void dialog_message_set_header(
|
|
DialogMessage* message,
|
|
const char* text,
|
|
uint8_t x,
|
|
uint8_t y,
|
|
Align horizontal,
|
|
Align vertical) {
|
|
furi_check(message);
|
|
|
|
message->header_text = text;
|
|
message->header_text_x = x;
|
|
message->header_text_y = y;
|
|
message->header_horizontal = horizontal;
|
|
message->header_vertical = vertical;
|
|
}
|
|
|
|
void dialog_message_set_icon(DialogMessage* message, const Icon* icon, uint8_t x, uint8_t y) {
|
|
furi_check(message);
|
|
|
|
message->icon = icon;
|
|
message->icon_x = x;
|
|
message->icon_y = y;
|
|
}
|
|
|
|
void dialog_message_set_buttons(
|
|
DialogMessage* message,
|
|
const char* left,
|
|
const char* center,
|
|
const char* right) {
|
|
furi_check(message);
|
|
|
|
message->left_button_text = left;
|
|
message->center_button_text = center;
|
|
message->right_button_text = right;
|
|
}
|