flipperzero-firmware/applications/gui/view.h

159 lines
3.9 KiB
C
Raw Normal View History

#pragma once
#include <input/input.h>
#include "canvas.h"
#include <stddef.h>
#include <stdint.h>
[FL-140] Core api dynamic records (#296) * SYSTEM: tickless mode with deep sleep. * Move FreeRTOS ticks to lptim2 * API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source. * API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode. * NFC: support for tickless mode. * API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications. * BLE: prevent sleep while core2 starting * HAL: nap while in insomnia mode * init records work * try to implement record delete * tests and flapp * flapp subsystem * new core functions to get app stat, simplify core code * fix thread termination * add strdup to core * fix tests * Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage * Refactoring: update furi record api usage, cleanup code * Fix broken merge for freertos apps * Core, Target: fix compilation warnings * Drop firmware target local * HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode. * SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial. * delete old app example-ipc * delete old app fatfs list * fix strobe app, add input header * delete old display driver * comment old app qr-code * fix sd-card test, add forced widget update * remove unused new core test * increase heap to 128k * comment and assert old core tests * fix syntax Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 16:09:26 +00:00
#ifdef __cplusplus
extern "C" {
#endif
/* Hides drawing view_port */
#define VIEW_NONE 0xFFFFFFFF
/* Ignore navigation event */
#define VIEW_IGNORE 0xFFFFFFFE
/* Deatch from gui, deallocate Views and ViewDispatcher
* BE SUPER CAREFUL, deallocation happens automatically on GUI thread
* You ARE NOT owning ViewDispatcher and Views instances
*/
#define VIEW_DESTROY 0xFFFFFFFA
/* View Draw callback
* @param canvas, pointer to canvas
* @param view_model, pointer to context
* @warning called from GUI thread
*/
typedef void (*ViewDrawCallback)(Canvas* canvas, void* model);
/* View Input callback
* @param event, pointer to input event data
* @param context, pointer to context
* @return true if event handled, false if event ignored
* @warning called from GUI thread
*/
typedef bool (*ViewInputCallback)(InputEvent* event, void* context);
/* View navigation callback
* @param context, pointer to context
* @return next view id
* @warning called from GUI thread
*/
typedef uint32_t (*ViewNavigationCallback)(void* context);
/* View callback
* @param context, pointer to context
* @warning called from GUI thread
*/
typedef void (*ViewCallback)(void* context);
/* View model types */
typedef enum {
/* Model is not allocated */
ViewModelTypeNone,
/* Model consist of atomic types and/or partial update is not critical for rendering.
* Lock free.
*/
ViewModelTypeLockFree,
/* Model access is guarded with mutex.
* Locking gui thread.
*/
ViewModelTypeLocking,
} ViewModelType;
typedef struct View View;
/* Allocate and init View
* @return pointer to View
*/
View* view_alloc();
/* Free View
* @param pointer to View
*/
void view_free(View* view);
/* Set View Draw callback
* @param view, pointer to View
* @param callback, draw callback
*/
void view_set_draw_callback(View* view, ViewDrawCallback callback);
/* Set View Draw callback
* @param view, pointer to View
* @param callback, input callback
*/
void view_set_input_callback(View* view, ViewInputCallback callback);
/* Set Navigation Previous callback
* @param view, pointer to View
* @param callback, input callback
*/
void view_set_previous_callback(View* view, ViewNavigationCallback callback);
/* Set Navigation Next callback
* @param view, pointer to View
* @param callback, input callback
*/
void view_set_next_callback(View* view, ViewNavigationCallback callback);
/* Set Enter callback
* @param view, pointer to View
* @param callback, callback
*/
void view_set_enter_callback(View* view, ViewCallback callback);
/* Set Exit callback
* @param view, pointer to View
* @param callback, callback
*/
void view_set_exit_callback(View* view, ViewCallback callback);
/* Set View Draw callback
* @param view, pointer to View
* @param context, context for callbacks
*/
void view_set_context(View* view, void* context);
/* Allocate view model.
* @param view, pointer to View
* @param type, View Model Type
* @param size, size
*/
void view_allocate_model(View* view, ViewModelType type, size_t size);
/* Free view model data memory.
* @param view, pointer to View
*/
void view_free_model(View* view);
/* Get view model data
* @param view, pointer to View
* @return pointer to model data
* @warning Don't forget to commit model changes
*/
void* view_get_model(View* view);
/* Commit view model
* @param view, pointer to View
*/
void view_commit_model(View* view);
/*
* With clause for view model
* @param view, View instance pointer
* @param function_body a (){} lambda declaration,
* executed within you parent function context.
*/
#define with_view_model(view, function_body) \
{ \
void* p = view_get_model(view); \
({ void __fn__ function_body __fn__; })(p); \
view_commit_model(view); \
}
[FL-140] Core api dynamic records (#296) * SYSTEM: tickless mode with deep sleep. * Move FreeRTOS ticks to lptim2 * API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source. * API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode. * NFC: support for tickless mode. * API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications. * BLE: prevent sleep while core2 starting * HAL: nap while in insomnia mode * init records work * try to implement record delete * tests and flapp * flapp subsystem * new core functions to get app stat, simplify core code * fix thread termination * add strdup to core * fix tests * Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage * Refactoring: update furi record api usage, cleanup code * Fix broken merge for freertos apps * Core, Target: fix compilation warnings * Drop firmware target local * HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode. * SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial. * delete old app example-ipc * delete old app fatfs list * fix strobe app, add input header * delete old display driver * comment old app qr-code * fix sd-card test, add forced widget update * remove unused new core test * increase heap to 128k * comment and assert old core tests * fix syntax Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 16:09:26 +00:00
#ifdef __cplusplus
}
#endif