removed need for string length in api

This commit is contained in:
vurtun 2015-03-30 00:51:07 +02:00
parent 4e7f37243c
commit 667b4bcf29
3 changed files with 30 additions and 28 deletions

View File

@ -377,7 +377,6 @@ main(int argc, char *argv[])
if (SDL_Init(SDL_INIT_VIDEO) < 0)
die("[SDL] unabled to initialize\n");
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
win = SDL_CreateWindow("clone",
0, 0, WIN_WIDTH, WIN_HEIGHT, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN);
if (!win) die("[SDL] unable to create window\n");
@ -427,12 +426,12 @@ main(int argc, char *argv[])
GUI_PANEL_HEADER|GUI_PANEL_CLOSEABLE|GUI_PANEL_MINIMIZABLE|
GUI_PANEL_MOVEABLE|GUI_PANEL_SCROLLBAR|GUI_PANEL_SCALEABLE);
gui_panel_layout(panel, 30, 1);
if (gui_panel_button_text(panel, "button", 6, GUI_BUTTON_SWITCH))
if (gui_panel_button_text(panel, "button", GUI_BUTTON_SWITCH))
fprintf(stdout, "button pressed!\n");
check = gui_panel_check(panel, "advanced", 8, check);
check = gui_panel_check(panel, "advanced", check);
gui_panel_layout(panel, 30, 2);
if (gui_panel_option(panel, "easy", 4, option == 0)) option = 0;
if (gui_panel_option(panel, "hard", 4, option == 1)) option = 1;
if (gui_panel_option(panel, "easy", option == 0)) option = 0;
if (gui_panel_option(panel, "hard", option == 1)) option = 1;
gui_panel_layout(panel, 30, 1);
slider = gui_panel_slider(panel, 0, slider, 10, 1.0f, GUI_HORIZONTAL);
prog = gui_panel_progress(panel, prog, 100, gui_true, GUI_HORIZONTAL);
@ -448,8 +447,8 @@ main(int argc, char *argv[])
gui_begin_panel(ctx, subpanel, "Error",
GUI_PANEL_HEADER|GUI_PANEL_BORDER|GUI_PANEL_MOVEABLE);
gui_panel_layout(subpanel, 30, 2);
if (gui_panel_button_text(subpanel, "ok", 2, GUI_BUTTON_SWITCH)) break;
if (gui_panel_button_text(subpanel, "cancel", 6, GUI_BUTTON_SWITCH)) break;
if (gui_panel_button_text(subpanel, "ok", GUI_BUTTON_SWITCH)) break;
if (gui_panel_button_text(subpanel, "cancel", GUI_BUTTON_SWITCH)) break;
gui_end_panel(ctx, subpanel, NULL);
gui_end(ctx, &output, NULL);
/* ---------------------------------------------------------*/

29
gui.c
View File

