renamed everything + added more widget animations

This commit is contained in:
vurtun 2015-08-29 11:04:09 +02:00
parent 493c16ec34
commit 02c42176a6
4 changed files with 1992 additions and 2177 deletions

View File

@ -6,8 +6,8 @@ written in ANSI C. It was designed as a simple embeddable user interface for
application and does not have any direct dependencies. The toolkit was mainly application and does not have any direct dependencies. The toolkit was mainly
developed to have a simple GUI for the X11 window system but can be used developed to have a simple GUI for the X11 window system but can be used
with other platforms like win32 or libraries like nanovg. The library uses with other platforms like win32 or libraries like nanovg. The library uses
no heap allocation outside of draw commands and as a whole has a low memory no heap allocation outside of draw commands and as a whole has a low default
footprint. heap memory footprint.
## Features ## Features
- Immediate mode graphical user interface toolkit - Immediate mode graphical user interface toolkit
@ -229,9 +229,7 @@ gui_command_queue_init(&queue, &alloc, initial_size, grow_factor);
## FAQ ## FAQ
#### Where is the demo/example code? #### Where is the demo/example code?
The demo and example code can be found in the demo folder. The demo and example code can be found in the demo folder.
There is demo code for Linux(X11), Windows(win32) and OpenGL(SDL2, freetype). There is demo code for Linux(X11) and nanovg.
As for now there will be no DirectX demo since I don't have experience
programming using DirectX but you are more than welcome to provide one.
#### Why did you use ANSI C and not C99 or C++? #### Why did you use ANSI C and not C99 or C++?
Personally I stay out of all "discussions" about C vs C++ since they are totally Personally I stay out of all "discussions" about C vs C++ since they are totally

View File

