added panel tabs

This commit is contained in:
vurtun 2015-03-30 17:31:55 +02:00
parent a23649ba9f
commit 4fb9870f33
3 changed files with 65 additions and 7 deletions

View File

@ -19,7 +19,7 @@
#define UNUSED(v) (void)v
#define WIN_WIDTH 800
#define WIN_HEIGHT 600
#define MAX_MEMORY (128 * 1024)
#define MAX_MEMORY (256 * 1024)
#define MAX_PANELS 16
#define DTIME 33
#define MAX_BUFFER 64
@ -352,6 +352,7 @@ main(int argc, char *argv[])
struct gui_font *font;
struct gui_panel *panel;
struct gui_panel *subpanel;
struct gui_panel tab;
struct gui_config config;
struct gui_memory memory;
struct gui_input input;
@ -371,6 +372,8 @@ main(int argc, char *argv[])
gui_size item_cur = 0;
gui_float list_off = 0.0f;
gui_bool list_sel[5];
gui_bool minimized = gui_true;
memset(list_sel, 0, sizeof list_sel);
/* Window */
UNUSED(argc); UNUSED(argv);
@ -441,6 +444,11 @@ main(int argc, char *argv[])
gui_panel_layout(panel, 100, 1);
gui_panel_plot(panel, values, LEN(values));
gui_panel_histo(panel, values, LEN(values));
minimized = gui_panel_tab_begin(panel, &tab, "Options", minimized);
gui_panel_layout(&tab, 30, 1);
if (gui_panel_button_text(&tab, "button", GUI_BUTTON_SWITCH))
fprintf(stdout, "tab button pressed!\n");
gui_panel_tab_end(panel, &tab);
list_off = gui_panel_list(panel, list_sel, items, LEN(items), list_off, 30);
gui_end_panel(ctx, panel, NULL);

59
gui.c
View File