@ -1773,12 +1773,13 @@ gui_panel_text(struct gui_panel *panel, const char *str, gui_size len)
}
gui_bool
gui_panel_button_text(struct gui_panel *panel, const char *str, gui_size len,
gui_panel_button_text(struct gui_panel *panel, const char *str,
enum gui_button_behavior behavior)
{
struct gui_rect bounds;
struct gui_button button;
const struct gui_config *config;
gui_size len;
assert(panel);
assert(panel->config);
@ -1789,6 +1790,7 @@ gui_panel_button_text(struct gui_panel *panel, const char *str, gui_size len,
if (panel->minimized || (panel->flags & GUI_PANEL_HIDDEN)) return 0;
gui_panel_alloc_space(&bounds, panel);
config = panel->config;
len = strsiz(str);
button.x = bounds.x;
button.y = bounds.y;
@ -1900,12 +1902,12 @@ gui_panel_button_icon(struct gui_panel *panel, gui_texture tex,
}
gui_bool
gui_panel_button_toggle(struct gui_panel *panel, const char *str, gui_size len,
gui_bool value)
gui_panel_button_toggle(struct gui_panel *panel, const char *str, gui_bool value)
{
struct gui_rect bounds;
struct gui_button button;
const struct gui_config *config;
gui_size len;
assert(panel);
assert(panel->config);
@ -1916,6 +1918,7 @@ gui_panel_button_toggle(struct gui_panel *panel, const char *str, gui_size len,
if (panel->minimized || (panel->flags & GUI_PANEL_HIDDEN)) return 0;
gui_panel_alloc_space(&bounds, panel);
config = panel->config;
len = strsiz(str);
button.x = bounds.x;
button.y = bounds.y;
@ -1943,12 +1946,12 @@ gui_panel_button_toggle(struct gui_panel *panel, const char *str, gui_size len,
}
gui_bool
gui_panel_check(struct gui_panel *panel, const char *text, gui_size length,
gui_bool is_active)
gui_panel_check(struct gui_panel *panel, const char *text, gui_bool is_active)
{
struct gui_rect bounds;
struct gui_toggle toggle;
const struct gui_config *config;
gui_size length;
assert(panel);
assert(panel->config);
@ -1959,6 +1962,7 @@ gui_panel_check(struct gui_panel *panel, const char *text, gui_size length,
if (panel->minimized || (panel->flags & GUI_PANEL_HIDDEN)) return is_active;
gui_panel_alloc_space(&bounds, panel);
config = panel->config;
length = strsiz(text);
toggle.x = bounds.x;
toggle.y = bounds.y;
@ -1977,12 +1981,12 @@ gui_panel_check(struct gui_panel *panel, const char *text, gui_size length,
}
gui_bool
gui_panel_option(struct gui_panel *panel, const char *text, gui_size length,
gui_bool is_active)
gui_panel_option(struct gui_panel *panel, const char *text, gui_bool is_active)
{
struct gui_rect bounds;
struct gui_toggle toggle;
const struct gui_config *config;
gui_size length;
assert(panel);
assert(panel->config);
@ -1993,6 +1997,7 @@ gui_panel_option(struct gui_panel *panel, const char *text, gui_size length,
if (panel->minimized || (panel->flags & GUI_PANEL_HIDDEN)) return is_active;
gui_panel_alloc_space(&bounds, panel);
config = panel->config;
length = strsiz(text);
toggle.x = bounds.x;
toggle.y = bounds.y;
@ -2423,10 +2428,8 @@ gui_panel_list(struct gui_panel *panel, gui_bool *selection,
config.panel_padding.x = 0.0f;
config.item_spacing.y = 0.0f;
gui_panel_layout(&list, item_height, 1);
for (i = 0; i < item_count; i++) {
selection[i] = gui_panel_button_toggle(&list, items[i],
strsiz(items[i]), selection[i]);
}
for (i = 0; i < item_count; i++)
selection[i] = gui_panel_button_toggle(&list, items[i] , selection[i]);
gui_panel_end(&list);
return list.offset;
}
@ -2494,6 +2497,7 @@ gui_new(const struct gui_memory *memory, const struct gui_input *input)
struct gui_context *ctx;
static const gui_size align_panels = ALIGNOF(struct gui_context_panel);
static const gui_size align_list = ALIGNOF(struct gui_draw_call_list**);
assert(memory);
assert(input);
if (!memory || !input)
@ -2575,6 +2579,7 @@ gui_rm_draw_list(struct gui_context *ctx, struct gui_draw_call_list *list)
if (ctx->panel_lists[i] == list)
break;
}
if (i == ctx->panel_size) return;
if (i < ctx->panel_size-1) {
for (n = i+1; n < ctx->panel_size; n++, i++)
@ -2634,9 +2639,11 @@ gui_begin_panel(struct gui_context *ctx, struct gui_panel *panel,
struct gui_context_panel *cpanel;
struct gui_draw_buffer *out;
struct gui_draw_buffer *global;
assert(ctx);
assert(panel);
assert(title);
if (!ctx || !panel || !title)
return gui_false;
if (panel->flags & GUI_PANEL_HIDDEN)

16
gui.h
View File

@ -404,19 +404,15 @@ gui_bool gui_panel_begin(struct gui_panel*, struct gui_draw_buffer*,
void gui_panel_layout(struct gui_panel*, gui_float height, gui_size cols);
void gui_panel_seperator(struct gui_panel*, gui_size cols);
void gui_panel_text(struct gui_panel*, const char *str, gui_size len);
gui_bool gui_panel_check(struct gui_panel*, const char*, gui_size, gui_bool active);
gui_bool gui_panel_option(struct gui_panel*, const char*, gui_size, gui_bool active);
gui_bool gui_panel_button_text(struct gui_panel*, const char*, gui_size,
enum gui_button_behavior);
gui_bool gui_panel_button_color(struct gui_panel*, const struct gui_color,
enum gui_button_behavior);
gui_bool gui_panel_button_triangle(struct gui_panel*, enum gui_heading,
enum gui_button_behavior);
gui_bool gui_panel_check(struct gui_panel*, const char*, gui_bool active);
gui_bool gui_panel_option(struct gui_panel*, const char*, gui_bool active);
gui_bool gui_panel_button_text(struct gui_panel*, const char*, enum gui_button_behavior);
gui_bool gui_panel_button_color(struct gui_panel*, const struct gui_color, enum gui_button_behavior);
gui_bool gui_panel_button_triangle(struct gui_panel*, enum gui_heading, enum gui_button_behavior);
gui_bool gui_panel_button_toggle(struct gui_panel*, const char*, gui_bool value);
gui_bool gui_panel_button_icon(struct gui_panel*, gui_texture,
struct gui_texCoord from, struct gui_texCoord to,
enum gui_button_behavior);
gui_bool gui_panel_button_toggle(struct gui_panel*, const char*, gui_size,
gui_bool value);
gui_float gui_panel_slider(struct gui_panel*, gui_float min, gui_float val,
gui_float max, gui_float step, enum gui_direction);
gui_size gui_panel_progress(struct gui_panel*, gui_size cur, gui_size max,