From 073affc975d6c780c286bf9c534ef5014b7b1ed9 Mon Sep 17 00:00:00 2001 From: vurtun Date: Wed, 9 Sep 2015 14:31:19 +0200 Subject: [PATCH] added seperator widget --- gui.c | 32 ++++++++++++++++++++++++++++---- gui.h | 3 +++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/gui.c b/gui.c index 5a78284..e3e2bc2 100644 --- a/gui.c +++ b/gui.c @@ -5376,7 +5376,7 @@ gui_layout_row_tiled_begin(struct gui_context *layout, if (!layout->valid) return; layout->row.tiled = tiled; - gui_panel_layout(layout, (gui_size)tiled->height, 2); + gui_panel_layout(layout, tiled->height, 2); if (tiled->fmt == GUI_STATIC) { /* calculate bounds of the tiled layout */ struct gui_rect clip, space; @@ -5431,7 +5431,7 @@ gui_layout_row_tiled_push(struct gui_context *layout, spacing = config->properties[GUI_PROPERTY_ITEM_SPACING]; if (s->format == GUI_SLOT_HORIZONTAL) { slot_bounds.h -= (2 * spacing.y); - slot_bounds.w -= s->capacity * spacing.x; + slot_bounds.w -= (gui_float)s->capacity * spacing.x; layout->row.item.h = slot_bounds.h; layout->row.item.y = slot_bounds.y; @@ -5440,9 +5440,9 @@ gui_layout_row_tiled_push(struct gui_context *layout, } else { layout->row.item.x = slot_bounds.x + spacing.x; layout->row.item.w = slot_bounds.w - (2 * spacing.x); - layout->row.item.h = (slot_bounds.h - s->capacity * spacing.y)/(gui_float)s->capacity; + layout->row.item.h = (slot_bounds.h - (gui_float)s->capacity * spacing.y)/(gui_float)s->capacity; layout->row.item.y = slot_bounds.y + (gui_float)index * layout->row.item.h; - layout->row.item.y += (index * spacing.y); + layout->row.item.y += ((gui_float)index * spacing.y); } } @@ -5770,6 +5770,30 @@ gui_spacing(struct gui_context *l, gui_size cols) l->row.index = index; } +void +gui_seperator(struct gui_context *layout) +{ + struct gui_command_buffer *out; + const struct gui_style *config; + struct gui_vec2 item_padding; + struct gui_vec2 item_spacing; + struct gui_rect bounds; + GUI_ASSERT(layout); + if (!layout) return; + + out = layout->buffer; + config = layout->style; + item_padding = gui_style_property(config, GUI_PROPERTY_ITEM_PADDING); + item_spacing = gui_style_property(config, GUI_PROPERTY_ITEM_SPACING); + + bounds.w = MAX(layout->width, 2 * item_spacing.x + 2 * item_padding.x); + bounds.y = (layout->at_y + layout->row.height + item_padding.y) - layout->offset.y; + bounds.x = layout->at_x + item_spacing.x + item_padding.x - layout->offset.x; + bounds.w = bounds.w - (2 * item_spacing.x + 2 * item_padding.x); + gui_command_buffer_push_line(out, bounds.x, bounds.y, bounds.x + bounds.w, + bounds.y + bounds.h, config->colors[GUI_COLOR_BORDER]); +} + enum gui_widget_state gui_widget(struct gui_rect *bounds, struct gui_context *layout) { diff --git a/gui.h b/gui.h index 7d4eb7c..508aa4d 100644 --- a/gui.h +++ b/gui.h @@ -2960,6 +2960,7 @@ void gui_layout_pop(struct gui_context*); window widget API gui_widget -- base function for all widgets to allocate space gui_spacing -- column seperator and is basically an empty widget + gui_seperator -- adds either a horizontal or vertical seperator gui_text -- text widget for printing text with length gui_text_colored -- colored text widget for printing string by length gui_label -- text widget for printing zero terminated strings @@ -2995,6 +2996,8 @@ void gui_spacing(struct gui_context*, gui_size cols); Input: - number of columns or widget to jump over */ +void gui_seperator(struct gui_context*); +/* this function creates a seperator line */ void gui_text(struct gui_context*, const char*, gui_size, enum gui_text_align); /* this function creates a bounded non terminated text widget with either