@ -1,7 +1,7 @@
#define MAX_BUFFER 64 #define MAX_BUFFER 64
#define MAX_MEMORY (16 * 1024) #define MAX_MEMORY (16 * 1024)
#define WINDOW_WIDTH 800 #define WINDOW_WIDTH 1200
#define WINDOW_HEIGHT 600 #define WINDOW_HEIGHT 800
#include <stdio.h> #include <stdio.h>
@ -25,31 +25,30 @@
#define COLOR_MAP(COLOR)\ #define COLOR_MAP(COLOR)\
COLOR(text)\ COLOR(text)\
COLOR(panel)\ COLOR(text_hovering)\
COLOR(text_active)\
COLOR(window)\
COLOR(header)\ COLOR(header)\
COLOR(border)\ COLOR(border)\
COLOR(button)\ COLOR(button)\
COLOR(button_hover)\ COLOR(button_hover)\
COLOR(button_toggle)\ COLOR(button_active)\
COLOR(button_hover_font)\ COLOR(toggle)\
COLOR(check)\ COLOR(toggle_hover)\
COLOR(check_background)\ COLOR(toggle_cursor)\
COLOR(check_active)\
COLOR(option)\
COLOR(option_background)\
COLOR(option_active)\
COLOR(slider)\ COLOR(slider)\
COLOR(slider_bar)\
COLOR(slider_cursor)\ COLOR(slider_cursor)\
COLOR(slider_cursor_hover)\
COLOR(slider_cursor_active)\
COLOR(progress)\ COLOR(progress)\
COLOR(progress_cursor)\ COLOR(progress_cursor)\
COLOR(progress_cursor_hover)\
COLOR(progress_cursor_active)\
COLOR(input)\ COLOR(input)\
COLOR(input_cursor)\ COLOR(input_cursor)\
COLOR(input_text)\ COLOR(input_text)\
COLOR(selector)\ COLOR(spinner)\
COLOR(selector_triangle)\ COLOR(spinner_triangle)\
COLOR(selector_text)\
COLOR(selector_button)\
COLOR(histo)\ COLOR(histo)\
COLOR(histo_bars)\ COLOR(histo_bars)\
COLOR(histo_negative)\ COLOR(histo_negative)\
@ -59,14 +58,15 @@
COLOR(plot_highlight)\ COLOR(plot_highlight)\
COLOR(scrollbar)\ COLOR(scrollbar)\
COLOR(scrollbar_cursor)\ COLOR(scrollbar_cursor)\
COLOR(scrollbar_cursor_hover)\
COLOR(scrollbar_cursor_active)\
COLOR(table_lines)\ COLOR(table_lines)\
COLOR(tab_header)\ COLOR(tab_header)\
COLOR(shelf)\ COLOR(shelf)\
COLOR(shelf_text)\ COLOR(shelf_text)\
COLOR(shelf_active)\ COLOR(shelf_active)\
COLOR(shelf_active_text)\ COLOR(shelf_active_text)\
COLOR(scaler)\ COLOR(scaler)
COLOR(layout_scaler)
enum weapon_types { enum weapon_types {
#define WEAPON(id, name) WEAPON_##id, #define WEAPON(id, name) WEAPON_##id,
@ -231,12 +231,12 @@ upload_tree(struct test_tree *base, struct gui_tree *tree, struct tree_node *nod
enum gui_tree_node_operation op; enum gui_tree_node_operation op;
if (node->count) { if (node->count) {
i = 0; i = 0;
op = gui_panel_tree_begin_node(tree, node->name, &node->state); op = gui_tree_begin_node(tree, node->name, &node->state);
while (i < node->count) while (i < node->count)
i += upload_tree(base, tree, node->children[i]); i += upload_tree(base, tree, node->children[i]);
gui_panel_tree_end_node(tree); gui_tree_end_node(tree);
} }
else op = gui_panel_tree_leaf(tree, node->name, &node->state); else op = gui_tree_leaf(tree, node->name, &node->state);
switch (op) { switch (op) {
case GUI_NODE_NOP: break; case GUI_NODE_NOP: break;
@ -268,45 +268,45 @@ struct color_picker {
}; };
static gui_bool static gui_bool
color_picker(struct gui_panel_layout *panel, struct color_picker* control, color_picker(struct gui_context *panel, struct color_picker* control,
const char *name, struct gui_color *color) const char *name, struct gui_color *color)
{ {
int i; int i;
gui_byte *iter; gui_byte *iter;
gui_bool ret = gui_true; gui_bool ret = gui_true;
struct gui_panel_layout popup; struct gui_context popup;
gui_panel_popup_begin(panel, &popup, GUI_POPUP_STATIC, gui_rect(10, 100, 280, 280), gui_vec2(0,0)); gui_popup_begin(panel, &popup, GUI_POPUP_STATIC, gui_rect(10, 100, 280, 280), gui_vec2(0,0));
{ {
if (gui_panel_header(&popup, "Color", GUI_CLOSEABLE, GUI_CLOSEABLE, GUI_HEADER_LEFT)) { if (gui_header(&popup, "Color", GUI_CLOSEABLE, GUI_CLOSEABLE, GUI_HEADER_LEFT)) {
gui_panel_popup_close(&popup); gui_popup_close(&popup);
return gui_false; return gui_false;
} }
gui_panel_row_dynamic(&popup, 30, 2); gui_layout_row_dynamic(&popup, 30, 2);
gui_panel_label(&popup, name, GUI_TEXT_LEFT); gui_label(&popup, name, GUI_TEXT_LEFT);
gui_panel_button_color(&popup, control->color, GUI_BUTTON_DEFAULT); gui_button_color(&popup, control->color, GUI_BUTTON_DEFAULT);
iter = &control->color.r; iter = &control->color.r;
gui_panel_row_dynamic(&popup, 30, 2); gui_layout_row_dynamic(&popup, 30, 2);
for (i = 0; i < 4; ++i, iter++) { for (i = 0; i < 4; ++i, iter++) {
gui_float t = *iter; gui_float t = *iter;
t = gui_panel_slider(&popup, 0, t, 255, 10); t = gui_slider(&popup, 0, t, 255, 10);
*iter = (gui_byte)t; *iter = (gui_byte)t;
*iter = (gui_byte)gui_panel_spinner(&popup, 0, *iter, 255, 1, NULL); *iter = (gui_byte)gui_spinner(&popup, 0, *iter, 255, 1, NULL);
} }
gui_panel_row_dynamic(&popup, 30, 3); gui_layout_row_dynamic(&popup, 30, 3);
gui_panel_spacing(&popup, 1); gui_spacing(&popup, 1);
if (gui_panel_button_text(&popup, "ok", GUI_BUTTON_DEFAULT)) { if (gui_button_text(&popup, "ok", GUI_BUTTON_DEFAULT)) {
gui_panel_popup_close(&popup); gui_popup_close(&popup);
*color = control->color; *color = control->color;
ret = gui_false; ret = gui_false;
} }
if (gui_panel_button_text(&popup, "cancel", GUI_BUTTON_DEFAULT)) { if (gui_button_text(&popup, "cancel", GUI_BUTTON_DEFAULT)) {
gui_panel_popup_close(&popup); gui_popup_close(&popup);
ret = gui_false; ret = gui_false;
} }
} }
gui_panel_popup_end(panel, &popup); gui_popup_end(panel, &popup);
control->active = (gui_state)ret; control->active = (gui_state)ret;
return ret; return ret;
} }
@ -315,14 +315,14 @@ color_picker(struct gui_panel_layout *panel, struct color_picker* control,
* LABEL * LABEL
* ----------------------------------------------------------------- */ * ----------------------------------------------------------------- */
static void static void
gui_panel_labelf(struct gui_panel_layout *panel, enum gui_text_align align, const gui_char *fmt, ...) gui_labelf(struct gui_context *panel, enum gui_text_align align, const gui_char *fmt, ...)
{ {
gui_char buffer[1024]; gui_char buffer[1024];
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, args); vsnprintf(buffer, sizeof(buffer), fmt, args);
buffer[1023] = 0; buffer[1023] = 0;
gui_panel_label(panel, buffer, align); gui_label(panel, buffer, align);
va_end(args); va_end(args);
} }
@ -353,82 +353,82 @@ struct color_combo_box {
}; };
static void static void
combo_box(struct gui_panel_layout *panel, struct combobox *combo, combo_box(struct gui_context *panel, struct combobox *combo,
const char**values, gui_size count) const char**values, gui_size count)
{ {
gui_panel_combo(panel, values, count, &combo->selected, 30, gui_combo(panel, values, count, &combo->selected, 30,
&combo->active, &combo->scrollbar); &combo->active, &combo->scrollbar);
} }
static void static void
prog_combo_box(struct gui_panel_layout *panel, gui_size *values, gui_size count, prog_combo_box(struct gui_context *panel, gui_size *values, gui_size count,
struct prog_combo_box *demo) struct prog_combo_box *demo)
{ {
gui_size i = 0; gui_size i = 0;
gui_int sum = 0; gui_int sum = 0;
gui_char buffer[64]; gui_char buffer[64];
struct gui_panel_layout combo; struct gui_context combo;
memset(&combo, 0, sizeof(combo)); memset(&combo, 0, sizeof(combo));
for (i = 0; i < count; ++i) for (i = 0; i < count; ++i)
sum += (gui_int)values[i]; sum += (gui_int)values[i];
sprintf(buffer, "%d", sum); sprintf(buffer, "%d", sum);
gui_panel_combo_begin(panel, &combo, buffer, &demo->active, demo->scrollbar); gui_combo_begin(panel, &combo, buffer, &demo->active, demo->scrollbar);
{ {
gui_panel_row_dynamic(&combo, 30, 1); gui_layout_row_dynamic(&combo, 30, 1);
for (i = 0; i < count; ++i) for (i = 0; i < count; ++i)
values[i] = gui_panel_progress(&combo, values[i], 100, gui_true); values[i] = gui_progress(&combo, values[i], 100, gui_true);
} }
demo->scrollbar = gui_panel_combo_end(panel, &combo); demo->scrollbar = gui_combo_end(panel, &combo);
} }
static void static void
color_combo_box(struct gui_panel_layout *panel, struct color_combo_box *demo) color_combo_box(struct gui_context *panel, struct color_combo_box *demo)
{ {
/* color slider progressbar */ /* color slider progressbar */
gui_char buffer[32]; gui_char buffer[32];
struct gui_panel_layout combo; struct gui_context combo;
memset(&combo, 0, sizeof(combo)); memset(&combo, 0, sizeof(combo));
sprintf(buffer, "#%02x%02x%02x%02x", demo->color.r, demo->color.g, sprintf(buffer, "#%02x%02x%02x%02x", demo->color.r, demo->color.g,
demo->color.b, demo->color.a); demo->color.b, demo->color.a);
gui_panel_combo_begin(panel, &combo, buffer, &demo->active, demo->scrollbar); gui_combo_begin(panel, &combo, buffer, &demo->active, demo->scrollbar);
{ {
int i; int i;
const char *color_names[] = {"R:", "G:", "B:", "A:"}; const char *color_names[] = {"R:", "G:", "B:", "A:"};
gui_float ratios[] = {0.15f, 0.85f}; gui_float ratios[] = {0.15f, 0.85f};
gui_byte *iter = &demo->color.r; gui_byte *iter = &demo->color.r;
gui_panel_row(&combo, GUI_DYNAMIC, 30, 2, ratios); gui_layout_row(&combo, GUI_DYNAMIC, 30, 2, ratios);
for (i = 0; i < 4; ++i, iter++) { for (i = 0; i < 4; ++i, iter++) {
gui_float t = *iter; gui_float t = *iter;
gui_panel_label(&combo, color_names[i], GUI_TEXT_LEFT); gui_label(&combo, color_names[i], GUI_TEXT_LEFT);
t = gui_panel_slider(&combo, 0, t, 255, 5); t = gui_slider(&combo, 0, t, 255, 5);
*iter = (gui_byte)t; *iter = (gui_byte)t;
} }
} }
demo->scrollbar = gui_panel_combo_end(panel, &combo); demo->scrollbar = gui_combo_end(panel, &combo);
} }
static void static void
check_combo_box(struct gui_panel_layout *panel, gui_bool *values, gui_size count, check_combo_box(struct gui_context *panel, gui_bool *values, gui_size count,
struct check_combo_box *demo) struct check_combo_box *demo)
{ {
/* checkbox combobox */ /* checkbox combobox */
gui_int sum = 0; gui_int sum = 0;
gui_size i = 0; gui_size i = 0;
gui_char buffer[64]; gui_char buffer[64];
struct gui_panel_layout combo; struct gui_context combo;
memset(&combo, 0, sizeof(combo)); memset(&combo, 0, sizeof(combo));
for (i = 0; i < count; ++i) for (i = 0; i < count; ++i)
sum += (gui_int)values[i]; sum += (gui_int)values[i];
sprintf(buffer, "%d", sum); sprintf(buffer, "%d", sum);
gui_panel_combo_begin(panel, &combo, buffer, &demo->active, demo->scrollbar); gui_combo_begin(panel, &combo, buffer, &demo->active, demo->scrollbar);
{ {
gui_panel_row_dynamic(&combo, 30, 1); gui_layout_row_dynamic(&combo, 30, 1);
for (i = 0; i < count; ++i) for (i = 0; i < count; ++i)
values[i] = gui_panel_check(&combo, weapons[i], values[i]); values[i] = gui_check(&combo, weapons[i], values[i]);
} }
demo->scrollbar = gui_panel_combo_end(panel, &combo); demo->scrollbar = gui_combo_end(panel, &combo);
} }
/* ================================================================= /* =================================================================
@ -487,10 +487,10 @@ struct demo_gui {
void *memory; void *memory;
const struct gui_input *input; const struct gui_input *input;
struct gui_command_queue queue; struct gui_command_queue queue;
struct gui_config config; struct gui_style config;
struct gui_font font; struct gui_font font;
struct gui_panel panel; struct gui_window panel;
struct gui_panel sub; struct gui_window sub;
struct state state; struct state state;
gui_size w, h; gui_size w, h;
}; };
@ -499,53 +499,52 @@ struct demo_gui {
* WIDGETS * WIDGETS
* ----------------------------------------------------------------- */ * ----------------------------------------------------------------- */
static void static void
widget_panel(struct gui_panel_layout *panel, struct state *demo) widget_panel(struct gui_context *panel, struct state *demo)
{ {
/* Labels */ /* Labels */
gui_panel_row_dynamic(panel, 30, 1); gui_layout_row_dynamic(panel, 30, 1);
demo->scaleable = gui_panel_check(panel, "Scaleable Layout", demo->scaleable); demo->scaleable = gui_check(panel, "Scaleable Layout", demo->scaleable);
if (!demo->scaleable) if (!demo->scaleable)
gui_panel_row_static(panel, 30, 150, 1); gui_layout_row_static(panel, 30, 150, 1);
gui_panel_label(panel, "text left", GUI_TEXT_LEFT); gui_label(panel, "text left", GUI_TEXT_LEFT);
gui_panel_label(panel, "text center", GUI_TEXT_CENTERED); gui_label(panel, "text center", GUI_TEXT_CENTERED);
gui_panel_label(panel, "text right", GUI_TEXT_RIGHT); gui_label(panel, "text right", GUI_TEXT_RIGHT);
/* Buttons */ /* Buttons */
if (gui_panel_button_text(panel, "button", GUI_BUTTON_DEFAULT)) if (gui_button_text(panel, "button", GUI_BUTTON_DEFAULT))
demo->popup = gui_true; demo->popup = gui_true;
if (gui_panel_button_text_triangle(panel, GUI_RIGHT, "next", GUI_TEXT_LEFT, GUI_BUTTON_DEFAULT)) if (gui_button_text_symbol(panel, GUI_SYMBOL_TRIANGLE_RIGHT, "next", GUI_TEXT_LEFT, GUI_BUTTON_DEFAULT))
fprintf(stdout, "right triangle button pressed!\n"); fprintf(stdout, "right triangle button pressed!\n");
if (gui_panel_button_text_triangle(panel,GUI_LEFT,"previous",GUI_TEXT_RIGHT,GUI_BUTTON_DEFAULT)) if (gui_button_text_symbol(panel,GUI_SYMBOL_TRIANGLE_LEFT,"previous",GUI_TEXT_RIGHT,GUI_BUTTON_DEFAULT))
fprintf(stdout, "left triangle button pressed!\n"); fprintf(stdout, "left triangle button pressed!\n");
demo->toggle = gui_panel_button_toggle(panel, "toggle", demo->toggle); demo->toggle = gui_button_toggle(panel, "toggle", demo->toggle);
/* Checkbox + Radio buttons */ /* Checkbox + Radio buttons */
demo->checkbox = gui_panel_check(panel, "checkbox", demo->checkbox); demo->checkbox = gui_check(panel, "checkbox", demo->checkbox);
if (!demo->scaleable) if (!demo->scaleable)
gui_panel_row_static(panel, 30, 75, 2); gui_layout_row_static(panel, 30, 75, 2);
else gui_panel_row_dynamic(panel, 30, 2); else gui_layout_row_dynamic(panel, 30, 2);
if (gui_panel_option(panel, "option 0", demo->option == 0)) if (gui_option(panel, "option 0", demo->option == 0))
demo->option = 0; demo->option = 0;
if (gui_panel_option(panel, "option 1", demo->option == 1)) if (gui_option(panel, "option 1", demo->option == 1))
demo->option = 1; demo->option = 1;
{ {
/* custom row layout by array */ /* custom row layout by array */
const gui_float ratio[] = {0.8f, 0.2f}; const gui_float ratio[] = {0.8f, 0.2f};
const gui_float pixel[] = {150.0f, 30.0f}; const gui_float pixel[] = {150.0f, 30.0f};
enum gui_panel_row_layout_format fmt = (demo->scaleable) ? GUI_DYNAMIC : GUI_STATIC; enum gui_row_layout_format fmt = (demo->scaleable) ? GUI_DYNAMIC : GUI_STATIC;
gui_panel_row(panel, fmt, 30, 2, (fmt == GUI_DYNAMIC) ? ratio: pixel); gui_layout_row(panel, fmt, 30, 2, (fmt == GUI_DYNAMIC) ? ratio: pixel);
demo->slider = gui_panel_slider(panel, 0, demo->slider, 10, 1.0f); demo->slider = gui_slider(panel, 0, demo->slider, 10, 1.0f);
gui_panel_labelf(panel, GUI_TEXT_LEFT, "%.2f", demo->slider); gui_labelf(panel, GUI_TEXT_LEFT, "%.2f", demo->slider);
demo->progressbar = gui_panel_progress(panel, demo->progressbar, 100, gui_true); demo->progressbar = gui_progress(panel, demo->progressbar, 100, gui_true);
gui_panel_labelf(panel, GUI_TEXT_LEFT, "%lu", demo->progressbar); gui_labelf(panel, GUI_TEXT_LEFT, "%lu", demo->progressbar);
} }
/* item selection */ /* item selection */
if (!demo->scaleable) gui_panel_row_static(panel, 30, 150, 1); if (!demo->scaleable) gui_layout_row_static(panel, 30, 150, 1);
else gui_panel_row_dynamic(panel, 30, 1); else gui_layout_row_dynamic(panel, 30, 1);
demo->item_current = gui_panel_selector(panel, weapons, LEN(weapons), demo->item_current); demo->spinner = gui_spinner(panel, 0, demo->spinner, 250, 10, &demo->spinner_active);
demo->spinner = gui_panel_spinner(panel, 0, demo->spinner, 250, 10, &demo->spinner_active);
/* combo boxes */ /* combo boxes */
combo_box(panel, &demo->combo, weapons, LEN(weapons)); combo_box(panel, &demo->combo, weapons, LEN(weapons));
@ -555,100 +554,100 @@ widget_panel(struct gui_panel_layout *panel, struct state *demo)
{ {
/* immediate mode custom row layout */ /* immediate mode custom row layout */
enum gui_panel_row_layout_format fmt = (demo->scaleable) ? GUI_DYNAMIC : GUI_STATIC; enum gui_row_layout_format fmt = (demo->scaleable) ? GUI_DYNAMIC : GUI_STATIC;
gui_panel_row_begin(panel, fmt, 30, 2); gui_layout_row_begin(panel, fmt, 30, 2);
{ {
gui_panel_row_push(panel,(fmt == GUI_DYNAMIC) ? 0.7f : 100); gui_layout_row_push(panel,(fmt == GUI_DYNAMIC) ? 0.7f : 100);
gui_panel_editbox(panel, &demo->edit); gui_editbox(panel, &demo->edit);
gui_panel_row_push(panel, (fmt == GUI_DYNAMIC) ? 0.3f : 80); gui_layout_row_push(panel, (fmt == GUI_DYNAMIC) ? 0.3f : 80);
if (gui_panel_button_text(panel, "submit", GUI_BUTTON_DEFAULT)) { if (gui_button_text(panel, "submit", GUI_BUTTON_DEFAULT)) {
gui_edit_box_clear(&demo->edit); gui_edit_box_clear(&demo->edit);
fprintf(stdout, "command executed!\n"); fprintf(stdout, "command executed!\n");
} }
} }
gui_panel_row_end(panel); gui_layout_row_end(panel);
} }
} }
static void static void
table_panel(struct gui_panel_layout *panel) table_panel(struct gui_context *panel)
{ {
gui_size i = 0; gui_size i = 0;
const char *table[] = {"Move forward", "w", "Move back", "s", "Move left", "a", const char *table[] = {"Move forward", "w", "Move back", "s", "Move left", "a",
"Move right", "d", "Jump", "SPACE", "Duck", "CTRL"}; "Move right", "d", "Jump", "SPACE", "Duck", "CTRL"};
gui_panel_table_begin(panel, GUI_TABLE_HHEADER, 30, 2); gui_table_begin(panel, GUI_TABLE_HHEADER, 30, 2);
gui_panel_label_colored(panel, "MOVEMENT", GUI_TEXT_CENTERED, gui_rgba(178, 122, 1, 255)); gui_label_colored(panel, "MOVEMENT", GUI_TEXT_CENTERED, gui_rgba(178, 122, 1, 255));
gui_panel_label_colored(panel, "KEY/BUTTON", GUI_TEXT_CENTERED, gui_rgba(178, 122, 1, 255)); gui_label_colored(panel, "KEY/BUTTON", GUI_TEXT_CENTERED, gui_rgba(178, 122, 1, 255));
for (i = 0; i < LEN(table); i += 2) { for (i = 0; i < LEN(table); i += 2) {
gui_panel_table_row(panel); gui_table_row(panel);
gui_panel_label(panel, table[i], GUI_TEXT_LEFT); gui_label(panel, table[i], GUI_TEXT_LEFT);
gui_panel_label(panel, table[i+1], GUI_TEXT_CENTERED); gui_label(panel, table[i+1], GUI_TEXT_CENTERED);
} }
gui_panel_table_end(panel); gui_table_end(panel);
} }
/* ----------------------------------------------------------------- /* -----------------------------------------------------------------
* STYLE * STYLE
* ----------------------------------------------------------------- */ * ----------------------------------------------------------------- */
static void static void
update_flags(struct gui_panel_layout *panel) update_flags(struct gui_context *panel)
{ {
gui_size n = 0; gui_size n = 0;
gui_flags res = 0; gui_flags res = 0;
gui_flags i = 0x01; gui_flags i = 0x01;
const char *options[]={"Hidden","Border","Header Border", "Moveable","Scaleable", "Minimized", "ROM"}; const char *options[]={"Hidden","Border","Header Border", "Moveable","Scaleable", "Minimized", "ROM"};
gui_panel_row_dynamic(panel, 30, 2); gui_layout_row_dynamic(panel, 30, 2);
do { do {
if (gui_panel_check(panel,options[n++],(panel->flags & i)?gui_true:gui_false)) if (gui_check(panel,options[n++],(panel->flags & i)?gui_true:gui_false))
res |= i; res |= i;
i = i << 1; i = i << 1;
} while (i <= GUI_PANEL_ROM); } while (i <= GUI_WINDOW_ROM);
panel->flags = res; panel->flags = res;
} }
static void static void
properties_tab(struct gui_panel_layout *panel, struct gui_config *config) properties_tab(struct gui_context *panel, struct gui_style *config)
{ {
int i = 0; int i = 0;
const char *properties[] = {"item spacing:", "item padding:", "panel padding:", const char *properties[] = {"item spacing:", "item padding:", "panel padding:",
"scaler size:", "scrollbar:"}; "scaler size:", "scrollbar:"};
gui_panel_row_dynamic(panel, 30, 3); gui_layout_row_dynamic(panel, 30, 3);
for (i = 0; i <= GUI_PROPERTY_SCROLLBAR_SIZE; ++i) { for (i = 0; i <= GUI_PROPERTY_SCROLLBAR_SIZE; ++i) {
gui_int tx, ty; gui_int tx, ty;
gui_panel_label(panel, properties[i], GUI_TEXT_LEFT); gui_label(panel, properties[i], GUI_TEXT_LEFT);
tx = gui_panel_spinner(panel,0,(gui_int)config->properties[i].x, 20, 1, NULL); tx = gui_spinner(panel,0,(gui_int)config->properties[i].x, 20, 1, NULL);
ty = gui_panel_spinner(panel,0,(gui_int)config->properties[i].y, 20, 1, NULL); ty = gui_spinner(panel,0,(gui_int)config->properties[i].y, 20, 1, NULL);
config->properties[i].x = (float)tx; config->properties[i].x = (float)tx;
config->properties[i].y = (float)ty; config->properties[i].y = (float)ty;
} }
} }
static void static void
round_tab(struct gui_panel_layout *panel, struct gui_config *config) round_tab(struct gui_context *panel, struct gui_style *config)
{ {
int i = 0; int i = 0;
const char *rounding[] = {"panel:", "button:", "checkbox:", "progress:", "input: ", const char *rounding[] = {"panel:", "button:", "checkbox:", "progress:", "input: ",
"graph:", "scrollbar:"}; "graph:", "scrollbar:"};
gui_panel_row_dynamic(panel, 30, 2); gui_layout_row_dynamic(panel, 30, 2);
for (i = 0; i < GUI_ROUNDING_MAX; ++i) { for (i = 0; i < GUI_ROUNDING_MAX; ++i) {
gui_int t; gui_int t;
gui_panel_label(panel, rounding[i], GUI_TEXT_LEFT); gui_label(panel, rounding[i], GUI_TEXT_LEFT);
t = gui_panel_spinner(panel,0,(gui_int)config->rounding[i], 20, 1, NULL); t = gui_spinner(panel,0,(gui_int)config->rounding[i], 20, 1, NULL);
config->rounding[i] = (float)t; config->rounding[i] = (float)t;
} }
} }
static void static void
color_tab(struct gui_panel_layout *panel, struct state *control, struct gui_config *config) color_tab(struct gui_context *panel, struct state *control, struct gui_style *config)
{ {
gui_size i = 0; gui_size i = 0;
gui_panel_row_dynamic(panel, 30, 2); gui_layout_row_dynamic(panel, 30, 2);
for (i = 0; i < GUI_COLOR_COUNT; ++i) { for (i = 0; i < GUI_COLOR_COUNT; ++i) {
struct gui_color c = config->colors[i]; struct gui_color c = config->colors[i];
gui_panel_label(panel, colors[i], GUI_TEXT_LEFT); gui_label(panel, colors[i], GUI_TEXT_LEFT);
if (gui_panel_button_color(panel, c, GUI_BUTTON_DEFAULT)) { if (gui_button_color(panel, c, GUI_BUTTON_DEFAULT)) {
control->picker.active = gui_true; control->picker.active = gui_true;
control->picker.color = config->colors[i]; control->picker.color = config->colors[i];
control->picker.index = i; control->picker.index = i;
@ -692,21 +691,21 @@ paste(gui_handle handle, struct gui_edit_box *box)
static void static void
init_demo(struct demo_gui *gui, struct gui_font *font) init_demo(struct demo_gui *gui, struct gui_font *font)
{ {
struct gui_config *config = &gui->config; struct gui_style *config = &gui->config;
struct state *win = &gui->state; struct state *win = &gui->state;
struct gui_clipboard clip; struct gui_clipboard clip;
gui->font = *font; gui->font = *font;
gui->running = gui_true; gui->running = gui_true;
gui_command_queue_init_fixed(&gui->queue, gui->memory, MAX_MEMORY); gui_command_queue_init_fixed(&gui->queue, gui->memory, MAX_MEMORY);
gui_config_default(config, GUI_DEFAULT_ALL, font); gui_style_default(config, GUI_DEFAULT_ALL, font);
/* panel */ /* panel */
gui_panel_init(&gui->panel, 30, 30, 280, 530, gui_window_init(&gui->panel, 30, 30, 280, 530,
GUI_PANEL_BORDER|GUI_PANEL_MOVEABLE|GUI_PANEL_SCALEABLE, GUI_WINDOW_BORDER|GUI_WINDOW_MOVEABLE|GUI_WINDOW_SCALEABLE,
&gui->queue, config, gui->input); &gui->queue, config, gui->input);
gui_panel_init(&gui->sub, 400, 50, 220, 180, gui_window_init(&gui->sub, 400, 50, 220, 180,
GUI_PANEL_BORDER|GUI_PANEL_MOVEABLE|GUI_PANEL_SCALEABLE, GUI_WINDOW_BORDER|GUI_WINDOW_MOVEABLE|GUI_WINDOW_SCALEABLE,
&gui->queue, config, gui->input); &gui->queue, config, gui->input);
/* widget state */ /* widget state */
@ -733,27 +732,27 @@ init_demo(struct demo_gui *gui, struct gui_font *font)
static void static void
run_demo(struct demo_gui *gui) run_demo(struct demo_gui *gui)
{ {
struct gui_panel_layout layout; struct gui_context layout;
struct state *state = &gui->state; struct state *state = &gui->state;
struct gui_panel_layout tab; struct gui_context tab;
struct gui_config *config = &gui->config; struct gui_style *config = &gui->config;
/* first panel */ /* first window */
gui_panel_begin(&layout, &gui->panel); gui_begin(&layout, &gui->panel);
{ {
/* header */ /* header */
gui->running = !gui_panel_header(&layout, "Demo", gui->running = !gui_header(&layout, "Demo",
GUI_CLOSEABLE|GUI_MINIMIZABLE, GUI_CLOSEABLE, GUI_HEADER_RIGHT); GUI_CLOSEABLE|GUI_MINIMIZABLE, GUI_CLOSEABLE, GUI_HEADER_RIGHT);
/* menubar */ /* menubar */
gui_panel_menubar_begin(&layout); gui_menubar_begin(&layout);
{ {
gui_panel_row_begin(&layout, GUI_STATIC, 25, 2); gui_layout_row_begin(&layout, GUI_STATIC, 25, 2);
{ {
gui_int sel; gui_int sel;
gui_panel_row_push(&layout, config->font.width(config->font.userdata, "__FILE__", 8)); gui_layout_row_push(&layout, config->font.width(config->font.userdata, "__FILE__", 8));
sel = gui_panel_menu(&layout, "FILE", file_items, LEN(file_items), 25, 100, sel = gui_menu(&layout, "FILE", file_items, LEN(file_items), 25, 100,
&state->file_open, gui_vec2(0,0)); &state->file_open);
switch (sel) { switch (sel) {
case MENU_FILE_OPEN: case MENU_FILE_OPEN:
fprintf(stdout, "[Menu:File] open clicked!\n"); break; fprintf(stdout, "[Menu:File] open clicked!\n"); break;
@ -765,9 +764,9 @@ run_demo(struct demo_gui *gui)
default: break; default: break;
} }
gui_panel_row_push(&layout, config->font.width(config->font.userdata, "__EDIT__", 8)); gui_layout_row_push(&layout, config->font.width(config->font.userdata, "__EDIT__", 8));
sel = gui_panel_menu(&layout, "EDIT", edit_items, LEN(edit_items), 25, 100, sel = gui_menu(&layout, "EDIT", edit_items, LEN(edit_items), 25, 100,
&state->edit_open, gui_vec2(0,0)); &state->edit_open);
switch (sel) { switch (sel) {
case MENU_EDIT_COPY: case MENU_EDIT_COPY:
fprintf(stdout, "[Menu:Edit] copy clicked!\n"); break; fprintf(stdout, "[Menu:Edit] copy clicked!\n"); break;
@ -781,113 +780,113 @@ run_demo(struct demo_gui *gui)
default: break; default: break;
} }
} }
gui_panel_row_end(&layout); gui_layout_row_end(&layout);
} }
gui_panel_menubar_end(&layout); gui_menubar_end(&layout);
/* panel style configuration */ /* panel style configuration */
if (gui_panel_layout_push(&layout, GUI_LAYOUT_TAB, "Style", &state->config_tab)) if (gui_layout_push(&layout, GUI_LAYOUT_TAB, "Style", &state->config_tab))
{ {
if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Options", &state->flag_tab)) { if (gui_layout_push(&layout, GUI_LAYOUT_NODE, "Options", &state->flag_tab)) {
update_flags(&layout); update_flags(&layout);
gui_panel_layout_pop(&layout); gui_layout_pop(&layout);
} }
if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Properties", &state->style_tab)) { if (gui_layout_push(&layout, GUI_LAYOUT_NODE, "Properties", &state->style_tab)) {
properties_tab(&layout, config); properties_tab(&layout, config);
gui_panel_layout_pop(&layout); gui_layout_pop(&layout);
} }
if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Rounding", &state->round_tab)) { if (gui_layout_push(&layout, GUI_LAYOUT_NODE, "Rounding", &state->round_tab)) {
round_tab(&layout, config); round_tab(&layout, config);
gui_panel_layout_pop(&layout); gui_layout_pop(&layout);
} }
if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Color", &state->color_tab)) { if (gui_layout_push(&layout, GUI_LAYOUT_NODE, "Color", &state->color_tab)) {
color_tab(&layout, state, config); color_tab(&layout, state, config);
gui_panel_layout_pop(&layout); gui_layout_pop(&layout);
} }
gui_panel_layout_pop(&layout); gui_layout_pop(&layout);
} }
/* widgets examples */ /* widgets examples */
if (gui_panel_layout_push(&layout, GUI_LAYOUT_TAB, "Widgets", &state->widget_tab)) { if (gui_layout_push(&layout, GUI_LAYOUT_TAB, "Widgets", &state->widget_tab)) {
widget_panel(&layout, state); widget_panel(&layout, state);
gui_panel_layout_pop(&layout); gui_layout_pop(&layout);
} }
/* popup panel */ /* popup panel */
if (state->popup) { if (state->popup) {
gui_panel_popup_begin(&layout, &tab, GUI_POPUP_STATIC, gui_rect(20, 100, 220, 150), gui_vec2(0,0)); gui_popup_begin(&layout, &tab, GUI_POPUP_STATIC, gui_rect(20, 100, 220, 150), gui_vec2(0,0));
{ {
if (gui_panel_header(&tab, "Popup", GUI_CLOSEABLE, GUI_CLOSEABLE, GUI_HEADER_LEFT)) { if (gui_header(&tab, "Popup", GUI_CLOSEABLE, GUI_CLOSEABLE, GUI_HEADER_LEFT)) {
gui_panel_popup_close(&tab); gui_popup_close(&tab);
state->popup = gui_false; state->popup = gui_false;
} }
gui_panel_row_dynamic(&tab, 30, 1); gui_layout_row_dynamic(&tab, 30, 1);
gui_panel_label(&tab, "Are you sure you want to exit?", GUI_TEXT_LEFT); gui_label(&tab, "Are you sure you want to exit?", GUI_TEXT_LEFT);
gui_panel_row_dynamic(&tab, 30, 4); gui_layout_row_dynamic(&tab, 30, 4);
gui_panel_spacing(&tab, 1); gui_spacing(&tab, 1);
if (gui_panel_button_text(&tab, "Yes", GUI_BUTTON_DEFAULT)) { if (gui_button_text(&tab, "Yes", GUI_BUTTON_DEFAULT)) {
gui_panel_popup_close(&tab); gui_popup_close(&tab);
state->popup = gui_false; state->popup = gui_false;
} }
if (gui_panel_button_text(&tab, "No", GUI_BUTTON_DEFAULT)) { if (gui_button_text(&tab, "No", GUI_BUTTON_DEFAULT)) {
gui_panel_popup_close(&tab); gui_popup_close(&tab);
state->popup = gui_false; state->popup = gui_false;
} }
} }
gui_panel_popup_end(&layout, &tab); gui_popup_end(&layout, &tab);
} }
{ {
/* shelf + graphes */ /* shelf + graphes */
static const char *shelfs[] = {"Histogram", "Lines"}; static const char *shelfs[] = {"Histogram", "Lines"};
gui_panel_row_dynamic(&layout, 180, 1); gui_layout_row_dynamic(&layout, 180, 1);
state->shelf_selection = gui_panel_shelf_begin(&layout, &tab, shelfs, state->shelf_selection = gui_shelf_begin(&layout, &tab, shelfs,
LEN(shelfs), state->shelf_selection, state->shelf); LEN(shelfs), state->shelf_selection, state->shelf);
{ {
enum {COLUMNS, LINES}; enum {COLUMNS, LINES};
static const gui_float values[]={8.0f,15.0f,20.0f,12.0f,30.0f,12.0f,35.0f,40.0f,20.0f}; static const gui_float values[]={8.0f,15.0f,20.0f,12.0f,30.0f,12.0f,35.0f,40.0f,20.0f};
gui_panel_row_dynamic(&tab, 100, 1); gui_layout_row_dynamic(&tab, 100, 1);
switch (state->shelf_selection) { switch (state->shelf_selection) {
case COLUMNS: case COLUMNS:
gui_panel_graph(&tab, GUI_GRAPH_COLUMN, values, LEN(values), 0); break; gui_graph(&tab, GUI_GRAPH_COLUMN, values, LEN(values), 0); break;
case LINES: case LINES:
gui_panel_graph(&tab, GUI_GRAPH_LINES, values, LEN(values), 0); break; gui_graph(&tab, GUI_GRAPH_LINES, values, LEN(values), 0); break;
default: break; default: break;
} }
} }
state->shelf = gui_panel_shelf_end(&layout, &tab); state->shelf = gui_shelf_end(&layout, &tab);
} }
/* table */ /* table */
gui_panel_row_dynamic(&layout, 180, 1); gui_layout_row_dynamic(&layout, 180, 1);
gui_panel_group_begin(&layout, &tab, "Table", state->table); gui_child_begin(&layout, &tab, "Table", state->table);
table_panel(&tab); table_panel(&tab);
state->table = gui_panel_group_end(&layout, &tab); state->table = gui_child_end(&layout, &tab);
{ {
/* tree */ /* tree */
struct gui_tree tree; struct gui_tree tree;
gui_panel_row_dynamic(&layout, 250, 1); gui_layout_row_dynamic(&layout, 250, 1);
gui_panel_tree_begin(&layout, &tree, "Tree", 20, state->tree); gui_tree_begin(&layout, &tree, "Tree", 20, state->tree);
upload_tree(&state->test, &tree, &state->test.root); upload_tree(&state->test, &tree, &state->test.root);
state->tree = gui_panel_tree_end(&layout, &tree); state->tree = gui_tree_end(&layout, &tree);
} }
} }
gui_panel_end(&layout, &gui->panel); gui_end(&layout, &gui->panel);
/* second panel */ /* second panel */
gui_panel_begin(&layout, &gui->sub); gui_begin(&layout, &gui->sub);
{ {
enum {EASY, HARD}; enum {EASY, HARD};
gui_panel_header(&layout, "Show", GUI_CLOSEABLE, 0, GUI_HEADER_LEFT); gui_header(&layout, "Show", GUI_CLOSEABLE, 0, GUI_HEADER_LEFT);
gui_panel_row_static(&layout, 30, 80, 1); gui_layout_row_static(&layout, 30, 80, 1);
if (gui_panel_button_text(&layout, "button", GUI_BUTTON_DEFAULT)) { if (gui_button_text(&layout, "button", GUI_BUTTON_DEFAULT)) {
/* event handling */ /* event handling */
} }
gui_panel_row_dynamic(&layout, 30, 2); gui_layout_row_dynamic(&layout, 30, 2);
if (gui_panel_option(&layout, "easy", state->op == EASY)) state->op = EASY; if (gui_option(&layout, "easy", state->op == EASY)) state->op = EASY;
if (gui_panel_option(&layout, "hard", state->op == HARD)) state->op = HARD; if (gui_option(&layout, "hard", state->op == HARD)) state->op = HARD;
} }
gui_panel_end(&layout, &gui->sub); gui_end(&layout, &gui->sub);
} }

2403
gui.c

File diff suppressed because it is too large Load Diff

1379
gui.h

File diff suppressed because it is too large Load Diff