Loading...
Searching...
No Matches
js_gui.h
1#include "../../js_modules.h"
2#include <gui/view.h>
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8typedef enum {
9 JsViewPropTypeString,
10 JsViewPropTypeNumber,
11 JsViewPropTypeArr,
12 JsViewPropTypeTypedArr,
13 JsViewPropTypeBool,
14} JsViewPropType;
15
16typedef union {
17 const char* string;
18 int32_t number;
19 bool boolean;
20 mjs_val_t term;
22
28typedef bool (
29 *JsViewPropAssign)(struct mjs* mjs, void* specific_view, JsViewPropValue value, void* context);
30
32typedef struct {
33 const char* name; //<! Property name, as visible from JS
34 JsViewPropType type; // <! Property type, ensured by the GUI module
35 JsViewPropAssign assign; // <! Property assignment callback
37
38// View method signatures
39
41typedef void* (*JsViewAlloc)(void);
43typedef View* (*JsViewGetView)(void* specific_view);
45typedef void (*JsViewFree)(void* specific_view);
46
47// Glue code method signatures
48
50typedef void* (*JsViewCustomMake)(struct mjs* mjs, void* specific_view, mjs_val_t view_obj);
52typedef void (*JsViewCustomDestroy)(void* specific_view, void* custom_state, FuriEventLoop* loop);
54typedef bool (
55 *JsViewAddChild)(struct mjs* mjs, void* specific_view, void* custom_state, mjs_val_t child_obj);
57typedef void (*JsViewResetChildren)(void* specific_view, void* custom_state);
58
70typedef struct {
71 JsViewAlloc alloc;
72 JsViewGetView get_view;
73 JsViewFree free;
74
75 JsViewCustomMake custom_make; // <! May be NULL
76 JsViewCustomDestroy custom_destroy; // <! May be NULL
77
78 JsViewAddChild add_child; // <! May be NULL
79 JsViewResetChildren reset_children; // <! May be NULL
80
81 size_t prop_cnt; //<! Number of properties visible from JS
82 JsViewPropDescriptor props[]; // <! Descriptors of properties visible from JS
84
85// Callback ordering:
86// +-> add_child -+
87// +-> reset_children -+
88// alloc -> get_view -> custom_make -+-> props[i].assign -+> custom_destroy -> free
89// \__________ creation __________/ \____ use ____/ \___ destruction ____/
90
103mjs_val_t js_gui_make_view_factory(struct mjs* mjs, const JsViewDescriptor* view_descriptor);
104
108#define JS_GUI_VIEW_DEF(name, descriptor) \
109 static void* view_mod_ctor(struct mjs* mjs, mjs_val_t* object, JsModules* modules) { \
110 UNUSED(modules); \
111 *object = js_gui_make_view_factory(mjs, descriptor); \
112 return NULL; \
113 } \
114 static const JsModuleDescriptor js_mod_desc = { \
115 "gui__" #name, \
116 view_mod_ctor, \
117 NULL, \
118 NULL, \
119 }; \
120 static const FlipperAppPluginDescriptor plugin_descriptor = { \
121 .appid = PLUGIN_APP_ID, \
122 .ep_api_version = PLUGIN_API_VERSION, \
123 .entry_point = &js_mod_desc, \
124 }; \
125 const FlipperAppPluginDescriptor* js_view_##name##_ep(void) { \
126 return &plugin_descriptor; \
127 }
128
129#ifdef __cplusplus
130}
131#endif
Definition event_loop_i.h:80
Descriptor for a JS view.
Definition js_gui.h:70
Property descriptor.
Definition js_gui.h:32
Definition view_i.h:16
Definition mjs_core.h:63
Definition js_gui.h:16
GUI: View API.