simplified open/close record with transaction
This commit is contained in:
parent
ad59fea716
commit
6e03655767
@ -12,6 +12,19 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a record, calls the code and then closes the record.
|
||||||
|
* @param record_name const char* that contains the name of the record
|
||||||
|
* @param variable_name the name of the variable that is used in the `code`
|
||||||
|
* @param code the code to execute: consider putting it between {}
|
||||||
|
*/
|
||||||
|
#define FURI_RECORD_TRANSACTION(record_name, variable_name, code) \
|
||||||
|
{ \
|
||||||
|
NbGui* (variable_name) = (NbGui*)furi_record_open(record_name); \
|
||||||
|
code \
|
||||||
|
furi_record_close(record_name); \
|
||||||
|
}
|
||||||
|
|
||||||
/** Initialize record storage For internal use only.
|
/** Initialize record storage For internal use only.
|
||||||
*/
|
*/
|
||||||
void furi_record_init();
|
void furi_record_init();
|
||||||
|
|||||||
@ -14,16 +14,11 @@ ViewPort* view_port = NULL;
|
|||||||
static void prv_on_button_click(lv_event_t _Nonnull* event) {
|
static void prv_on_button_click(lv_event_t _Nonnull* event) {
|
||||||
ESP_LOGI(TAG, "button clicked");
|
ESP_LOGI(TAG, "button clicked");
|
||||||
|
|
||||||
// TODO: make macro for record 'transactions'
|
FURI_RECORD_TRANSACTION(RECORD_GUI, gui, {
|
||||||
NbGui* gui = furi_record_open(RECORD_GUI);
|
gui_remove_view_port(gui, view_port);
|
||||||
gui_remove_view_port(gui, view_port);
|
view_port_free(view_port);
|
||||||
|
view_port = NULL;
|
||||||
view_port_free(view_port);
|
});
|
||||||
view_port = NULL;
|
|
||||||
|
|
||||||
// Close Gui record
|
|
||||||
furi_record_close(RECORD_GUI);
|
|
||||||
gui = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prv_hello_world_lvgl(lv_obj_t* parent, void* context) {
|
static void prv_hello_world_lvgl(lv_obj_t* parent, void* context) {
|
||||||
@ -52,13 +47,9 @@ static int32_t prv_hello_world_main(void* param) {
|
|||||||
view_port = view_port_alloc();
|
view_port = view_port_alloc();
|
||||||
view_port_draw_callback_set(view_port, &prv_hello_world_lvgl, view_port);
|
view_port_draw_callback_set(view_port, &prv_hello_world_lvgl, view_port);
|
||||||
|
|
||||||
// Register view port in GUI
|
FURI_RECORD_TRANSACTION(RECORD_GUI, gui, {
|
||||||
NbGui* gui = furi_record_open(RECORD_GUI);
|
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
})
|
||||||
|
|
||||||
// Close Gui record
|
|
||||||
furi_record_close(RECORD_GUI);
|
|
||||||
gui = NULL;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user