basic features work for linux

This commit is contained in:
vurtun 2015-04-16 20:05:43 +02:00
parent b1d42ae471
commit 41ce335226
4 changed files with 36 additions and 96 deletions

View File

@ -14,12 +14,12 @@ WORK IN PROGRESS: I do not garantee that anything works right now
- Configurable
- UTF-8 supported
## Limitation
- It does NOT provide platform indepenedent window management
- It does NOT provide platform independent input handling
- It does NOT provide a renderer backend
- it does NOT implement a font library
- Summary: It is only responsible for the actual user interface
## Limitations
- Does NOT provide platform independent window management
- Does NOT provide platform independent input handling
- Does NOT provide a renderer backend
- Does NOT implement a font library
Summary: It is only responsible for the actual user interface
## Layer
The gui toolkit consists of three level of abstraction. First the basic widget layer
@ -35,32 +35,37 @@ Each higher level of astraction uses the lower level(s) internally to build
on but offers a little bit of a different API.
## Configuration
While the widgets layer offers the most configuration and even expects you to
configure each and every widget, the upper levels provide you with a basic set of
configurable attributes like color, padding and spacing.
The gui toolkit provides a number of different attributes that can be
configured, like spacing, padding, size and color.
While the widget API even expects you to provide the configuration
for each and every widget the higher layers provide you with a set of
attributes in the `gui_config` structure. The structure either needs to be
filled by the user or can be setup with some default values by the function
`gui_default_config`. Modification on the fly to the `gui_config` is in
in true immedate mode fashion possible and supported.
## FAQ
### Where is Widget X?
#### Where is Widget X?
A number of basic widgets are provided but some of the more complex widgets like
comboboxes, tables and tree views are not yet implemented. Maybe if I have more
comboboxes, tables and trees are not yet implemented. Maybe if I have more
time I will look into adding them, except for comboboxes which are just
really hard to implement.
### 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
worthless and never brought anything good with it. The simple answer is I
personally love C and have nothing against people using C++ exspecially the new
iterations with C++11 and C++14.
While this hopefully settles my view on C vs C++ there is still ANSI C vs C99.
While for personal projects I only use C99 with all its niceties, libraries are a
While for personal projects I only use C99 with all its niceties, libraries are
a little bit different. Libraries are designed to reach the highest number of
users possible which brings me to ANSI C which is probably the most portable
programming language out there. In addition not all C compiler like the MSVC
users possible which brings me to ANSI C which is the most portable version.
In addition not all C compiler like the MSVC
compiler fully support C99, which finalized my decision to use ANSI C.
### Why do you typedef our own types instead of using the standard types
Because this project is in ANSI C which does not have the header file `<stdint.h>`
and therefore does not provide me the with fixed sized types that I need. Therefore
#### Why do you typedef our own types instead of using the standard types
This Project uses ANSI C which does not have the header file `<stdint.h>`
and therefore does not provide the fixed sized types that I need. Therefore
I defined my own types which need to be set to the correct size for each
plaform. But if your development environment provides the header file you can define
`GUI_USE_FIXED_SIZE_TYPES` to directly use the correct types.

View File

@ -318,6 +318,11 @@ key(struct XWindow *xw, struct gui_input *in, XEvent *evt, gui_bool down)
gui_input_key(in, GUI_KEY_SPACE, down);
else if (*code == XK_BackSpace)
gui_input_key(in, GUI_KEY_BACKSPACE, down);
else if (*code > 32 && *code < 128 && !down) {
gui_glyph glyph;
glyph[0] = (gui_char)*code;
gui_input_char(in, glyph);
}
XFree(code);
}
@ -428,7 +433,7 @@ demo_panel(struct gui_context *ctx, struct gui_panel *panel, struct demo *demo)
/* Tabs */
gui_panel_layout(panel, 100, 1);
gui_panel_tab_begin(panel, &demo->tab, "Difficulty");
gui_panel_layout(&demo->tab, 30, 2);
gui_panel_layout(&demo->tab, 30, 1);
if (gui_panel_option(&demo->tab, "easy", demo->option == 0)) demo->option = 0;
if (gui_panel_option(&demo->tab, "hard", demo->option == 1)) demo->option = 1;
if (gui_panel_option(&demo->tab, "normal", demo->option == 2)) demo->option = 2;
@ -455,10 +460,9 @@ demo_panel(struct gui_context *ctx, struct gui_panel *panel, struct demo *demo)
demo->slider = gui_panel_slider(&demo->group, 0, demo->slider, 10, 1.0f);
demo->prog = gui_panel_progress(&demo->group, demo->prog, 100, gui_true);
demo->item_cur = gui_panel_selector(&demo->group, items, LEN(items), demo->item_cur);
demo->spin_act = gui_panel_spinner(&demo->group, 0, &demo->spinner, 250, 10, demo->spin_act);
demo->in_act = gui_panel_input(&demo->group, demo->in_buf, &demo->in_len,
MAX_BUFFER, GUI_INPUT_DEFAULT, demo->in_act);
if (gui_panel_shell(&demo->group, demo->cmd_buf, &demo->cmd_len, MAX_BUFFER, &demo->cmd_act))
fprintf(stdout, "shell executed!\n");
gui_panel_group_end(panel, &demo->group);
gui_end_panel(ctx, panel, NULL);
@ -520,11 +524,11 @@ main(int argc, char *argv[])
font.height = (gui_float)xfont->height;
font.width = font_get_text_width;
gui_default_config(&config);
panel = gui_new_panel(ctx, 50, 50, 500, 320, &config, &font);
panel = gui_new_panel(ctx, 50, 50, 400, 300, &config, &font);
memset(&demo, 0, sizeof(demo));
demo.tab.minimized = gui_false;
demo.spinner = 250;
demo.tab.minimized = gui_true;
demo.spinner = 100;
demo.slider = 2.0f;
demo.prog = 60;
demo.current = 1;