@ -1601,11 +1601,13 @@ gui_panel_begin(struct gui_panel *panel, struct gui_draw_buffer *out,
clip.h = h - panel->header_height;
if (panel->flags & GUI_PANEL_SCROLLBAR)
clip.h -= (config->panel_padding.y + config->item_padding.y);
else clip.h = null_rect.h;
} else {
clip.x = x; clip.y = y;
clip.w = w; clip.h = h;
if (panel->flags & GUI_PANEL_SCROLLBAR)
clip.h -= config->panel_padding.y;
else clip.h = null_rect.h;
panel->header_height = config->panel_padding.y + config->item_padding.y;
}
@ -2439,6 +2441,45 @@ gui_panel_list(struct gui_panel *panel, gui_bool *selection,
return list.offset;
}
gui_bool
gui_panel_tab_begin(struct gui_panel *panel, struct gui_panel* tab,
const char *title, gui_bool minimized)
{
struct gui_rect bounds;
gui_float old_height;
gui_size old_cols;
gui_flags flags;
assert(panel);
assert(tab);
if (!panel || !tab) return minimized;
if ((panel->flags & GUI_PANEL_HIDDEN) || panel->minimized)
return minimized;
old_height = panel->row_height;
old_cols = panel->row_columns;
gui_panel_layout(panel, 0, 1);
gui_panel_alloc_space(&bounds, panel);
panel->row_height = old_height;
panel->row_columns = old_cols;
gui_panel_init(tab, panel->config, panel->font);
tab->minimized = minimized;
flags = GUI_PANEL_BORDER|GUI_PANEL_MINIMIZABLE|GUI_PANEL_HEADER;
gui_panel_begin(tab, panel->out, panel->in, title,
bounds.x, bounds.y, bounds.w, null_rect.h, flags);
return tab->minimized;
}
void
gui_panel_tab_end(struct gui_panel *panel, struct gui_panel *tab)
{
if (panel->minimized || (panel->flags & GUI_PANEL_HIDDEN)) return;
gui_panel_end(tab);
panel->at_y -= panel->row_height;
panel->at_y += tab->height + tab->config->item_spacing.y;
}
void
gui_panel_end(struct gui_panel *panel)
{
@ -2545,6 +2586,7 @@ gui_alloc_panel(struct gui_context *ctx)
panel = ctx->free_list;
ctx->free_list = panel->next;
panel->next = NULL;
panel->prev = NULL;
return panel;
} else if (ctx->panel_capacity) {
ctx->panel_capacity--;
@ -2565,7 +2607,7 @@ gui_free_panel(struct gui_context *ctx, struct gui_context_panel *panel)
static void
gui_stack_push(struct gui_context *ctx, struct gui_context_panel *panel)
{
if (!ctx->stack_end) {
if (!ctx->stack_begin) {
ctx->stack_begin = panel;
ctx->stack_end = panel;
return;
@ -2585,6 +2627,8 @@ gui_stack_remove(struct gui_context *ctx, struct gui_context_panel *panel)
panel->next->prev = panel->prev;
if (ctx->stack_begin == panel)
ctx->stack_begin = panel->next;
if (ctx->stack_end == panel)
ctx->stack_end = panel->prev;
panel->next = NULL;
panel->prev = NULL;
}
@ -2628,10 +2672,12 @@ gui_panel_del(struct gui_context *ctx, struct gui_panel *panel)
void
gui_begin(struct gui_context *ctx, gui_float w, gui_float h)
{
struct gui_context_panel *iter;
assert(ctx);
if (!ctx) return;
ctx->width = w;
ctx->height = h;
iter = ctx->stack_begin;
}
gui_bool
@ -2656,7 +2702,7 @@ gui_begin_panel(struct gui_context *ctx, struct gui_panel *panel,
in = ctx->input;
cpanel = (struct gui_context_panel*)panel;
inpanel = INBOX(in->mouse_prev.x,in->mouse_prev.y, cpanel->x, cpanel->y, cpanel->w, cpanel->h);
if (in->mouse_down && in->mouse_clicked && inpanel) {
if (in->mouse_down && in->mouse_clicked && inpanel && cpanel != ctx->active) {
struct gui_context_panel *iter = cpanel->next;
while (iter) {
if (INBOX(in->mouse_prev.x, in->mouse_prev.y, iter->x, iter->y, iter->w, iter->h))
@ -2712,8 +2758,8 @@ gui_begin_panel(struct gui_context *ctx, struct gui_panel *panel,
out->command_capacity = global->command_capacity - global->command_size;
out->clips = global->clips;
out->clip_capacity = global->clip_capacity;
return gui_panel_begin(panel, out, (ctx->active == cpanel) ? ctx->input : NULL,
title, cpanel->x, cpanel->y, cpanel->w, cpanel->h, flags);
in = (ctx->active == cpanel) ? ctx->input : NULL;
return gui_panel_begin(panel, out, in, title, cpanel->x, cpanel->y, cpanel->w, cpanel->h, flags);
}
void
@ -2744,10 +2790,11 @@ gui_end(struct gui_context *ctx, struct gui_output *output,
gui_size n = 0;
struct gui_context_panel *iter = ctx->stack_begin;
while (iter) {
ctx->output_list[n++] = &iter->list;
if (!(iter->panel.flags & GUI_PANEL_HIDDEN))
ctx->output_list[n++] = &iter->list;
iter = iter->next;
}
output->list_size = ctx->panel_size;
output->list_size = n;
output->list = ctx->output_list;
}
gui_output_end(&ctx->global_buffer, NULL, status);

3
gui.h
View File

@ -429,6 +429,9 @@ gui_int gui_panel_plot(struct gui_panel*, const gui_float *values,
gui_size value_count);
gui_int gui_panel_histo(struct gui_panel*, const gui_float *values,
gui_size value_count);
gui_bool gui_panel_tab_begin(struct gui_panel*, struct gui_panel* tab,
const char *title, gui_bool minimized);
void gui_panel_tab_end(struct gui_panel *panel, struct gui_panel *tab);
gui_float gui_panel_list(struct gui_panel*, gui_bool *selected, const char *items[],
gui_size item_count, gui_float offset, gui_float item_height);
void gui_panel_end(struct gui_panel*);