static void update_show(struct show_window *show, struct gui_stack *stack, struct gui_input *in, unsigned int ms) { struct gui_panel_layout tab; struct gui_panel_layout layout; static const char *shelfs[] = {"Histogram", "Lines"}; gui_panel_begin_stacked(&layout, &show->hook, stack, "Show", in); show->combobox_tab = gui_panel_tab_begin(&layout, &tab, "Combobox", show->combobox_tab); combobox_panel(&tab, show); gui_panel_tab_end(&layout, &tab); show->widget_tab = gui_panel_tab_begin(&layout, &tab, "Widgets", show->widget_tab); widget_panel(&tab, show); gui_panel_tab_end(&layout, &tab); gui_panel_row(&layout, 110, 1); gui_panel_group_begin(&layout, &tab, "Time", show->time_scrollbar); time_panel(&tab, ms); show->time_scrollbar = gui_panel_group_end(&layout, &tab); gui_panel_row(&layout, 180, 1); show->shelf_selection = gui_panel_shelf_begin(&layout, &tab, shelfs, LEN(shelfs), show->shelf_selection, show->shelf_scrollbar); graph_panel(&tab, show->shelf_selection); show->shelf_scrollbar = gui_panel_shelf_end(&layout, &tab); gui_panel_row(&layout, 180, 1); gui_panel_group_begin(&layout, &tab, "Table", show->table_scrollbar); table_panel(&tab); show->table_scrollbar = gui_panel_group_end(&layout, &tab); gui_panel_end(&layout, &show->hook); }
static struct gui_color color_picker(struct gui_panel_layout *panel, struct control_window *control, const char *name, struct gui_color color) { int i; gui_byte *iter; gui_bool *active[4]; active[0] = &control->spinner_r_active; active[1] = &control->spinner_g_active; active[2] = &control->spinner_b_active; active[3] = &control->spinner_a_active; gui_panel_row(panel, 30, 2); gui_panel_label(panel, name, GUI_TEXT_LEFT); gui_panel_button_color(panel, color, GUI_BUTTON_DEFAULT); iter = &color.r; gui_panel_row(panel, 30, 2); for (i = 0; i < 4; ++i, iter++) { gui_float t = *iter; t = gui_panel_slider(panel, 0, t, 255, 10); *iter = (gui_byte)t; *iter = (gui_byte)gui_panel_spinner(panel, 0, *iter, 255, 1, active[i]); } return color; }
static void widget_panel(struct gui_panel_layout *panel, struct show_window *demo) { const char *items[] = {"Fist", "Pistol", "Shotgun", "Railgun", "BFG"}; gui_panel_row(panel, 30, 1); gui_panel_label(panel, "text left", GUI_TEXT_LEFT); gui_panel_label(panel, "text center", GUI_TEXT_CENTERED); gui_panel_label(panel, "text right", GUI_TEXT_RIGHT); if (gui_panel_button_text(panel, "button", GUI_BUTTON_DEFAULT)) fprintf(stdout, "button pressed!\n"); if (gui_panel_button_text_triangle(panel, GUI_RIGHT, "next", GUI_TEXT_LEFT, GUI_BUTTON_DEFAULT)) fprintf(stdout, "right triangle button pressed!\n"); if (gui_panel_button_text_triangle(panel,GUI_LEFT,"previous",GUI_TEXT_RIGHT,GUI_BUTTON_DEFAULT)) fprintf(stdout, "left triangle button pressed!\n"); demo->toggle = gui_panel_button_toggle(panel, "toggle", demo->toggle); demo->checkbox = gui_panel_check(panel, "checkbox", demo->checkbox); gui_panel_row(panel, 30, 2); if (gui_panel_option(panel, "option 0", demo->option == 0)) demo->option = 0; if (gui_panel_option(panel, "option 1", demo->option == 1)) demo->option = 1; { char buffer[MAX_BUFFER]; const gui_float ratio[] = {0.8f, 0.2f}; gui_panel_row_templated(panel, 30, 2, ratio); demo->slider = gui_panel_slider(panel, 0, demo->slider, 10, 1.0f); sprintf(buffer, "%.2f", demo->slider); gui_panel_label(panel, buffer, GUI_TEXT_LEFT); demo->progressbar = gui_panel_progress(panel, demo->progressbar, 100, gui_true); sprintf(buffer, "%lu", demo->progressbar); gui_panel_label(panel, buffer, GUI_TEXT_LEFT); } gui_panel_row(panel, 30, 1); demo->item_current = gui_panel_selector(panel, items, LEN(items), demo->item_current); demo->spinner = gui_panel_spinner(panel, 0, demo->spinner, 250, 10, &demo->spinner_active); { const gui_float ratio[] = {0.7f, 0.3f}; gui_panel_row_templated(panel, 30, 2, ratio); demo->input_length = gui_panel_edit(panel, demo->input_buffer, demo->input_length, MAX_BUFFER, &demo->input_active, GUI_INPUT_DEFAULT); if (gui_panel_button_text(panel, "submit", GUI_BUTTON_DEFAULT)) { demo->input_length = 0; fprintf(stdout, "command executed!\n"); } } }
static void color_combo_box(struct gui_panel_layout *panel, struct color_combo_box *demo) { /* color slider progressbar */ gui_char buffer[32]; struct gui_panel_layout combo; memset(&combo, 0, sizeof(combo)); sprintf(buffer, "#%02x%02x%02x%02x", demo->color.r, demo->color.g, demo->color.b, demo->color.a); gui_panel_combo_begin(panel, &combo, buffer, &demo->active, demo->scrollbar); { int i; const char *color_names[] = {"R:", "G:", "B:", "A:"}; gui_float ratios[] = {0.15f, 0.85f}; gui_byte *iter = &demo->color.r; gui_panel_row(&combo, GUI_DYNAMIC, 30, 2, ratios); for (i = 0; i < 4; ++i, iter++) { gui_float t = *iter; gui_panel_label(&combo, color_names[i], GUI_TEXT_LEFT); t = gui_panel_slider(&combo, 0, t, 255, 5); *iter = (gui_byte)t; } } demo->scrollbar = gui_panel_combo_end(panel, &combo); }
static void color_tab(struct gui_panel_layout *panel, struct control_window *control, struct gui_config *config) { gui_size i = 0; static const char *labels[] = {"Text:", "Panel:", "Header:", "Border:", "Button:", "Button Border:", "Button Hovering:", "Button Toggle:", "Button Hovering Text:", "Check:", "Check BG:", "Check Active:", "Option:", "Option BG:", "Option Active:", "Slider:", "Slider bar:", "Slider boder:","Slider cursor:", "Progress:", "Progress Cursor:", "Editbox:", "Editbox cursor:", "Editbox Border:", "Editbox Text:", "Spinner:", "Spinner Border:", "Spinner Triangle:", "Spinner Text:", "Selector:", "Selector Border:", "Selector Triangle:", "Selector Text:", "Histo:", "Histo Bars:", "Histo Negative:", "Histo Hovering:", "Plot:", "Plot Lines:", "Plot Hightlight:", "Scrollbar:", "Scrollbar Cursor:", "Scrollbar Border:", "Table lines:", "Shelf:", "Shelf Text:", "Shelf Active:", "Shelf Active Text:", "Scaler:", "Tiled Scaler" }; if (control->picker_active) { control->color = color_picker(panel,control,labels[control->current_color], control->color); gui_panel_row(panel, 30, 3); gui_panel_spacing(panel, 1); if (gui_panel_button_text(panel, "ok", GUI_BUTTON_DEFAULT)) { config->colors[control->current_color] = control->color; control->picker_active = gui_false; } if (gui_panel_button_text(panel, "cancel", GUI_BUTTON_DEFAULT)) control->picker_active = gui_false; } else { gui_panel_row(panel, 30, 2); for (i = 0; i < GUI_COLOR_COUNT; ++i) { struct gui_color c = config->colors[i]; gui_panel_label(panel, labels[i], GUI_TEXT_LEFT); if (gui_panel_button_color(panel, c, GUI_BUTTON_DEFAULT)) { if (!control->picker_active) { control->picker_active = gui_true; control->color = config->colors[i]; control->current_color = i; } else continue; } } } }
static void combobox_panel(struct gui_panel_layout *panel, struct show_window *demo) { gui_int i = 0; static const char *options[] = {"easy", "normal", "hard", "hell", "doom", "godlike"}; gui_panel_row(panel, 30, 3); for (i = 0; i < (gui_int)LEN(options); i++) { if (gui_panel_option(panel, options[i], demo->combo_selection == i)) demo->combo_selection = i; } }
static void graph_panel(struct gui_panel_layout *panel, gui_size current) { enum {COL, PLOT}; 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(panel, 100, 1); if (current == COL) { gui_panel_graph(panel, GUI_GRAPH_COLUMN, values, LEN(values), 0); } else { gui_panel_graph(panel, GUI_GRAPH_LINES, values, LEN(values), 0); } }
static void time_panel(struct gui_panel_layout *panel, unsigned int ms) { char buffer[MAX_BUFFER]; ms = MAX(1, ms); gui_panel_row(panel, 20, 2); gui_panel_label(panel, "FPS:", GUI_TEXT_LEFT); sprintf(buffer, "%.2f", 1.0f/((float)ms/1000.0f)); gui_panel_label(panel, buffer, GUI_TEXT_CENTERED); gui_panel_label(panel, "MS:", GUI_TEXT_LEFT); sprintf(buffer, "%d", ms); gui_panel_label(panel, buffer, GUI_TEXT_CENTERED); }
static void round_tab(struct gui_panel_layout *panel, struct gui_config *config) { int i = 0; const char *rounding[] = {"panel:", "button:", "checkbox:", "progress:", "input: ", "graph:", "scrollbar:"}; gui_panel_row(panel, 30, 2); for (i = 0; i < GUI_ROUNDING_MAX; ++i) { gui_int t; gui_panel_label(panel, rounding[i], GUI_TEXT_LEFT); t = gui_panel_spinner(panel,0,(gui_int)config->rounding[i], 20, 1, NULL); config->rounding[i] = (float)t; } }
static void update_flags(struct gui_panel_layout *panel, struct control_window *control) { gui_size n = 0; gui_flags res = 0; gui_flags i = 0x01; const char *options[]={"Hidden","Border","Minimizable","Closeable","Moveable","Scaleable"}; gui_panel_row(panel, 30, 2); do { if (gui_panel_check(panel,options[n++],(control->show_flags & i)?gui_true:gui_false)) res |= i; i = i << 1; } while (i <= GUI_PANEL_SCALEABLE); control->show_flags = res; }
static void properties_tab(struct gui_panel_layout *panel, struct gui_config *config) { int i = 0; const char *properties[] = {"item spacing:", "item padding:", "panel padding:", "scaler size:", "scrollbar:"}; gui_panel_row(panel, 30, 3); for (i = 0; i <= GUI_PROPERTY_SCROLLBAR_WIDTH; ++i) { gui_int tx, ty; gui_panel_label(panel, properties[i], GUI_TEXT_LEFT); tx = gui_panel_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); config->properties[i].x = (float)tx; config->properties[i].y = (float)ty; } }
/* ----------------------------------------------------------------- * WIDGETS * ----------------------------------------------------------------- */ static void widget_panel(struct gui_panel_layout *panel, struct state *demo) { /* Labels */ gui_panel_row_dynamic(panel, 30, 1); demo->scaleable = gui_panel_check(panel, "Scaleable Layout", demo->scaleable); if (!demo->scaleable) gui_panel_row_static(panel, 30, 150, 1); gui_panel_label(panel, "text left", GUI_TEXT_LEFT); gui_panel_label(panel, "text center", GUI_TEXT_CENTERED); gui_panel_label(panel, "text right", GUI_TEXT_RIGHT); /* Buttons */ if (gui_panel_button_text(panel, "button", GUI_BUTTON_DEFAULT)) demo->popup = gui_true; if (gui_panel_button_text_triangle(panel, GUI_RIGHT, "next", GUI_TEXT_LEFT, GUI_BUTTON_DEFAULT)) fprintf(stdout, "right triangle button pressed!\n"); if (gui_panel_button_text_triangle(panel,GUI_LEFT,"previous",GUI_TEXT_RIGHT,GUI_BUTTON_DEFAULT)) fprintf(stdout, "left triangle button pressed!\n"); demo->toggle = gui_panel_button_toggle(panel, "toggle", demo->toggle); /* checkbox + radio buttons */ demo->checkbox = gui_panel_check(panel, "checkbox", demo->checkbox); if (!demo->scaleable) gui_panel_row_static(panel, 30, 75, 2); else gui_panel_row_dynamic(panel, 30, 2); if (gui_panel_option(panel, "option 0", demo->option == 0)) demo->option = 0; if (gui_panel_option(panel, "option 1", demo->option == 1)) demo->option = 1; { /* retain mode custom row layout */ const gui_float ratio[] = {0.8f, 0.2f}; const gui_float pixel[] = {150.0f, 30.0f}; enum gui_panel_row_layout_format fmt = (demo->scaleable) ? GUI_DYNAMIC : GUI_STATIC; gui_panel_row(panel, fmt, 30, 2, (fmt == GUI_DYNAMIC) ? ratio: pixel); demo->slider = gui_panel_slider(panel, 0, demo->slider, 10, 1.0f); gui_panel_labelf(panel, GUI_TEXT_LEFT, "%.2f", demo->slider); demo->progressbar = gui_panel_progress(panel, demo->progressbar, 100, gui_true); gui_panel_labelf(panel, GUI_TEXT_LEFT, "%lu", demo->progressbar); } /* item selection */ if (!demo->scaleable) gui_panel_row_static(panel, 30, 150, 1); else gui_panel_row_dynamic(panel, 30, 1); demo->item_current = gui_panel_selector(panel, weapons, LEN(weapons), demo->item_current); combo_box(panel, &demo->combo, weapons, LEN(weapons)); prog_combo_box(panel, demo->prog_values, LEN(demo->prog_values), &demo->progcom); color_combo_box(panel, &demo->colcom); check_combo_box(panel, demo->check_values, LEN(demo->check_values), &demo->checkcom); demo->spinner = gui_panel_spinner_int(panel, 0, demo->spinner, 250, 10, &demo->spinner_active); { /* immediate mode custom row layout */ enum gui_panel_row_layout_format fmt = (demo->scaleable) ? GUI_DYNAMIC : GUI_STATIC; gui_panel_row_begin(panel, fmt, 30, 2); { gui_panel_row_push(panel,(fmt == GUI_DYNAMIC) ? 0.7f : 100); gui_panel_editbox(panel, &demo->edit); gui_panel_row_push(panel, (fmt == GUI_DYNAMIC) ? 0.3f : 80); if (gui_panel_button_text(panel, "submit", GUI_BUTTON_DEFAULT)) { gui_edit_box_clear(&demo->edit); fprintf(stdout, "command executed!\n"); } } gui_panel_row_end(panel); } }