73
gui.c
View File

@ -1001,7 +1001,7 @@ gui_widget_input(struct gui_command_buffer *buf, gui_char *buffer, gui_size *le
label_y = input->y + input->pad_y;
label_h = input_h - 2 * input->pad_y;
gui_buffer_push_text(buf, font->user, label_x, label_y, label_w, label_h,
&buffer[offset], text_len, input->foreground, input->font);
&buffer[offset], text_len, input->foreground, input->background);
if (input_active && input->show_cursor) {
gui_buffer_push_rect(buf, label_x + (gui_float)text_width, label_y,
(gui_float)cursor_width, label_h, input->background);
@ -1174,6 +1174,7 @@ gui_widget_scroll(struct gui_command_buffer *buffer, const struct gui_scroll *sc
button.background = scroll->foreground;
button.foreground = scroll->background;
button.highlight = scroll->foreground;
button.highlight_content = scroll->background;
button.behavior = GUI_BUTTON_DEFAULT;
button_up_pressed = gui_widget_button_triangle(buffer, &button, GUI_UP, in);
button.y = scroll->y + scroll_h - button.h;
@ -1881,74 +1882,6 @@ gui_panel_input(struct gui_panel *panel, gui_char *buffer, gui_size *length,
return gui_widget_input(panel->out, buffer, length, &field, &panel->font, panel->in);
}
gui_size
gui_panel_shell(struct gui_panel *panel, gui_char *buffer, gui_size *length,
gui_size max, gui_bool *active)
{
struct gui_rect bounds;
gui_size submit = 0;
gui_size space = 0;
struct gui_button button;
struct gui_input_field field;
const struct gui_config *config;
assert(panel);
assert(panel->config);
assert(panel->out);
assert(buffer);
assert(length);
assert(active);
if (!panel || !panel->config || !panel->out) return 0;
if (panel->minimized || (panel->flags & GUI_PANEL_HIDDEN)) return 0;
gui_panel_alloc_space(&bounds, panel);
config = panel->config;
field.x = bounds.x;
field.y = bounds.y;
field.w = bounds.w;
field.h = bounds.h;
field.pad_x = config->item_padding.x;
field.pad_y = config->item_padding.y;
field.max = max;
field.filter = GUI_INPUT_DEFAULT;
field.active = *active;
field.font = config->colors[GUI_COLOR_TEXT];
field.background = config->colors[GUI_COLOR_INPUT];
field.foreground = config->colors[GUI_COLOR_INPUT_BORDER];
space = panel->font.width(panel->font.user, (const gui_char*)"Submit", 6);
button.y = field.y;
button.h = field.h;
button.w = (gui_float)space + 2 * field.pad_x - 1;
button.x = field.x + field.w - button.w + 1;
button.pad_x = field.pad_x;
button.pad_y = field.pad_y;
button.border = 1;
button.behavior = GUI_BUTTON_DEFAULT;
button.background = config->colors[GUI_COLOR_BUTTON];
button.foreground = config->colors[GUI_COLOR_BUTTON_BORDER];
button.content = config->colors[GUI_COLOR_TEXT];
button.highlight = config->colors[GUI_COLOR_BUTTON_HOVER];
button.highlight_content = config->colors[GUI_COLOR_BUTTON_HOVER_FONT];
if (gui_widget_button_text(panel->out, &button, "Submit", 6, &panel->font, panel->in)) {
submit = *length;
*length = 0;
}
field.w = field.w - button.w;
*active = gui_widget_input(panel->out, (gui_char*)buffer, length, &field,
&panel->font, panel->in);
if (!submit && active && panel->in) {
const struct gui_key *enter = &panel->in->keys[GUI_KEY_ENTER];
if ((enter->down && enter->clicked)) {
submit = *length;
*length = 0;
}
}
return submit;
}
gui_bool
gui_panel_spinner(struct gui_panel *panel, gui_int min, gui_int *value,
gui_int max, gui_int step, gui_bool active)
@ -2049,11 +1982,11 @@ gui_panel_selector(struct gui_panel *panel, const char *items[],
gui_buffer_push_rect(panel->out, bounds.x + 1, bounds.y + 1, bounds.w - 2, bounds.h - 2,
config->colors[GUI_COLOR_SELECTOR]);
button.border = 1;
button.y = bounds.y;
button.h = bounds.h / 2;
button.w = bounds.h - config->item_padding.x + 1;
button.x = bounds.x + bounds.w - button.w - 1;
button.border = 1;
button.pad_x = MAX(3, button.h - panel->font.height);
button.pad_y = MAX(3, button.h - panel->font.height);
button.behavior = GUI_BUTTON_DEFAULT;

2
gui.h
View File

@ -474,8 +474,6 @@ gui_size gui_panel_progress(struct gui_panel*, gui_size cur, gui_size max,
gui_bool modifyable);
gui_bool gui_panel_input(struct gui_panel*, gui_char *buffer, gui_size *len,
gui_size max, enum gui_input_filter, gui_bool active);
gui_size gui_panel_shell(struct gui_panel*, gui_char *buffer, gui_size *length,
gui_size max, gui_bool *active);
gui_bool gui_panel_spinner(struct gui_panel*, gui_int min, gui_int *value,
gui_int max, gui_int step, gui_bool active);
gui_size gui_panel_selector(struct gui_panel*, const char *items[],