mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-30 08:20:21 +00:00
224d0aefe4
* First part of multitarget porting * Delete firmware/targets/f7/Inc directory * Delete firmware/targets/f7/Src directory * gpio: cli fixes; about: using version from HAL * sdk: path fixes * gui: include fixes * applications: more include fixes * gpio: ported to new apis * hal: introduced furi_hal_target_hw.h; libs: added one_wire * hal: f18 target * github: also build f18 by default * typo fix * fbt: removed extra checks on app list * api: explicitly bundling select mlib headers with sdk * hal: f18: changed INPUT_DEBOUNCE_TICKS to match f7 * cleaned up commented out code * docs: added info on hw targets * docs: targets: formatting fixes * f18: fixed link error * f18: fixed API version to match f7 * docs: hardware: minor wording fixes * faploader: added fw target check * docs: typo fixes * github: not building komi target by default * fbt: support for `targets` field for built-in apps * github: reworked build flow to exclude app_set; fbt: removed komi-specific appset; added additional target buildset check * github: fixed build; nfc: fixed pvs warnings * attempt to fix target id * f7, f18: removed certain HAL function from public API * apps: debug: enabled bt_debug_app for f18 * Targets: backport input pins configuration routine from F7 to F18 Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
173 lines
5 KiB
C
173 lines
5 KiB
C
#include "view_stack.h"
|
|
#include "view_i.h"
|
|
|
|
#include <gui/view.h>
|
|
#include <core/memmgr.h>
|
|
|
|
#define MAX_VIEWS 3
|
|
|
|
typedef struct {
|
|
View* views[MAX_VIEWS];
|
|
} ViewStackModel;
|
|
|
|
struct ViewStack {
|
|
View* view;
|
|
};
|
|
|
|
static void view_stack_draw(Canvas* canvas, void* model);
|
|
static bool view_stack_input(InputEvent* event, void* context);
|
|
|
|
static void view_stack_update_callback(View* view_top_or_bottom, void* context) {
|
|
furi_assert(view_top_or_bottom);
|
|
furi_assert(context);
|
|
|
|
View* view_stack_view = context;
|
|
if(view_stack_view->update_callback) {
|
|
view_stack_view->update_callback(
|
|
view_stack_view, view_stack_view->update_callback_context);
|
|
}
|
|
}
|
|
|
|
static void view_stack_enter(void* context) {
|
|
furi_assert(context);
|
|
|
|
ViewStack* view_stack = context;
|
|
ViewStackModel* model = view_get_model(view_stack->view);
|
|
|
|
/* if more than 1 Stack View hold same view they have to reassign update_callback_context */
|
|
for(int i = 0; i < MAX_VIEWS; ++i) {
|
|
if(model->views[i]) {
|
|
view_set_update_callback_context(model->views[i], view_stack->view);
|
|
if(model->views[i]->enter_callback) {
|
|
model->views[i]->enter_callback(model->views[i]->context);
|
|
}
|
|
}
|
|
}
|
|
|
|
view_commit_model(view_stack->view, false);
|
|
}
|
|
|
|
static void view_stack_exit(void* context) {
|
|
furi_assert(context);
|
|
|
|
ViewStack* view_stack = context;
|
|
ViewStackModel* model = view_get_model(view_stack->view);
|
|
|
|
for(int i = 0; i < MAX_VIEWS; ++i) {
|
|
if(model->views[i] && model->views[i]->exit_callback) {
|
|
model->views[i]->exit_callback(model->views[i]->context);
|
|
}
|
|
}
|
|
|
|
view_commit_model(view_stack->view, false);
|
|
}
|
|
|
|
ViewStack* view_stack_alloc(void) {
|
|
ViewStack* view_stack = malloc(sizeof(ViewStack));
|
|
view_stack->view = view_alloc();
|
|
|
|
view_allocate_model(view_stack->view, ViewModelTypeLocking, sizeof(ViewStackModel));
|
|
view_set_draw_callback(view_stack->view, view_stack_draw);
|
|
view_set_input_callback(view_stack->view, view_stack_input);
|
|
view_set_context(view_stack->view, view_stack);
|
|
view_set_enter_callback(view_stack->view, view_stack_enter);
|
|
view_set_exit_callback(view_stack->view, view_stack_exit);
|
|
return view_stack;
|
|
}
|
|
|
|
void view_stack_free(ViewStack* view_stack) {
|
|
furi_assert(view_stack);
|
|
|
|
ViewStackModel* model = view_get_model(view_stack->view);
|
|
for(int i = 0; i < MAX_VIEWS; ++i) {
|
|
if(model->views[i]) {
|
|
view_set_update_callback(model->views[i], NULL);
|
|
view_set_update_callback_context(model->views[i], NULL);
|
|
}
|
|
}
|
|
view_commit_model(view_stack->view, false);
|
|
|
|
view_free(view_stack->view);
|
|
free(view_stack);
|
|
}
|
|
|
|
static void view_stack_draw(Canvas* canvas, void* _model) {
|
|
furi_assert(_model);
|
|
|
|
ViewStackModel* model = _model;
|
|
for(int i = 0; i < MAX_VIEWS; ++i) {
|
|
if(model->views[i]) {
|
|
view_draw(model->views[i], canvas);
|
|
}
|
|
}
|
|
}
|
|
|
|
static bool view_stack_input(InputEvent* event, void* context) {
|
|
furi_assert(event);
|
|
furi_assert(context);
|
|
|
|
ViewStack* view_stack = context;
|
|
|
|
bool consumed = false;
|
|
ViewStackModel* model = view_get_model(view_stack->view);
|
|
for(int i = MAX_VIEWS - 1; i >= 0; i--) {
|
|
if(model->views[i] && view_input(model->views[i], event)) {
|
|
consumed = true;
|
|
break;
|
|
}
|
|
}
|
|
view_commit_model(view_stack->view, false);
|
|
|
|
return consumed;
|
|
}
|
|
|
|
void view_stack_add_view(ViewStack* view_stack, View* view) {
|
|
furi_assert(view_stack);
|
|
furi_assert(view);
|
|
|
|
bool result = false;
|
|
ViewStackModel* model = view_get_model(view_stack->view);
|
|
for(int i = 0; i < MAX_VIEWS; ++i) {
|
|
if(!model->views[i]) {
|
|
model->views[i] = view;
|
|
view_set_update_callback(model->views[i], view_stack_update_callback);
|
|
view_set_update_callback_context(model->views[i], view_stack->view);
|
|
if(view->enter_callback) {
|
|
view->enter_callback(view->context);
|
|
}
|
|
result = true;
|
|
break;
|
|
}
|
|
}
|
|
view_commit_model(view_stack->view, result);
|
|
furi_assert(result);
|
|
}
|
|
|
|
void view_stack_remove_view(ViewStack* view_stack, View* view) {
|
|
furi_assert(view_stack);
|
|
furi_assert(view);
|
|
|
|
/* Removing view on-the-go is dangerous, but it is protected with
|
|
* Locking model, so system is consistent at any time. */
|
|
bool result = false;
|
|
ViewStackModel* model = view_get_model(view_stack->view);
|
|
for(int i = 0; i < MAX_VIEWS; ++i) {
|
|
if(model->views[i] == view) {
|
|
if(view->exit_callback) {
|
|
view->exit_callback(view->context);
|
|
}
|
|
view_set_update_callback(model->views[i], NULL);
|
|
view_set_update_callback_context(model->views[i], NULL);
|
|
model->views[i] = NULL;
|
|
result = true;
|
|
break;
|
|
}
|
|
}
|
|
view_commit_model(view_stack->view, result);
|
|
furi_assert(result);
|
|
}
|
|
|
|
View* view_stack_get_view(ViewStack* view_stack) {
|
|
furi_assert(view_stack);
|
|
return view_stack->view;
|
|
}
|