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} JsViewPropType;
13
14typedef union {
15 const char* string;
16 int32_t number;
17 mjs_val_t array;
19
25typedef bool (
26 *JsViewPropAssign)(struct mjs* mjs, void* specific_view, JsViewPropValue value, void* context);
27
29typedef struct {
30 const char* name; //<! Property name, as visible from JS
31 JsViewPropType type; // <! Property type, ensured by the GUI module
32 JsViewPropAssign assign; // <! Property assignment callback
34
35// View method signatures
36
38typedef void* (*JsViewAlloc)(void);
40typedef View* (*JsViewGetView)(void* specific_view);
42typedef void (*JsViewFree)(void* specific_view);
43
44// Glue code method signatures
45
47typedef void* (*JsViewCustomMake)(struct mjs* mjs, void* specific_view, mjs_val_t view_obj);
49typedef void (*JsViewCustomDestroy)(void* specific_view, void* custom_state, FuriEventLoop* loop);
50
62typedef struct {
63 JsViewAlloc alloc;
64 JsViewGetView get_view;
65 JsViewFree free;
66 JsViewCustomMake custom_make; // <! May be NULL
67 JsViewCustomDestroy custom_destroy; // <! May be NULL
68 size_t prop_cnt; //<! Number of properties visible from JS
69 JsViewPropDescriptor props[]; // <! Descriptors of properties visible from JS
71
72// Callback ordering:
73// alloc -> get_view -> [custom_make (if set)] -> props[i].assign -> [custom_destroy (if_set)] -> free
74// \_______________ creation ________________/ \___ usage ___/ \_________ destruction _________/
75
88mjs_val_t js_gui_make_view_factory(struct mjs* mjs, const JsViewDescriptor* view_descriptor);
89
93#define JS_GUI_VIEW_DEF(name, descriptor) \
94 static void* view_mod_ctor(struct mjs* mjs, mjs_val_t* object, JsModules* modules) { \
95 UNUSED(modules); \
96 *object = js_gui_make_view_factory(mjs, descriptor); \
97 return NULL; \
98 } \
99 static const JsModuleDescriptor js_mod_desc = { \
100 "gui__" #name, \
101 view_mod_ctor, \
102 NULL, \
103 NULL, \
104 }; \
105 static const FlipperAppPluginDescriptor plugin_descriptor = { \
106 .appid = PLUGIN_APP_ID, \
107 .ep_api_version = PLUGIN_API_VERSION, \
108 .entry_point = &js_mod_desc, \
109 }; \
110 const FlipperAppPluginDescriptor* js_view_##name##_ep(void) { \
111 return &plugin_descriptor; \
112 }
113
114#ifdef __cplusplus
115}
116#endif
Definition event_loop_i.h:79
Descriptor for a JS view.
Definition js_gui.h:62
Property descriptor.
Definition js_gui.h:29
Definition view_i.h:16
Definition mjs_core.h:63
Definition js_gui.h:14
GUI: View API.