added panel hook concept
This commit is contained in:
parent
30800c95f2
commit
7644774cdb
16
Readme.md
16
Readme.md
@ -282,30 +282,30 @@ struct gui_stack stack;
|
|||||||
|
|
||||||
gui_buffer_init_fixed(buffer, &memory);
|
gui_buffer_init_fixed(buffer, &memory);
|
||||||
gui_default_config(&config);
|
gui_default_config(&config);
|
||||||
gui_panel_init(&hook.panel, 50, 50, 300, 200, 0, &config, &font);
|
gui_hook_init(&hook, 50, 50, 300, 200, 0, &config, &font);
|
||||||
gui_stack_clear(&stack);
|
gui_stack_clear(&stack);
|
||||||
gui_stack_push(&stack, &hook.panel);
|
gui_stack_push_hook(&stack, &hook);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
struct gui_panel_layout layout;
|
struct gui_panel_layout layout;
|
||||||
struct gui_canvas canvas;
|
struct gui_canvas canvas;
|
||||||
|
|
||||||
gui_buffer_begin(&canvas, &buffer, window_width, window_height);
|
gui_buffer_begin(&canvas, &buffer, window_width, window_height);
|
||||||
gui_panel_begin_stacked(&layout, &win.panel, &stack, "Demo", &canvas, &input);
|
gui_hook_begin(&layout, &hook, &stack, "Demo", &canvas, &input);
|
||||||
gui_panel_row(&layout, 30, 1);
|
gui_panel_row(&layout, 30, 1);
|
||||||
if (gui_panel_button_text(&layout, "button", GUI_BUTTON_DEFAULT))
|
if (gui_panel_button_text(&layout, "button", GUI_BUTTON_DEFAULT))
|
||||||
fprintf(stdout, "button pressed!\n");
|
fprintf(stdout, "button pressed!\n");
|
||||||
gui_panel_end(&layout, &win.panel);
|
gui_hook_end(&layout, &hook);
|
||||||
gui_buffer_end(&win.list, buffer, &status);
|
gui_buffer_end(gui_hook_list(&hook), buffer, &status);
|
||||||
|
|
||||||
/* draw each panel */
|
/* draw each panel */
|
||||||
struct gui_panel *iter = stack.begin;
|
struct gui_panel *iter = stack.begin;
|
||||||
while (iter) {
|
while (iter) {
|
||||||
const struct gui_panel_hook *h = iter;
|
struct gui_panel_hook *h = gui_hook(iter);
|
||||||
const struct gui_command *cmd = gui_list_begin(&h->list);
|
const struct gui_command *cmd = gui_list_begin(gui_hook_list(h));
|
||||||
while (cmd) {
|
while (cmd) {
|
||||||
/* execute command */
|
/* execute command */
|
||||||
cmd = gui_list_next(&h->list, cmd);
|
cmd = gui_list_next(gui_hook_list(h), cmd);
|
||||||
}
|
}
|
||||||
iter = iter->next;
|
iter = iter->next;
|
||||||
}
|
}
|
||||||
|
31
demo/demo.c
31
demo/demo.c
@ -2,7 +2,7 @@
|
|||||||
#define MAX_MEMORY (32 * 1024)
|
#define MAX_MEMORY (32 * 1024)
|
||||||
|
|
||||||
struct show_window {
|
struct show_window {
|
||||||
struct gui_panel_hook win;
|
struct gui_panel_hook hook;
|
||||||
gui_char in_buf[MAX_BUFFER];
|
gui_char in_buf[MAX_BUFFER];
|
||||||
gui_size in_len;
|
gui_size in_len;
|
||||||
gui_bool in_act;
|
gui_bool in_act;
|
||||||
@ -27,7 +27,7 @@ struct show_window {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct control_window {
|
struct control_window {
|
||||||
struct gui_panel_hook win;
|
struct gui_panel_hook hook;
|
||||||
gui_flags show_flags;
|
gui_flags show_flags;
|
||||||
gui_bool flag_min;
|
gui_bool flag_min;
|
||||||
gui_bool style_min;
|
gui_bool style_min;
|
||||||
@ -148,12 +148,12 @@ show_panel(struct show_window *show, struct gui_panel_stack *stack,
|
|||||||
struct gui_input *in, struct gui_canvas *canvas)
|
struct gui_input *in, struct gui_canvas *canvas)
|
||||||
{
|
{
|
||||||
struct gui_panel_layout layout;
|
struct gui_panel_layout layout;
|
||||||
gui_panel_begin_stacked(&layout, &show->win.panel, stack, "Show", canvas, in);
|
gui_hook_begin(&layout, &show->hook, stack, "Show", canvas, in);
|
||||||
combobox_panel(&layout, show);
|
combobox_panel(&layout, show);
|
||||||
widget_panel(&layout, show);
|
widget_panel(&layout, show);
|
||||||
graph_panel(&layout, show);
|
graph_panel(&layout, show);
|
||||||
table_panel(&layout, show);
|
table_panel(&layout, show);
|
||||||
gui_panel_end(&layout, &show->win.panel);
|
gui_hook_end(&layout, &show->hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -287,11 +287,11 @@ control_panel(struct control_window *control, struct gui_panel_stack *stack,
|
|||||||
{
|
{
|
||||||
gui_bool running;
|
gui_bool running;
|
||||||
struct gui_panel_layout layout;
|
struct gui_panel_layout layout;
|
||||||
running = gui_panel_begin_stacked(&layout, &control->win.panel, stack, "Control", canvas, in);
|
running = gui_hook_begin(&layout, &control->hook, stack, "Control", canvas, in);
|
||||||
flags_tab(&layout, control);
|
flags_tab(&layout, control);
|
||||||
style_tab(&layout, control, config);
|
style_tab(&layout, control, config);
|
||||||
color_tab(&layout, control, config);
|
color_tab(&layout, control, config);
|
||||||
gui_panel_end(&layout, &control->win.panel);
|
gui_hook_end(&layout, &control->hook);
|
||||||
return running;
|
return running;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,11 +301,12 @@ init_demo(struct show_window *show, struct control_window *control,
|
|||||||
{
|
{
|
||||||
memset(show, 0, sizeof(*show));
|
memset(show, 0, sizeof(*show));
|
||||||
gui_default_config(config);
|
gui_default_config(config);
|
||||||
gui_panel_init(&show->win.panel, 50, 50, 300, 500,
|
|
||||||
|
gui_hook_init(&show->hook, 50, 50, 300, 500,
|
||||||
GUI_PANEL_BORDER|GUI_PANEL_MOVEABLE|
|
GUI_PANEL_BORDER|GUI_PANEL_MOVEABLE|
|
||||||
GUI_PANEL_CLOSEABLE|GUI_PANEL_SCALEABLE|
|
GUI_PANEL_CLOSEABLE|GUI_PANEL_SCALEABLE|
|
||||||
GUI_PANEL_MINIMIZABLE, config, font);
|
GUI_PANEL_MINIMIZABLE, config, font);
|
||||||
gui_stack_push(stack, &show->win.panel);
|
gui_stack_push_hook(stack, &show->hook);
|
||||||
|
|
||||||
show->wid_min = gui_true;
|
show->wid_min = gui_true;
|
||||||
show->diff_min = gui_true;
|
show->diff_min = gui_true;
|
||||||
@ -314,10 +315,10 @@ init_demo(struct show_window *show, struct control_window *control,
|
|||||||
show->spinner = 100;
|
show->spinner = 100;
|
||||||
|
|
||||||
memset(control, 0, sizeof(*control));
|
memset(control, 0, sizeof(*control));
|
||||||
gui_panel_init(&control->win.panel, 380, 50, 400, 350,
|
gui_hook_init(&control->hook, 380, 50, 400, 350,
|
||||||
GUI_PANEL_BORDER|GUI_PANEL_MOVEABLE|GUI_PANEL_CLOSEABLE|GUI_PANEL_SCALEABLE, config, font);
|
GUI_PANEL_BORDER|GUI_PANEL_MOVEABLE|GUI_PANEL_CLOSEABLE|GUI_PANEL_SCALEABLE, config, font);
|
||||||
gui_stack_push(stack, &control->win.panel);
|
gui_stack_push_hook(stack, &control->hook);
|
||||||
control->show_flags = show->win.panel.flags;
|
control->show_flags = gui_hook_panel(&show->hook)->flags;
|
||||||
control->style_min = gui_true;
|
control->style_min = gui_true;
|
||||||
control->color_min = gui_true;
|
control->color_min = gui_true;
|
||||||
}
|
}
|
||||||
@ -334,14 +335,14 @@ run_demo(struct show_window *show, struct control_window *control, struct gui_pa
|
|||||||
gui_buffer_begin(NULL, buffer, width, height);
|
gui_buffer_begin(NULL, buffer, width, height);
|
||||||
gui_buffer_lock(&canvas, buffer, &sub, 0, width, height);
|
gui_buffer_lock(&canvas, buffer, &sub, 0, width, height);
|
||||||
running = control_panel(control, stack, in, &canvas, config);
|
running = control_panel(control, stack, in, &canvas, config);
|
||||||
gui_buffer_unlock(&control->win.list, buffer, &sub, &canvas, NULL);
|
gui_buffer_unlock(gui_hook_list(&control->hook), buffer, &sub, &canvas, NULL);
|
||||||
|
|
||||||
show->win.panel.flags = control->show_flags;
|
gui_hook_panel(&show->hook)->flags = control->show_flags;
|
||||||
gui_buffer_lock(&canvas, buffer, &sub, 0, width, height);
|
gui_buffer_lock(&canvas, buffer, &sub, 0, width, height);
|
||||||
show_panel(show, stack, in, &canvas);
|
show_panel(show, stack, in, &canvas);
|
||||||
if (show->win.panel.flags & GUI_PANEL_HIDDEN)
|
if (gui_hook_panel(&show->hook)->flags & GUI_PANEL_HIDDEN)
|
||||||
control->show_flags |= GUI_PANEL_HIDDEN;
|
control->show_flags |= GUI_PANEL_HIDDEN;
|
||||||
gui_buffer_unlock(&show->win.list, buffer, &sub, &canvas, NULL);
|
gui_buffer_unlock(gui_hook_list(&show->hook), buffer, &sub, &canvas, NULL);
|
||||||
gui_buffer_end(NULL, buffer, NULL, NULL);
|
gui_buffer_end(NULL, buffer, NULL, NULL);
|
||||||
return running;
|
return running;
|
||||||
}
|
}
|
||||||
|
@ -483,7 +483,7 @@ draw(struct gui_panel_stack *stack, int width, int height)
|
|||||||
struct gui_panel *iter = stack->begin;
|
struct gui_panel *iter = stack->begin;
|
||||||
if (!stack->count) return;
|
if (!stack->count) return;
|
||||||
while (iter) {
|
while (iter) {
|
||||||
struct gui_panel_hook *hook = (void*)iter;
|
struct gui_panel_hook *hook = gui_hook(iter);
|
||||||
execute(&hook->list, width, height);
|
execute(&hook->list, width, height);
|
||||||
iter = iter->next;
|
iter = iter->next;
|
||||||
}
|
}
|
||||||
|
@ -347,8 +347,8 @@ draw(XSurface *surf, struct gui_panel_stack *stack)
|
|||||||
struct gui_panel *iter = stack->begin;
|
struct gui_panel *iter = stack->begin;
|
||||||
if (!stack->count) return;
|
if (!stack->count) return;
|
||||||
while (iter) {
|
while (iter) {
|
||||||
struct gui_panel_hook *hook = (void*)iter;
|
struct gui_panel_hook *hook = gui_hook(iter);
|
||||||
execute(surf, &hook->list);
|
execute(surf, gui_hook_list(hook));
|
||||||
iter = iter->next;
|
iter = iter->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
gui.h
25
gui.h
@ -13,6 +13,10 @@ extern "C" {
|
|||||||
#define GUI_UTF_SIZE 4
|
#define GUI_UTF_SIZE 4
|
||||||
#define GUI_INPUT_MAX 16
|
#define GUI_INPUT_MAX 16
|
||||||
#define GUI_UTF_INVALID 0xFFFD
|
#define GUI_UTF_INVALID 0xFFFD
|
||||||
|
#define GUI_HOOK_PANEL_NAME panel
|
||||||
|
#define GUI_HOOK_LIST_NAME list
|
||||||
|
#define GUI_HOOK_ATTR(T, name) struct T name
|
||||||
|
#define GUI_HOOK_OUT gui_command_list
|
||||||
|
|
||||||
#ifdef GUI_USE_FIXED_TYPES
|
#ifdef GUI_USE_FIXED_TYPES
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -427,9 +431,10 @@ struct gui_panel_stack {
|
|||||||
struct gui_panel *end;
|
struct gui_panel *end;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct gui_panel_hook {
|
struct gui_panel_hook {
|
||||||
struct gui_panel panel;
|
GUI_HOOK_ATTR(gui_panel, GUI_HOOK_PANEL_NAME);
|
||||||
struct gui_command_list list;
|
GUI_HOOK_ATTR(GUI_HOOK_OUT, GUI_HOOK_LIST_NAME);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Input */
|
/* Input */
|
||||||
@ -583,6 +588,22 @@ void gui_stack_clear(struct gui_panel_stack*);
|
|||||||
void gui_stack_push(struct gui_panel_stack*, struct gui_panel*);
|
void gui_stack_push(struct gui_panel_stack*, struct gui_panel*);
|
||||||
void gui_stack_pop(struct gui_panel_stack*, struct gui_panel*);
|
void gui_stack_pop(struct gui_panel_stack*, struct gui_panel*);
|
||||||
|
|
||||||
|
|
||||||
|
/* Hook */
|
||||||
|
#define gui_hook(p) ((struct gui_panel_hook*)(p))
|
||||||
|
#define gui_hook_panel(h) (&((h)->GUI_HOOK_PANEL_NAME))
|
||||||
|
#define gui_hook_list(h) (&((h)->GUI_HOOK_LIST_NAME))
|
||||||
|
#define gui_hook_init(hook, x, y, w, h, flags, config, font)\
|
||||||
|
gui_panel_init(&(*(hook)).GUI_HOOK_PANEL_NAME, x, y, w, h, flags, config, font)
|
||||||
|
#define gui_hook_begin(layout, hook, stack, title, canvas, in)\
|
||||||
|
gui_panel_begin_stacked(layout, &(*(hook)).GUI_HOOK_PANEL_NAME, stack, title, canvas, in)
|
||||||
|
#define gui_hook_end(layout, hook)\
|
||||||
|
gui_panel_end((layout), &(hook)->GUI_HOOK_PANEL_NAME)
|
||||||
|
#define gui_stack_push_hook(stack, hook)\
|
||||||
|
gui_stack_push(stack, &(*(hook)).GUI_HOOK_PANEL_NAME)
|
||||||
|
#define gui_stack_pop_hook(stack, hook)\
|
||||||
|
gui_stack_pop(stack, &(*(hook)).GUI_HOOK_PANEL_NAME)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user