Welcome to mirror list, hosted at ThFree Co, Russian Federation.

view.h « gui « applications - github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 38127a7b979dff43f4b33c2fc1757b74f375f40f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#pragma once

#include <input/input.h>
#include "canvas.h"

#include <stddef.h>
#include <stdint.h>

#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

typedef enum {
    ViewOrientationHorizontal,
    ViewOrientationVertical,
} ViewOrientation;

/* View, anonymous type */
typedef struct View View;

/* 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 Custom callback
 * @param event, number of custom event
 * @param context, pointer to context
 * @return true if event handled, false if event ignored
 */
typedef bool (*ViewCustomCallback)(uint32_t 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 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
 */
typedef void (*ViewUpdateCallback)(View* view, 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;

/* 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 Input callback
 * @param view, pointer to View
 * @param callback, input callback
 */
void view_set_input_callback(View* view, ViewInputCallback callback);

/* Set View Custom callback
 * @param view, pointer to View
 * @param callback, input callback
 */
void view_set_custom_callback(View* view, ViewCustomCallback 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 Update callback
 * @param view, pointer to View
 * @param callback, callback
 */
void view_set_update_callback(View* view, ViewUpdateCallback callback);

/* Set View Draw callback
 * @param view, pointer to View
 * @param context, context for callbacks
 */
void view_set_update_callback_context(View* view, void* context);

/* Set View Draw callback
 * @param view, pointer to View
 * @param context, context for callbacks
 */
void view_set_context(View* view, void* context);

/* Set View Orientation
 * @param view, pointer to View
 * @param orientation, either vertical or horizontal
 */
void view_set_orientation(View* view, ViewOrientation orientation);

/* 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
 * @param update, true if you want to emit view update, false otherwise
 */
void view_commit_model(View* view, bool update);

#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
/* 
 * 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
 */
#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);                          \
    }
#endif