added icon to tree nodes + fixed c++ errors

This commit is contained in:
vurtun 2015-07-18 03:37:42 +02:00
parent 0601fb49fd
commit 6f5c990470
3 changed files with 92 additions and 86 deletions

View File

@ -4,7 +4,7 @@
#define WINDOW_HEIGHT 600
struct tree_node {
enum gui_tree_node_state state;
gui_tree_node_state state;
const char *name;
struct tree_node *parent;
struct tree_node *children[8];
@ -112,7 +112,9 @@ widget_panel(struct gui_panel_layout *panel, struct show_window *demo)
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;
{
/* templated row layout */
char buffer[MAX_BUFFER];
const gui_float ratio[] = {0.8f, 0.2f};
gui_panel_row_templated(panel, 30, 2, ratio);
@ -129,12 +131,14 @@ widget_panel(struct gui_panel_layout *panel, struct show_window *demo)
demo->spinner = gui_panel_spinner(panel, 0, demo->spinner, 250, 10, &demo->spinner_active);
gui_panel_row_begin(panel, 30, 2);
gui_panel_row_push_widget(panel, 0.7f);
gui_panel_editbox(panel, &demo->input);
gui_panel_row_push_widget(panel, 0.3f);
if (gui_panel_button_text(panel, "submit", GUI_BUTTON_DEFAULT)) {
gui_edit_box_reset(&demo->input);
fprintf(stdout, "command executed!\n");
{
gui_panel_row_push_widget(panel, 0.7f);
gui_panel_editbox(panel, &demo->input);
gui_panel_row_push_widget(panel, 0.3f);
if (gui_panel_button_text(panel, "submit", GUI_BUTTON_DEFAULT)) {
gui_edit_box_reset(&demo->input);
fprintf(stdout, "command executed!\n");
}
}
gui_panel_row_end(panel);
}
@ -322,31 +326,37 @@ update_show(struct show_window *show, struct gui_stack *stack, struct gui_input
gui_panel_begin_stacked(&layout, &show->hook, stack, "Show", in);
show->combobox_tab = gui_panel_tab_begin(&layout, &tab, "Combobox",
GUI_BORDER, show->combobox_tab);
combobox_panel(&tab, show);
gui_panel_tab_end(&layout, &tab);
show->widget_tab = gui_panel_tab_begin(&layout, &tab, "Widgets",GUI_BORDER, show->widget_tab);
widget_panel(&tab, show);
gui_panel_tab_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_BORDER, show->combobox_tab);
{
struct gui_tree tree;
gui_panel_row(&layout, 250, 1);
gui_panel_tree_begin(&layout, &tree, "Tree", 20, show->tree_offset);
upload_tree(&show->tree, &tree, &show->tree.root);
show->tree_offset = gui_panel_tree_end(&layout, &tree);
combobox_panel(&tab, show);
gui_panel_tab_end(&layout, &tab);
/* Widgets */
show->widget_tab = gui_panel_tab_begin(&layout, &tab, "Widgets",GUI_BORDER, show->widget_tab);
widget_panel(&tab, show);
gui_panel_tab_end(&layout, &tab);
/* Graph */
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);
/* Table */
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);
{
/* Tree */
struct gui_tree tree;
gui_panel_row(&layout, 250, 1);
gui_panel_tree_begin(&layout, &tree, "Tree", 20, show->tree_offset);
upload_tree(&show->tree, &tree, &show->tree.root);
show->tree_offset = gui_panel_tree_end(&layout, &tree);
}
}
gui_panel_end(&layout, &show->hook);
}
@ -494,22 +504,23 @@ update_control(struct control_window *control, struct gui_stack *stack,
struct gui_panel_layout tab;
running = gui_panel_begin_stacked(&layout, &control->hook, stack, "Control", in);
control->flag_tab = gui_panel_tab_begin(&layout, &tab, "Options", GUI_BORDER, control->flag_tab);
update_flags(&tab, control);
gui_panel_tab_end(&layout, &tab);
{
control->flag_tab = gui_panel_tab_begin(&layout, &tab, "Options", GUI_BORDER, control->flag_tab);
update_flags(&tab, control);
gui_panel_tab_end(&layout, &tab);
control->style_tab = gui_panel_tab_begin(&layout, &tab, "Properties", GUI_BORDER, control->style_tab);
properties_tab(&tab, config);
gui_panel_tab_end(&layout, &tab);
control->style_tab = gui_panel_tab_begin(&layout, &tab, "Properties", GUI_BORDER, control->style_tab);
properties_tab(&tab, config);
gui_panel_tab_end(&layout, &tab);
control->round_tab = gui_panel_tab_begin(&layout, &tab, "Rounding", GUI_BORDER, control->round_tab);
round_tab(&tab, config);
gui_panel_tab_end(&layout, &tab);
control->color_tab = gui_panel_tab_begin(&layout, &tab, "Color", GUI_BORDER, control->color_tab);
color_tab(&tab, control, config);
gui_panel_tab_end(&layout, &tab);
control->round_tab = gui_panel_tab_begin(&layout, &tab, "Rounding", GUI_BORDER, control->round_tab);
round_tab(&tab, config);
gui_panel_tab_end(&layout, &tab);
control->color_tab = gui_panel_tab_begin(&layout, &tab, "Color", GUI_BORDER, control->color_tab);
color_tab(&tab, control, config);
gui_panel_tab_end(&layout, &tab);
}
gui_panel_end(&layout, &control->hook);
return running;
}

