[wip] change gui/widget api

This commit is contained in:
aanper 2020-10-15 11:32:48 +03:00
parent f2a38cf174
commit 19ef348c80
4 changed files with 55 additions and 56 deletions

View File

@ -22,48 +22,32 @@ struct GUI {
WidgetArray_t widgets_dialog;
};
void gui_widget_status_bar_add(GUI* gui, Widget* widget) {
void gui_add_widget(GUI* gui, Widget* widget, WidgetLayer layer) {
WidgetArray_t* widget_array = NULL;
switch(layer) {
case WidgetLayerStatusBar:
widget_array = &gui->widgets_status_bar;
break;
case WidgetLayerMain:
widget_array = &gui->widgets;
break;
case WidgetLayerFullscreen:
widget_array = &gui->widgets_fs;
break;
case WidgetLayerDialog:
widget_array = &gui->widgets_dialog;
break;
default:
}
assert(gui);
assert(widget);
assert(widget_array);
gui_event_lock(gui->event);
WidgetArray_push_back(gui->widgets_status_bar, widget);
widget_gui_set(widget, gui);
gui_event_unlock(gui->event);
gui_update(gui);
}
void gui_widget_add(GUI* gui, Widget* widget) {
assert(gui);
assert(widget);
gui_event_lock(gui->event);
WidgetArray_push_back(gui->widgets, widget);
widget_gui_set(widget, gui);
gui_event_unlock(gui->event);
gui_update(gui);
}
void gui_widget_fs_add(GUI* gui, Widget* widget) {
assert(gui);
assert(widget);
gui_event_lock(gui->event);
WidgetArray_push_back(gui->widgets_fs, widget);
widget_gui_set(widget, gui);
gui_event_unlock(gui->event);
gui_update(gui);
}
void gui_widget_dialog_add(GUI* gui, Widget* widget) {
assert(gui);
assert(widget);
gui_event_lock(gui->event);
WidgetArray_push_back(gui->widgets_dialog, widget);
WidgetArray_push_back(widget_array, widget);
widget_gui_set(widget, gui);
gui_event_unlock(gui->event);
@ -148,8 +132,10 @@ GUI* gui_alloc() {
WidgetArray_init(gui->widgets);
WidgetArray_init(gui->widgets_fs);
WidgetArray_init(gui->widgets_dialog);
// Event dispatcher
gui->event = gui_event_alloc();
// Drawing canvas
gui->canvas = canvas_alloc();
@ -158,12 +144,20 @@ GUI* gui_alloc() {
void gui_task(void* p) {
GUI* gui = gui_alloc();
GuiApi gui_api = {
.add_widget = gui_add_widget,
.gui = gui,
};
// Create FURI record
if(!furi_create_deprecated("gui", gui, sizeof(gui))) {
if(!furi_create("gui", &gui_api)) {
printf("[gui_task] cannot create the gui record\n");
furiac_exit(NULL);
}
furiac_ready();
// Forever dispatch
while(1) {
GUIMessage message = gui_event_message_next(gui->event);

View File

@ -1,12 +1,18 @@
#pragma once
#include "widget.h"
typedef enum {
WidgetLayerStatusBar,
WidgetLayerMain,
WidgetLayerFullscreen,
WidgetLayerDialog
} WidgetLayer;
typedef struct Widget Widget;
typedef struct GUI GUI;
void gui_widget_status_bar_add(GUI* gui, Widget* widget);
void gui_widget_add(GUI* gui, Widget* widget);
void gui_widget_fs_add(GUI* gui, Widget* widget);
void gui_widget_dialog_add(GUI* gui, Widget* widget);
typedef struct {
void (*add_widget)(GUI* gui, Widget* widget, WidgetLayer layer);
GUI* gui;
} GuiApi;

View File

@ -7,15 +7,6 @@
#include "gui.h"
#include "gui_i.h"
struct Widget {
void* gui;
bool is_enabled;
WidgetDrawCallback draw_callback;
void* draw_callback_context;
WidgetInputCallback input_callback;
void* input_callback_context;
};
Widget* widget_alloc(WidgetDrawCallback callback, void* callback_context) {
Widget* widget = furi_alloc(sizeof(Widget));
widget->is_enabled = true;

View File

@ -4,7 +4,15 @@
typedef struct GUI GUI;
typedef struct Canvas Canvas;
typedef struct Widget Widget;
typedef struct {
void* gui;
bool is_enabled;
WidgetDrawCallback draw_callback;
void* draw_callback_context;
WidgetInputCallback input_callback;
void* input_callback_context;
} Widget;
typedef void (*WidgetDrawCallback)(Canvas* canvas, void* context);
typedef void (*WidgetInputCallback)(InputEvent* event, void* context);