major update for changes look in the update issue #9

This commit is contained in:
vurtun 2015-08-02 13:49:51 +02:00
parent 4299c3e3b0
commit ccb271e7d9
10 changed files with 600 additions and 195 deletions

View File

@ -32,7 +32,7 @@ Summary: It is only responsible for the actual user interface
## Gallery
![gui demo](/screen/demo.png?raw=true)
![gui config](/screen/config.png?raw=true)
![gui explorer](/screen/explorer.png?raw=true)
![gui screenshot](/screen/screenshot.png?raw=true)
## Example
@ -63,6 +63,7 @@ gui_size len = 0;
gui_char buffer[256];
gui_bool active = gui_false;
gui_size option = 0;
gui_size cursor = 0;
struct gui_input input = {0};
while (1) {
@ -73,16 +74,16 @@ while (1) {
/* GUI */
struct gui_panel_layout layout;
gui_panel_begin(&layout, &panel, &input);
gui_panel_header(&layout, "Show", GUI_CLOSEABLE, 0);
gui_panel_row(&layout, 30, 1);
gui_panel_header(&layout, "Demo", GUI_CLOSEABLE, 0, GUI_HEADER_RIGHT);
gui_panel_layout_flux_fixed(&layout, 30, 1);
if (gui_panel_button_text(&layout, "button", GUI_BUTTON_DEFAULT)) {
/* event handling */
}
gui_panel_row(&layout, 30, 2);
gui_panel_layout_flux_fixed(&layout, 30, 2);
if (gui_panel_option(&layout, "easy", option == 0)) option = 0;
if (gui_panel_option(&layout, "hard", option == 1)) option = 1;
gui_panel_label(&layout, "input:", GUI_TEXT_LEFT);
len = gui_panel_edit(&layout, buffer, len, 256, &active, GUI_INPUT_DEFAULT);
len = gui_panel_edit(&layout, buffer, len, 256, &active, &cursor, GUI_INPUT_DEFAULT);
gui_panel_end(&layout, &panel);
/* draw */
@ -301,8 +302,8 @@ while (1) {
struct gui_panel_layout layout;
gui_panel_begin_stacked(&layout, &panel, &stack, &input);
gui_panel_header(&layout, "Demo", GUI_CLOSEABLE|GUI_MINIMIZABLE, 0);
gui_panel_row(&layout, 30, 1);
gui_panel_header(&layout, "Demo", GUI_CLOSEABLE, 0, GUI_HEADER_RIGHT);
gui_panel_layout_flux_fixed(&layout, 30, 1);
if (gui_panel_button_text(&layout, "button", GUI_BUTTON_DEFAULT))
fprintf(stdout, "button pressed!\n");
gui_panel_end(&layout, &panel);
@ -353,7 +354,7 @@ while (1) {
/* GUI */
struct gui_panel_layout layout;
gui_panel_begin_tiled(&layout, &panel, &tiled, GUI_SLOT_LEFT, 0, "Demo", &input);
gui_panel_row(&layout, 30, 1);
gui_panel_layout_flux_fixed(&layout, 30, 1);
if (gui_panel_button_text(&layout, "button", GUI_BUTTON_DEFAULT))
fprintf(stdout, "button pressed!\n");
gui_panel_end(&layout, &panel);

View File

@ -1,5 +1,5 @@
#define MAX_BUFFER 64
#define MAX_MEMORY (32 * 1024)
#define MAX_MEMORY (16 * 1024)
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
@ -41,7 +41,6 @@ struct state {
/* tree */
struct test_tree tree;
struct tree_node nodes[8];
gui_float tree_offset;
/* tabs */
enum gui_node_state config_tab;
@ -52,9 +51,9 @@ struct state {
enum gui_node_state flag_tab;
/* scrollbars */
gui_float shelf_scrollbar;
gui_float table_scrollbar;
gui_float tree_scrollbar;
struct gui_vec2 shelf_scrollbar;
struct gui_vec2 table_scrollbar;
struct gui_vec2 tree_scrollbar;
/* color picker */
gui_bool picker_active;
@ -221,7 +220,7 @@ widget_panel(struct gui_panel_layout *panel, struct state *demo)
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);
demo->in_len = gui_panel_edit(panel, demo->in_buf, demo->in_len, MAX_BUFFER,
&demo->in_active, GUI_INPUT_DEFAULT);
&demo->in_active, NULL, GUI_INPUT_DEFAULT);
if (demo->scaleable) {
gui_panel_layout_flux_row_begin(panel, 30, 2);
@ -412,7 +411,7 @@ properties_tab(struct gui_panel_layout *panel, struct gui_config *config)
"scaler size:", "scrollbar:"};
gui_panel_layout_flux_fixed(panel, 30, 3);
for (i = 0; i <= GUI_PROPERTY_SCROLLBAR_WIDTH; ++i) {
for (i = 0; i <= GUI_PROPERTY_SCROLLBAR_SIZE; ++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);
@ -510,20 +509,48 @@ color_tab(struct gui_panel_layout *panel, struct state *control, struct gui_conf
}
}
static void
copy(gui_handle handle, const char *text, gui_size size)
{
gui_char buffer[1024];
UNUSED(handle);
if (size >= 1023) return;
memcpy(buffer, text, size);
buffer[size] = '\0';
clipboard_set(buffer);
}
static void
paste(gui_handle handle, struct gui_edit_box *box)
{
gui_size len;
const char *text;
UNUSED(handle);
if (!clipboard_is_filled()) return;
text = clipboard_get();
len = strlen(text);
gui_edit_box_add(box, text, len);
}
static void
init_demo(struct demo_gui *gui, struct gui_font *font)
{
struct gui_config *config = &gui->config;
struct state *win = &gui->state;
struct gui_clipboard clip;
gui->font = *font;
gui->running = gui_true;
clip.userdata.ptr = NULL,
clip.copy = copy;
clip.paste = paste;
gui_command_buffer_init_fixed(&gui->buffer, gui->memory, MAX_MEMORY, GUI_CLIP);
gui_config_default(config, GUI_DEFAULT_ALL, font);
gui_panel_init(&gui->panel, 30, 30, 280, 530,
GUI_PANEL_BORDER|GUI_PANEL_MOVEABLE|GUI_PANEL_SCALEABLE, &gui->buffer, config);
gui_edit_box_init_fixed(&win->input, win->input_buffer, MAX_BUFFER, NULL, NULL);
gui_edit_box_init_fixed(&win->input, win->input_buffer, MAX_BUFFER, &clip, NULL);
win->config_tab = GUI_MINIMIZED;
win->widget_tab = GUI_MINIMIZED;
win->style_tab = GUI_MINIMIZED;
@ -642,9 +669,9 @@ run_demo(struct demo_gui *gui, struct gui_input *input)
/* Tree */
struct gui_tree tree;
gui_panel_layout_flux_fixed(&layout, 250, 1);
gui_panel_tree_begin(&layout, &tree, "Tree", 20, state->tree_offset);
gui_panel_tree_begin(&layout, &tree, "Tree", 20, state->tree_scrollbar);
upload_tree(&state->tree, &tree, &state->tree.root);
state->tree_offset = gui_panel_tree_end(&layout, &tree);
state->tree_scrollbar = gui_panel_tree_end(&layout, &tree);
}
}
gui_panel_end(&layout, &gui->panel);

View File

@ -33,6 +33,19 @@
#define UNUSED(a) ((void)(a))
#include "../gui.h"
static void
clipboard_set(const char *text)
{SDL_SetClipboardText(text);}
static gui_bool
clipboard_is_filled(void)
{return SDL_HasClipboardText();}
static const char*
clipboard_get(void)
{return SDL_GetClipboardText();}
#include "demo.c"
static void
@ -155,7 +168,8 @@ draw(NVGcontext *nvg, struct gui_command_buffer *list, int width, int height)
} break;
case GUI_COMMAND_TRIANGLE: {
const struct gui_command_triangle *t = gui_command(triangle, cmd);
draw_triangle(nvg, t->a[0], t->a[1], t->b[0], t->b[1], t->c[0], t->c[1], t->color);
draw_triangle(nvg, t->a[0], t->a[1], t->b[0], t->b[1], t->c[0],
t->c[1], t->color);
} break;
case GUI_COMMAND_TEXT: {
const struct gui_command_text *t = gui_command(text, cmd);

View File

@ -33,6 +33,19 @@
#define UNUSED(a) ((void)(a))
#include "../gui.h"
static void
clipboard_set(const char *text)
{SDL_SetClipboardText(text);}
static gui_bool
clipboard_is_filled(void)
{return SDL_HasClipboardText();}
static const char*
clipboard_get(void)
{return SDL_GetClipboardText();}
#include "demo.c"
struct texCoord {

View File

@ -23,6 +23,11 @@
#define UNUSED(a) ((void)(a))
#include "../gui.h"
static void clipboard_set(const char *text){UNUSED(text);}
static gui_bool clipboard_is_filled(void){return gui_false;}
static const char* clipboard_get(void) {return NULL;}
#include "demo.c"
typedef struct XFont XFont;

596
gui.c

File diff suppressed because it is too large Load Diff

83
gui.h
View File

@ -40,8 +40,8 @@ Since the gui uses ANSI C which does not guarantee to have fixed types, you need
to set the appropriate size of each type. However if your developer environment
supports fixed size types by the <stdint> header you can just uncomment the define
to automatically set the correct size for each type in the library:
#define GUI_USE_FIXED_TYPES
*/
#define GUI_USE_FIXED_TYPES
#ifdef GUI_USE_FIXED_TYPES
#include <stdint.h>
typedef char gui_char;
@ -88,9 +88,10 @@ struct gui_image {gui_handle handle; struct gui_rect region;};
/* Callbacks */
struct gui_font;
struct gui_edit_box;
typedef gui_bool(*gui_filter)(gui_long unicode);
typedef gui_size(*gui_text_width_f)(gui_handle, const gui_char*, gui_size);
typedef gui_size(*gui_paste_f)(gui_handle, char *buffer, gui_size max);
typedef void(*gui_paste_f)(gui_handle, struct gui_edit_box*);
typedef void(*gui_copy_f)(gui_handle, const char*, gui_size size);
/*
@ -697,6 +698,12 @@ struct gui_clipboard {
gui_copy_f copy;
};
struct gui_selection {
gui_bool active;
gui_size begin;
gui_size end;
};
typedef struct gui_buffer gui_edit_buffer;
struct gui_edit_box {
gui_edit_buffer buffer;
@ -711,6 +718,8 @@ struct gui_edit_box {
/* copy paste callbacks */
gui_filter filter;
/* input filter callback */
struct gui_selection sel;
/* text selection */
};
/* filter function */
@ -940,7 +949,7 @@ struct gui_slider {
/* slider cursor color */
};
struct gui_scroll {
struct gui_scrollbar {
gui_float rounding;
/* scrollbar rectangle rounding */
struct gui_color highlight;
@ -1205,7 +1214,7 @@ void gui_editbox(struct gui_command_buffer*, gui_float x, gui_float y, gui_float
*/
gui_size gui_edit(struct gui_command_buffer*, gui_float x, gui_float y, gui_float w,
gui_float h, gui_char*, gui_size, gui_size max, gui_bool*,
const struct gui_edit*, enum gui_input_filter filter,
gui_size *cursor, const struct gui_edit*, enum gui_input_filter filter,
const struct gui_input*, const struct gui_font*);
/* this function executes a editbox widget
Input:
@ -1226,9 +1235,9 @@ gui_size gui_edit(struct gui_command_buffer*, gui_float x, gui_float y, gui_floa
*/
gui_size gui_edit_filtered(struct gui_command_buffer*, gui_float x, gui_float y,
gui_float w, gui_float h, gui_char*, gui_size,
gui_size max, gui_bool*, const struct gui_edit*,
gui_filter filter, const struct gui_input*,
const struct gui_font*);
gui_size max, gui_bool*, gui_size *cursor,
const struct gui_edit*, gui_filter filter,
const struct gui_input*, const struct gui_font*);
/* this function executes a editbox widget
Input:
- output command buffer for drawing
@ -1283,10 +1292,29 @@ gui_size gui_selector(struct gui_command_buffer*, gui_float x, gui_float y,
Output:
- returns the from the user input updated spinner value
*/
gui_float gui_scroll(struct gui_command_buffer*, gui_float x, gui_float y,
gui_float gui_scrollbar_vertical(struct gui_command_buffer*, gui_float x, gui_float y,
gui_float w, gui_float h, gui_float offset, gui_float target,
gui_float step, const struct gui_scroll*, const struct gui_input*);
/* this function executes a scrollbar widget
gui_float step, const struct gui_scrollbar*,
const struct gui_input*);
/* this function executes a vertical scrollbar widget
Input:
- output command buffer for draw commands
- (x,y) position
- (width, height) size
- scrollbar offset in source pixel
- destination pixel size
- step pixel size if the scrollbar up- or down button is pressed
- visual widget style structure describing the selector
- input structure to update the slider with
Output:
- returns the from the user input updated scrollbar offset in pixels
*/
gui_float gui_scrollbar_horizontal(struct gui_command_buffer*, gui_float x,
gui_float y, gui_float w, gui_float h,
gui_float offset, gui_float target,
gui_float step, const struct gui_scrollbar*,
const struct gui_input*);
/* this function executes a horizontal scrollbar widget
Input:
- output command buffer for draw commands
- (x,y) position
@ -1407,7 +1435,7 @@ enum gui_config_properties {
GUI_PROPERTY_ITEM_PADDING,
GUI_PROPERTY_PADDING,
GUI_PROPERTY_SCALER_SIZE,
GUI_PROPERTY_SCROLLBAR_WIDTH,
GUI_PROPERTY_SCROLLBAR_SIZE,
GUI_PROPERTY_SIZE,
GUI_PROPERTY_NODE_SPACING,
GUI_PROPERTY_MAX
@ -1623,7 +1651,7 @@ struct gui_panel {
/* size with width and height of the panel */
gui_flags flags;
/* panel flags modifing its behavior */
gui_float offset;
struct gui_vec2 offset;
/* flag indicating if the panel is collapsed */
const struct gui_config *config;
/* configuration reference describing the panel style */
@ -1698,7 +1726,7 @@ struct gui_panel_header {
struct gui_panel_menu {
gui_float x, y, w, h;
/* menu bounds */
gui_float offset;
struct gui_vec2 offset;
/* saved panel scrollbar offset */
};
@ -1707,7 +1735,7 @@ struct gui_panel_layout {
/* panel flags modifing its behavior */
gui_float x, y, w, h;
/* position and size of the panel in the os window */
gui_float offset;
struct gui_vec2 offset;
/* panel scrollbar offset */
gui_bool is_table;
/* flag indicating if the panel is currently creating a table */
@ -1715,7 +1743,7 @@ struct gui_panel_layout {
/* flags describing the line drawing for every row in the table */
gui_bool valid;
/* flag inidicating if the panel is visible */
gui_float at_x, at_y;
gui_float at_x, at_y, max_x;
/* index position of the current widget row and column */
gui_float width, height;
/* size of the actual useable space inside the panel */
@ -2006,9 +2034,9 @@ void gui_panel_menu_end(struct gui_panel_layout*);
The first layout type with a fixed size table layout only needs to be set once
and works over row boundaries this includes `gui_panel_layout_flux_fixed`
as well as `gui_panel_layout_static_fixed`.
The second layout tike with its `gui_panel_layout_flux_row_xxx` and
`gui_panel_layout_static_row_xxx` functions only works for one row and
as to be set for each row. In addition the `gui_panel_layout_xxx_row_push`
The second layout type with functions `gui_panel_layout_flux_row_xxx` and
`gui_panel_layout_static_row_xxx` only works for one row and
has to be set for each row. In addition the `gui_panel_layout_xxx_row_push`
function has to be called for each widget.
The free position API works completly on the allocated space and the
`gui_panel_layout_xxxx_widget` functions need to be called for each widget
@ -2372,7 +2400,8 @@ gui_size gui_panel_progress(struct gui_panel_layout*, gui_size cur, gui_size max
void gui_panel_editbox(struct gui_panel_layout*, struct gui_edit_box*);
/* this function creates an editbox with copy & paste functionality and text buffering */
gui_size gui_panel_edit(struct gui_panel_layout*, gui_char *buffer, gui_size len,
gui_size max, gui_bool *active, enum gui_input_filter);
gui_size max, gui_bool *active, gui_size *cursor,
enum gui_input_filter);
/* this function creates an editbox to updated/insert user text input
Input:
- buffer to fill with user input
@ -2385,8 +2414,8 @@ gui_size gui_panel_edit(struct gui_panel_layout*, gui_char *buffer, gui_size len
- current state of the editbox with active(gui_true) or inactive(gui_false)
*/
gui_size gui_panel_edit_filtered(struct gui_panel_layout*, gui_char *buffer,
gui_size len, gui_size max,
gui_bool *active, gui_filter);
gui_size len, gui_size max, gui_bool *active,
gui_size *cursor, gui_filter);
/* this function creates an editbox to updated/insert filtered user text input
Input:
- buffer to fill with user input
@ -2568,7 +2597,7 @@ void gui_panel_table_end(struct gui_panel_layout*);
to its normal state.
*/
void gui_panel_tree_begin(struct gui_panel_layout*, struct gui_tree*,
const char*, gui_float row_height, gui_float offset);
const char*, gui_float row_height, struct gui_vec2 offset);
/* this function begins the tree building process
Input:
- title describing the tree or NULL
@ -2619,7 +2648,7 @@ enum gui_tree_node_operation gui_panel_tree_leaf_icon(struct gui_tree*,
Output:
- operation identifier what should be done with this node
*/
gui_float gui_panel_tree_end(struct gui_panel_layout*, struct gui_tree*);
struct gui_vec2 gui_panel_tree_end(struct gui_panel_layout*, struct gui_tree*);
/* this function ends a the tree building process */
/*
* -------------------------------------------------------------
@ -2632,7 +2661,7 @@ gui_float gui_panel_tree_end(struct gui_panel_layout*, struct gui_tree*);
gui_panel_shelf_end -- ends a previously started shelf build up process
*/
void gui_panel_group_begin(struct gui_panel_layout*, struct gui_panel_layout *tab,
const char *title, gui_float offset);
const char *title, struct gui_vec2 offset);
/* this function adds a grouped subpanel into the parent panel
IMPORTANT: You need to set the height of the group with panel_row_layout
Input:
@ -2641,14 +2670,14 @@ void gui_panel_group_begin(struct gui_panel_layout*, struct gui_panel_layout *ta
Output:
- group layout to fill with widgets
*/
gui_float gui_panel_group_end(struct gui_panel_layout*, struct gui_panel_layout* tab);
struct gui_vec2 gui_panel_group_end(struct gui_panel_layout*, struct gui_panel_layout* tab);
/* this function finishes the previously started group layout
Output:
- The from user input updated group scrollbar pixel offset
*/
gui_size gui_panel_shelf_begin(struct gui_panel_layout*, struct gui_panel_layout*,
const char *tabs[], gui_size size,
gui_size active, gui_float offset);
gui_size active, struct gui_vec2 offset);
/* this function adds a shelf subpanel into the parent panel
IMPORTANT: You need to set the height of the shelf with panel_row_layout
Input:
@ -2660,7 +2689,7 @@ gui_size gui_panel_shelf_begin(struct gui_panel_layout*, struct gui_panel_layout
- group layout to fill with widgets
- the from user input updated current shelf tab index
*/
gui_float gui_panel_shelf_end(struct gui_panel_layout*, struct gui_panel_layout*);
struct gui_vec2 gui_panel_shelf_end(struct gui_panel_layout*, struct gui_panel_layout*);
/* this function finishes the previously started shelf layout
Input:
- previously started group layout

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 42 KiB

BIN
screen/explorer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB