2021-10-03 10:36:05 +00:00
|
|
|
/**
|
|
|
|
* @file view.h
|
|
|
|
* GUI: View API
|
|
|
|
*/
|
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <input/input.h>
|
2021-10-02 17:00:56 +00:00
|
|
|
|
|
|
|
#include "icon_animation.h"
|
2021-01-08 04:42:48 +00:00
|
|
|
#include "canvas.h"
|
|
|
|
|
2021-02-03 09:52:54 +00:00
|
|
|
#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
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Hides drawing view_port */
|
2021-01-08 04:42:48 +00:00
|
|
|
#define VIEW_NONE 0xFFFFFFFF
|
2021-10-02 17:00:56 +00:00
|
|
|
|
|
|
|
/** Ignore navigation event */
|
2021-01-08 04:42:48 +00:00
|
|
|
#define VIEW_IGNORE 0xFFFFFFFE
|
|
|
|
|
2021-05-19 09:43:15 +00:00
|
|
|
typedef enum {
|
|
|
|
ViewOrientationHorizontal,
|
|
|
|
ViewOrientationVertical,
|
|
|
|
} ViewOrientation;
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** View, anonymous type */
|
2021-04-01 12:03:02 +00:00
|
|
|
typedef struct View View;
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** View Draw callback
|
2021-10-03 10:36:05 +00:00
|
|
|
* @param canvas, pointer to canvas
|
|
|
|
* @param view_model, pointer to context
|
|
|
|
* @warning called from GUI thread
|
2021-01-08 04:42:48 +00:00
|
|
|
*/
|
|
|
|
typedef void (*ViewDrawCallback)(Canvas* canvas, void* model);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** View Input callback
|
2021-10-03 10:36:05 +00:00
|
|
|
* @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
|
2021-01-08 04:42:48 +00:00
|
|
|
*/
|
|
|
|
typedef bool (*ViewInputCallback)(InputEvent* event, void* context);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** View Custom callback
|
2021-10-03 10:36:05 +00:00
|
|
|
* @param event, number of custom event
|
|
|
|
* @param context, pointer to context
|
|
|
|
* @return true if event handled, false if event ignored
|
2021-06-30 17:43:29 +00:00
|
|
|
*/
|
|
|
|
typedef bool (*ViewCustomCallback)(uint32_t event, void* context);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** View navigation callback
|
2021-10-03 10:36:05 +00:00
|
|
|
* @param context, pointer to context
|
|
|
|
* @return next view id
|
|
|
|
* @warning called from GUI thread
|
2021-01-08 04:42:48 +00:00
|
|
|
*/
|
|
|
|
typedef uint32_t (*ViewNavigationCallback)(void* context);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** View callback
|
2021-10-03 10:36:05 +00:00
|
|
|
* @param context, pointer to context
|
|
|
|
* @warning called from GUI thread
|
2021-02-04 12:05:46 +00:00
|
|
|
*/
|
|
|
|
typedef void (*ViewCallback)(void* context);
|
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** View Update Callback Called upon model change, need to be propagated to GUI
|
|
|
|
* throw ViewPort update
|
|
|
|
* @param view, pointer to view
|
|
|
|
* @param context, pointer to context
|
|
|
|
* @warning called from GUI thread
|
2021-04-01 12:03:02 +00:00
|
|
|
*/
|
|
|
|
typedef void (*ViewUpdateCallback)(View* view, void* context);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** View model types */
|
2021-01-08 04:42:48 +00:00
|
|
|
typedef enum {
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Model is not allocated */
|
2021-01-08 04:42:48 +00:00
|
|
|
ViewModelTypeNone,
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Model consist of atomic types and/or partial update is not critical for rendering.
|
2021-01-08 04:42:48 +00:00
|
|
|
* Lock free.
|
|
|
|
*/
|
|
|
|
ViewModelTypeLockFree,
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Model access is guarded with mutex.
|
2021-01-08 04:42:48 +00:00
|
|
|
* Locking gui thread.
|
|
|
|
*/
|
|
|
|
ViewModelTypeLocking,
|
|
|
|
} ViewModelType;
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Allocate and init View
|
|
|
|
* @return View instance
|
2021-01-08 04:42:48 +00:00
|
|
|
*/
|
|
|
|
View* view_alloc();
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Free View
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view instance
|
2021-01-08 04:42:48 +00:00
|
|
|
*/
|
|
|
|
void view_free(View* view);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Tie IconAnimation with View
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
|
|
|
* @param icon_animation IconAnimation instance
|
2021-10-02 17:00:56 +00:00
|
|
|
*/
|
|
|
|
void view_tie_icon_animation(View* view, IconAnimation* icon_animation);
|
|
|
|
|
|
|
|
/** Set View Draw callback
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
|
|
|
* @param callback draw callback
|
2021-01-08 04:42:48 +00:00
|
|
|
*/
|
|
|
|
void view_set_draw_callback(View* view, ViewDrawCallback callback);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Set View Input callback
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
|
|
|
* @param callback input callback
|
2021-01-08 04:42:48 +00:00
|
|
|
*/
|
|
|
|
void view_set_input_callback(View* view, ViewInputCallback callback);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Set View Custom callback
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
|
|
|
* @param callback input callback
|
2021-06-30 17:43:29 +00:00
|
|
|
*/
|
|
|
|
void view_set_custom_callback(View* view, ViewCustomCallback callback);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Set Navigation Previous callback
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
|
|
|
* @param callback input callback
|
2021-01-08 04:42:48 +00:00
|
|
|
*/
|
|
|
|
void view_set_previous_callback(View* view, ViewNavigationCallback callback);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Set Enter callback
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
|
|
|
* @param callback callback
|
2021-02-04 12:05:46 +00:00
|
|
|
*/
|
|
|
|
void view_set_enter_callback(View* view, ViewCallback callback);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Set Exit callback
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
|
|
|
* @param callback callback
|
2021-02-04 12:05:46 +00:00
|
|
|
*/
|
|
|
|
void view_set_exit_callback(View* view, ViewCallback callback);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Set Update callback
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
|
|
|
* @param callback callback
|
2021-04-01 12:03:02 +00:00
|
|
|
*/
|
|
|
|
void view_set_update_callback(View* view, ViewUpdateCallback callback);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Set View Draw callback
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
|
|
|
* @param context context for callbacks
|
2021-04-01 12:03:02 +00:00
|
|
|
*/
|
|
|
|
void view_set_update_callback_context(View* view, void* context);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Set View Draw callback
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
|
|
|
* @param context context for callbacks
|
2021-01-08 04:42:48 +00:00
|
|
|
*/
|
|
|
|
void view_set_context(View* view, void* context);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Set View Orientation
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
|
|
|
* @param orientation either vertical or horizontal
|
2021-05-19 09:43:15 +00:00
|
|
|
*/
|
|
|
|
void view_set_orientation(View* view, ViewOrientation orientation);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Allocate view model.
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
|
|
|
* @param type View Model Type
|
|
|
|
* @param size size
|
2021-01-08 04:42:48 +00:00
|
|
|
*/
|
|
|
|
void view_allocate_model(View* view, ViewModelType type, size_t size);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Free view model data memory.
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
2021-01-08 04:42:48 +00:00
|
|
|
*/
|
|
|
|
void view_free_model(View* view);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Get view model data
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
|
|
|
*
|
|
|
|
* @return pointer to model data
|
|
|
|
* @warning Don't forget to commit model changes
|
2021-01-08 04:42:48 +00:00
|
|
|
*/
|
|
|
|
void* view_get_model(View* view);
|
|
|
|
|
2021-10-02 17:00:56 +00:00
|
|
|
/** Commit view model
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param view View instance
|
|
|
|
* @param update true if you want to emit view update, false otherwise
|
2021-01-08 04:42:48 +00:00
|
|
|
*/
|
2021-02-10 09:06:29 +00:00
|
|
|
void view_commit_model(View* view, bool update);
|
2021-01-08 04:42:48 +00:00
|
|
|
|
2021-03-05 09:47:27 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#define with_view_model_cpp(view, type, var, function_body) \
|
|
|
|
{ \
|
|
|
|
type* p = static_cast<type*>(view_get_model(view)); \
|
|
|
|
bool update = [&](type * var) function_body(p); \
|
|
|
|
view_commit_model(view, update); \
|
|
|
|
}
|
|
|
|
#else
|
2021-10-03 10:36:05 +00:00
|
|
|
/** With clause for view model
|
|
|
|
*
|
|
|
|
* @param view View instance pointer
|
|
|
|
* @param function_body a (){} lambda declaration, executed within you
|
|
|
|
* parent function context
|
|
|
|
*
|
|
|
|
* @return true if you want to emit view update, false otherwise
|
2021-02-10 09:06:29 +00:00
|
|
|
*/
|
|
|
|
#define with_view_model(view, function_body) \
|
|
|
|
{ \
|
|
|
|
void* p = view_get_model(view); \
|
|
|
|
bool update = ({ bool __fn__ function_body __fn__; })(p); \
|
|
|
|
view_commit_model(view, update); \
|
2021-01-08 04:42:48 +00:00
|
|
|
}
|
2021-05-19 09:43:15 +00:00
|
|
|
#endif
|