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);
53
65typedef struct {
66 JsViewAlloc alloc;
67 JsViewGetView get_view;
68 JsViewFree free;
69 JsViewCustomMake custom_make; // <! May be NULL
70 JsViewCustomDestroy custom_destroy; // <! May be NULL
71 size_t prop_cnt; //<! Number of properties visible from JS
72 JsViewPropDescriptor props[]; // <! Descriptors of properties visible from JS
74
75// Callback ordering:
76// alloc -> get_view -> [custom_make (if set)] -> props[i].assign -> [custom_destroy (if_set)] -> free
77// \_______________ creation ________________/ \___ usage ___/ \_________ destruction _________/
78
91mjs_val_t js_gui_make_view_factory(struct mjs* mjs, const JsViewDescriptor* view_descriptor);
92
96#define JS_GUI_VIEW_DEF(name, descriptor) \
97 static void* view_mod_ctor(struct mjs* mjs, mjs_val_t* object, JsModules* modules) { \
98 UNUSED(modules); \
99 *object = js_gui_make_view_factory(mjs, descriptor); \
100 return NULL; \
101 } \
102 static const JsModuleDescriptor js_mod_desc = { \
103 "gui__" #name, \
104 view_mod_ctor, \
105 NULL, \
106 NULL, \
107 }; \
108 static const FlipperAppPluginDescriptor plugin_descriptor = { \
109 .appid = PLUGIN_APP_ID, \
110 .ep_api_version = PLUGIN_API_VERSION, \
111 .entry_point = &js_mod_desc, \
112 }; \
113 const FlipperAppPluginDescriptor* js_view_##name##_ep(void) { \
114 return &plugin_descriptor; \
115 }
116
117#ifdef __cplusplus
118}
119#endif
Definition event_loop_i.h:78
Descriptor for a JS view.
Definition js_gui.h:65
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.