#include "../../js_modules.h" #include #ifdef __cplusplus extern "C" { #endif typedef enum { JsViewPropTypeString, JsViewPropTypeNumber, JsViewPropTypeArr, JsViewPropTypeTypedArr, JsViewPropTypeBool, } JsViewPropType; typedef union { const char* string; int32_t number; bool boolean; mjs_val_t term; } JsViewPropValue; /** * @brief Assigns a value to a view property * * The name and the type are implicit and defined in the property descriptor */ typedef bool ( *JsViewPropAssign)(struct mjs* mjs, void* specific_view, JsViewPropValue value, void* context); /** @brief Property descriptor */ typedef struct { const char* name; // add_child -+ // +-> reset_children -+ // alloc -> get_view -> custom_make -+-> props[i].assign -+> custom_destroy -> free // \__________ creation __________/ \____ use ____/ \___ destruction ____/ /** * @brief Creates a JS `ViewFactory` object * * This function is intended to be used by individual view adapter modules that * wish to create a unified JS API interface in a declarative way. Usually this * is done via the `JS_GUI_VIEW_DEF` macro which hides all the boilerplate. * * The `ViewFactory` object exposes two methods, `make` and `makeWith`, each * returning a `View` object. These objects fully comply with the expectations * of the `ViewDispatcher`, TS type definitions and the proposed Flipper JS * coding style. */ mjs_val_t js_gui_make_view_factory(struct mjs* mjs, const JsViewDescriptor* view_descriptor); /** * @brief Defines a module implementing `View` glue code */ #define JS_GUI_VIEW_DEF(name, descriptor) \ static void* view_mod_ctor(struct mjs* mjs, mjs_val_t* object, JsModules* modules) { \ UNUSED(modules); \ *object = js_gui_make_view_factory(mjs, descriptor); \ return NULL; \ } \ static const JsModuleDescriptor js_mod_desc = { \ "gui__" #name, \ view_mod_ctor, \ NULL, \ NULL, \ }; \ static const FlipperAppPluginDescriptor plugin_descriptor = { \ .appid = PLUGIN_APP_ID, \ .ep_api_version = PLUGIN_API_VERSION, \ .entry_point = &js_mod_desc, \ }; \ const FlipperAppPluginDescriptor* js_view_##name##_ep(void) { \ return &plugin_descriptor; \ } #ifdef __cplusplus } #endif