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
26extern const JsValueDeclaration js_gui_font_declaration;
27
33typedef bool (
34 *JsViewPropAssign)(struct mjs* mjs, void* specific_view, JsViewPropValue value, void* context);
35
37typedef struct {
38 const char* name; //<! Property name, as visible from JS
39 JsViewPropType type; // <! Property type, ensured by the GUI module
40 JsViewPropAssign assign; // <! Property assignment callback
42
43// View method signatures
44
46typedef void* (*JsViewAlloc)(void);
48typedef View* (*JsViewGetView)(void* specific_view);
50typedef void (*JsViewFree)(void* specific_view);
51
52// Glue code method signatures
53
55typedef void* (*JsViewCustomMake)(struct mjs* mjs, void* specific_view, mjs_val_t view_obj);
57typedef void (*JsViewCustomDestroy)(void* specific_view, void* custom_state, FuriEventLoop* loop);
59typedef bool (
60 *JsViewAddChild)(struct mjs* mjs, void* specific_view, void* custom_state, mjs_val_t child_obj);
62typedef void (*JsViewResetChildren)(void* specific_view, void* custom_state);
63
75typedef struct {
76 JsViewAlloc alloc;
77 JsViewGetView get_view;
78 JsViewFree free;
79
80 JsViewCustomMake custom_make; // <! May be NULL
81 JsViewCustomDestroy custom_destroy; // <! May be NULL
82
83 JsViewAddChild add_child; // <! May be NULL
84 JsViewResetChildren reset_children; // <! May be NULL
85
86 size_t prop_cnt; //<! Number of properties visible from JS
87 JsViewPropDescriptor props[]; // <! Descriptors of properties visible from JS
89
90// Callback ordering:
91// +-> add_child -+
92// +-> reset_children -+
93// alloc -> get_view -> custom_make -+-> props[i].assign -+> custom_destroy -> free
94// \__________ creation __________/ \____ use ____/ \___ destruction ____/
95
108mjs_val_t js_gui_make_view_factory(struct mjs* mjs, const JsViewDescriptor* view_descriptor);
109
113#define JS_GUI_VIEW_DEF(name, descriptor) \
114 static void* view_mod_ctor(struct mjs* mjs, mjs_val_t* object, JsModules* modules) { \
115 UNUSED(modules); \
116 *object = js_gui_make_view_factory(mjs, descriptor); \
117 return NULL; \
118 } \
119 static const JsModuleDescriptor js_mod_desc = { \
120 "gui__" #name, \
121 view_mod_ctor, \
122 NULL, \
123 NULL, \
124 }; \
125 static const FlipperAppPluginDescriptor plugin_descriptor = { \
126 .appid = PLUGIN_APP_ID, \
127 .ep_api_version = PLUGIN_API_VERSION, \
128 .entry_point = &js_mod_desc, \
129 }; \
130 const FlipperAppPluginDescriptor* js_view_##name##_ep(void) { \
131 return &plugin_descriptor; \
132 }
133
134#ifdef __cplusplus
135}
136#endif
Definition event_loop_i.h:80
Definition js_value.h:57
Descriptor for a JS view.
Definition js_gui.h:75
Property descriptor.
Definition js_gui.h:37
Definition view_i.h:16
Definition mjs_core.h:63
Definition js_gui.h:16
GUI: View API.