64
gui.c
View File

@ -1110,7 +1110,7 @@ gui_edit_box_at_cursor(struct gui_edit_box *eb, gui_glyph g, gui_size *len)
return;
}
cursor = (eb->cursor) ? eb->cursor-1 : 0;
gui_edit_box_at(eb, 0, g, len);
gui_edit_box_at(eb, cursor, g, len);
}
void
@ -1593,7 +1593,6 @@ static gui_size
gui_utf_glyph_index_at_pos(const struct gui_font *font, const char *text,
gui_size text_len, gui_float xoff)
{
gui_size i = 0;
gui_long unicode;
gui_size glyph_offset = 0;
gui_size glyph_len = gui_utf_decode(text, &unicode, text_len);
@ -2649,18 +2648,17 @@ gui_panel_begin_tiled(struct gui_panel_layout *tile, struct gui_panel *panel,
switch (slot) {
case GUI_SLOT_TOP:
s = &layout->slots[GUI_SLOT_TOP];
scaler.x = bounds.x;
scaler.y = (bounds.y + bounds.h) - config->scaler_width;
scaler.w = bounds.w;
scaler.h = config->scaler_width;
if (in && s->state!=GUI_LOCKED && !(layout->flags&GUI_LAYOUT_INACTIVE) &&
in->mouse_down &&
GUI_INBOX(mpos.x, mpos.y, scaler.x, scaler.y, scaler.w, scaler.h)) {
gui_float py, dy = in->mouse_delta.y;
bounds.h += dy;
GUI_INBOX(mpos.x, mpos.y, scaler.x, scaler.y, scaler.w, scaler.h) &&
in->mouse_down)
{
gui_float py;
bounds.h += in->mouse_delta.y;
bounds.h = MAX(config->properties[GUI_PROPERTY_SIZE].y, bounds.h);
scaler.y = (bounds.y + bounds.h) - config->scaler_width;
@ -2678,19 +2676,19 @@ gui_panel_begin_tiled(struct gui_panel_layout *tile, struct gui_panel *panel,
bounds.h -= config->scaler_width;
break;
case GUI_SLOT_BOTTOM:
s = &layout->slots[GUI_SLOT_BOTTOM];
scaler.x = bounds.x;
scaler.y = bounds.y;
scaler.w = bounds.w;
scaler.h = config->scaler_width;
if (in && s->state != GUI_LOCKED && !(layout->flags & GUI_LAYOUT_INACTIVE) &&
in->mouse_down &&
GUI_INBOX(mpos.x, mpos.y, scaler.x, scaler.y, scaler.w, scaler.h)) {
gui_float py, dy = in->mouse_delta.y;
GUI_INBOX(mpos.x, mpos.y, scaler.x, scaler.y, scaler.w, scaler.h) &&
in->mouse_down)
{
gui_float py;
bounds.y += dy;
bounds.h += -dy;
bounds.y += in->mouse_delta.y;
bounds.h += -in->mouse_delta.y;
scaler.y = bounds.y;
py = 1.0f - ((bounds.h / (gui_float)layout->height) +
@ -2706,19 +2704,17 @@ gui_panel_begin_tiled(struct gui_panel_layout *tile, struct gui_panel *panel,
bounds.h -= config->scaler_width;
break;
case GUI_SLOT_LEFT:
s = &layout->slots[GUI_SLOT_LEFT];
scaler.x = bounds.x + bounds.w - config->scaler_width;
scaler.y = bounds.y;
scaler.w = config->scaler_width;
scaler.h = bounds.h;
if (in && s->state != GUI_LOCKED && in->mouse_down &&
!(layout->flags & GUI_LAYOUT_INACTIVE) &&
GUI_INBOX(mpos.x, mpos.y, scaler.x, scaler.y, scaler.w, scaler.h)) {
gui_float dx = in->mouse_delta.x;
GUI_INBOX(mpos.x, mpos.y, scaler.x, scaler.y, scaler.w, scaler.h) &&
!(layout->flags & GUI_LAYOUT_INACTIVE))
{
gui_float cx, rx;
bounds.w += dx;
bounds.w += in->mouse_delta.x;
bounds.w = MAX(config->properties[GUI_PROPERTY_SIZE].x, bounds.w);
scaler.x = bounds.x + bounds.w - config->scaler_width;
@ -2738,20 +2734,19 @@ gui_panel_begin_tiled(struct gui_panel_layout *tile, struct gui_panel *panel,
bounds.w -= config->scaler_width;
break;
case GUI_SLOT_RIGHT:
s = &layout->slots[GUI_SLOT_LEFT];
scaler.x = bounds.x;
scaler.y = bounds.y;
scaler.w = config->scaler_width;
scaler.h = bounds.h;
if (in && s->state != GUI_LOCKED && in->mouse_down &&
!(layout->flags & GUI_LAYOUT_INACTIVE) &&
GUI_INBOX(mpos.x, mpos.y, scaler.x, scaler.y, scaler.w, scaler.h)) {
gui_float dx = in->mouse_delta.x;
if (in && layout->slots[GUI_SLOT_LEFT].state != GUI_LOCKED && in->mouse_down &&
GUI_INBOX(mpos.x, mpos.y, scaler.x, scaler.y, scaler.w, scaler.h) &&
!(layout->flags & GUI_LAYOUT_INACTIVE))
{
gui_float cx, lx;
bounds.w -= dx;
bounds.x += dx;
bounds.w -= in->mouse_delta.x;
bounds.x += in->mouse_delta.x;
bounds.w = MAX(config->properties[GUI_PROPERTY_SIZE].x, bounds.w);
scaler.x = bounds.x;
@ -2899,6 +2894,7 @@ gui_panel_row_templated(struct gui_panel_layout *layout, gui_float height,
if (!layout) return;
if (!layout->valid) return;
/* calculate width of undefined widget ratios */
gui_panel_row(layout, height, cols);
layout->row.ratio = ratio;
for (i = 0; i < cols; ++i) {
@ -4188,7 +4184,7 @@ gui_panel_tree_begin(struct gui_panel_layout *p, struct gui_tree *tree,
static enum gui_tree_node_operation
gui_panel_tree_node(struct gui_tree *tree, enum gui_tree_node_symbol symbol,
const char *title, struct gui_image *img, enum gui_tree_node_state *state)
const char *title, struct gui_image *img, gui_tree_node_state *state)
{
struct gui_text text;
struct gui_rect bounds;
@ -4243,7 +4239,7 @@ gui_panel_tree_node(struct gui_tree *tree, enum gui_tree_node_symbol symbol,
if (gui_input_clicked(i, &sym)) {
if (*state & GUI_NODE_ACTIVE)
*state &= ~(gui_flags)GUI_NODE_ACTIVE;
else *state |= GUI_NODE_ACTIVE;
else *state |= (gui_flags)GUI_NODE_ACTIVE;
}
heading = (*state & GUI_NODE_ACTIVE) ? GUI_DOWN : GUI_RIGHT;
gui_triangle_from_direction(points, sym.x, sym.y, sym.w, sym.h, 0, 0, heading);
@ -4258,7 +4254,7 @@ gui_panel_tree_node(struct gui_tree *tree, enum gui_tree_node_symbol symbol,
if (gui_input_clicked(i, &label)) {
if (*state & GUI_NODE_SELECTED)
*state &= ~(gui_flags)GUI_NODE_SELECTED;
else *state |= GUI_NODE_SELECTED;
else *state |= (gui_flags)GUI_NODE_SELECTED;
}
{
@ -4295,7 +4291,7 @@ gui_panel_tree_node(struct gui_tree *tree, enum gui_tree_node_symbol symbol,
enum gui_tree_node_operation
gui_panel_tree_begin_node(struct gui_tree *tree, const char *title,
enum gui_tree_node_state *state)
gui_tree_node_state *state)
{
enum gui_tree_node_operation op;
op = gui_panel_tree_node(tree, GUI_TREE_NODE_TRIANGLE, title, 0, state);
@ -4308,7 +4304,7 @@ gui_panel_tree_begin_node(struct gui_tree *tree, const char *title,
enum gui_tree_node_operation
gui_panel_tree_begin_node_icon(struct gui_tree *tree, const char *title,
struct gui_image img, enum gui_tree_node_state *state)
struct gui_image img, gui_tree_node_state *state)
{
enum gui_tree_node_operation op;
op = gui_panel_tree_node(tree, GUI_TREE_NODE_TRIANGLE, title, &img, state);
@ -4321,12 +4317,12 @@ gui_panel_tree_begin_node_icon(struct gui_tree *tree, const char *title,
enum gui_tree_node_operation
gui_panel_tree_leaf(struct gui_tree *tree, const char *title,
enum gui_tree_node_state *state)
gui_tree_node_state *state)
{return gui_panel_tree_node(tree, GUI_TREE_NODE_BULLET, title, 0, state);}
enum gui_tree_node_operation
gui_panel_tree_leaf_icon(struct gui_tree *tree, const char *title, struct gui_image img,
enum gui_tree_node_state *state)
gui_tree_node_state *state)
{return gui_panel_tree_node(tree, GUI_TREE_NODE_BULLET, title, &img, state);}
void

15
gui.h
View File

@ -1743,10 +1743,9 @@ struct gui_panel_layout {
/* command draw call output command buffer */
};
enum gui_tree_node_state {
GUI_NODE_ACTIVE = 0x01,
GUI_NODE_SELECTED = 0x02
};
#define GUI_NODE_ACTIVE 0x01
#define GUI_NODE_SELECTED 0x02
typedef gui_flag gui_tree_node_state;
enum gui_tree_node_operation {
GUI_NODE_NOP,
@ -2211,7 +2210,7 @@ void gui_panel_tree_begin(struct gui_panel_layout*, struct gui_tree*,
- tree build up state structure
*/
enum gui_tree_node_operation gui_panel_tree_begin_node(struct gui_tree*, const char*,
enum gui_tree_node_state*);
gui_tree_node_state*);
/* this function begins a parent node
Input:
- title of the node
@ -2221,7 +2220,7 @@ enum gui_tree_node_operation gui_panel_tree_begin_node(struct gui_tree*, const c
*/
enum gui_tree_node_operation gui_panel_tree_begin_node_icon(struct gui_tree*,
const char*, struct gui_image,
enum gui_tree_node_state*);
gui_tree_node_state*);
/* this function begins a text icon parent node
Input:
- title of the node
@ -2234,7 +2233,7 @@ enum gui_tree_node_operation gui_panel_tree_begin_node_icon(struct gui_tree*,
void gui_panel_tree_end_node(struct gui_tree*);
/* this function ends a parent node */
enum gui_tree_node_operation gui_panel_tree_leaf(struct gui_tree*, const char*,
enum gui_tree_node_state*);
gui_tree_node_state*);
/* this function pushes a leaf node to the tree
Input:
- title of the node
@ -2244,7 +2243,7 @@ enum gui_tree_node_operation gui_panel_tree_leaf(struct gui_tree*, const char*,
*/
enum gui_tree_node_operation gui_panel_tree_leaf_icon(struct gui_tree*,
const char*, struct gui_image,
enum gui_tree_node_state*);
gui_tree_node_state*);
/* this function pushes a leaf icon node to the tree
Input:
- title of the node