removed shelf

This commit is contained in:
vurtun 2015-11-20 19:39:38 +01:00
parent 4cad83b52b
commit 297e271915
2 changed files with 1 additions and 217 deletions

170
zahnrad.c
View File

@ -5452,10 +5452,6 @@ zr_widget_spinner_float(struct zr_command_buffer *out, struct zr_rect r,
COLOR(SCROLLBAR_CURSOR_ACTIVE, 150, 150, 150, 255)\
COLOR(TABLE_LINES, 100, 100, 100, 255)\
COLOR(TAB_HEADER, 40, 40, 40, 255)\
COLOR(SHELF, 40, 40, 40, 255)\
COLOR(SHELF_TEXT, 150, 150, 150, 255)\
COLOR(SHELF_ACTIVE, 30, 30, 30, 255)\
COLOR(SHELF_ACTIVE_TEXT, 150, 150, 150, 255)\
COLOR(SCALER, 100, 100, 100, 255)
static const char *zr_style_color_names[] = {
@ -8061,172 +8057,6 @@ zr_group_end(struct zr_context *p, struct zr_context *g, struct zr_vec2 *scrollb
if (scrollbar)
*scrollbar = pan.offset;
}
/* -------------------------------------------------------------
*
* SHELF
*
* --------------------------------------------------------------*/
void
zr_shelf_begin(struct zr_context *parent, struct zr_context *shelf,
const char *tabs[], int size, int *active, struct zr_vec2 offset)
{
struct zr_style *config;
struct zr_command_buffer *out;
const struct zr_user_font *font;
struct zr_vec2 item_padding;
struct zr_vec2 panel_padding;
struct zr_rect bounds;
struct zr_rect *c;
struct zr_window panel;
float header_x, header_y;
float header_w, header_h;
ZR_ASSERT(parent);
ZR_ASSERT(tabs);
ZR_ASSERT(shelf);
ZR_ASSERT(active);
ZR_ASSERT(*active < size);
if (!parent || !shelf || !tabs || *active >= size)
return;
if (!parent->valid)
goto failed;
/* cache some config data */
config = parent->style;
out = parent->buffer;
font = &config->font;
item_padding = zr_style_property(config, ZR_PROPERTY_ITEM_PADDING);
panel_padding = zr_style_property(config, ZR_PROPERTY_PADDING);
/* allocate space for the shelf */
zr_panel_alloc_space(&bounds, parent);
zr_zero(shelf, sizeof(*shelf));
c = &parent->clip;
if (!ZR_INTERSECT(c->x, c->y, c->w, c->h, bounds.x, bounds.y, bounds.w, bounds.h))
goto failed;
/* calculate the header height for the tabs */
header_x = bounds.x;
header_y = bounds.y;
header_w = bounds.w;
header_h = panel_padding.y + 3 * item_padding.y + config->font.height;
{
/* basic button setup valid for every tab */
const struct zr_input *input;
struct zr_button_text button;
float item_width;
int i;
input = (parent->flags & ZR_WINDOW_ROM) ? 0 : parent->input;
item_width = (header_w - (float)size) / (float)size;
zr_fill_button(config, &button.base);
button.base.rounding = 0;
button.alignment = ZR_TEXT_CENTERED;
for (i = 0; i < size; i++) {
struct zr_rect b = {0,0,0,0};
/* calculate the needed space for the tab text */
zr_size text_width = font->width(font->userdata, font->height,
(const char*)tabs[i], zr_strsiz(tabs[i]));
text_width = text_width + (zr_size)(4 * item_padding.x);
/* calculate current tab button bounds */
b.y = header_y;
b.h = header_h;
b.x = header_x;
b.w = MIN(item_width, (float)text_width);
header_x += MIN(item_width, (float)text_width);
/* set different color for active or inactive tab */
if ((b.x + b.w) >= (bounds.x + bounds.w)) break;
if (*active != i) {
b.y += item_padding.y;
b.h -= item_padding.y;
button.base.normal = config->colors[ZR_COLOR_SHELF];
button.base.hover = config->colors[ZR_COLOR_SHELF];
button.base.active = config->colors[ZR_COLOR_SHELF];
button.normal = config->colors[ZR_COLOR_SHELF_TEXT];
button.hover = config->colors[ZR_COLOR_SHELF_TEXT];
button.active = config->colors[ZR_COLOR_SHELF_TEXT];
} else {
button.base.normal = config->colors[ZR_COLOR_SHELF_ACTIVE];
button.base.hover = config->colors[ZR_COLOR_SHELF_ACTIVE];
button.base.active = config->colors[ZR_COLOR_SHELF_ACTIVE];
button.normal = config->colors[ZR_COLOR_SHELF_ACTIVE_TEXT];
button.hover = config->colors[ZR_COLOR_SHELF_ACTIVE_TEXT];
button.active = config->colors[ZR_COLOR_SHELF_ACTIVE_TEXT];
}
if (zr_widget_button_text(out, b, tabs[i], ZR_BUTTON_DEFAULT, &button,
input, &config->font)) *active = i;
}
}
bounds.y += header_h;
bounds.h -= header_h;
{
/* setup fake window to create a context */
zr_flags flags;
flags = ZR_WINDOW_BORDER|ZR_WINDOW_TAB;
if (parent->flags & ZR_WINDOW_ROM)
flags |= ZR_WINDOW_ROM;
zr_window_init(&panel, zr_rect(bounds.x, bounds.y, bounds.w, bounds.h),
flags, 0, config, parent->input);
panel.buffer = *parent->buffer;
zr_begin(shelf, &panel);
*parent->buffer = panel.buffer;
shelf->buffer = parent->buffer;
shelf->offset = offset;
shelf->height -= header_h;
shelf->queue = parent->queue;
}
{
/* setup clip rect for the shelf panel */
struct zr_rect clip;
zr_unify(&clip, &parent->clip, shelf->clip.x, shelf->clip.y,
shelf->clip.x + shelf->clip.w, shelf->clip.y + shelf->clip.h);
zr_command_buffer_push_scissor(out, clip);
shelf->clip = clip;
}
return;
failed:
/* invalid panels still need correct data */
shelf->valid = zr_false;
shelf->style = parent->style;
shelf->buffer = parent->buffer;
shelf->input = parent->input;
shelf->queue = parent->queue;
}
void
zr_shelf_end(struct zr_context *p, struct zr_context *s, struct zr_vec2 *scrollbar)
{
struct zr_command_buffer *out;
struct zr_rect clip;
struct zr_window pan;
ZR_ASSERT(p);
ZR_ASSERT(s);
if (!p || !s) return;
if (!p->valid) return;
zr_zero(&pan, sizeof(pan));
out = p->buffer;
pan.bounds = s->bounds;
pan.flags = s->flags|ZR_WINDOW_TAB;
zr_unify(&clip, &p->clip, s->bounds.x, s->bounds.y,
s->bounds.x + s->bounds.w, s->bounds.y + s->bounds.h);
zr_command_buffer_push_scissor(out, clip);
zr_end(s, &pan);
zr_command_buffer_push_scissor(out, p->clip);
if (scrollbar)
*scrollbar = pan.offset;
}
/*
* -------------------------------------------------------------
*

View File

@ -1833,10 +1833,6 @@ enum zr_style_colors {
ZR_COLOR_SCROLLBAR_CURSOR_ACTIVE,
ZR_COLOR_TABLE_LINES,
ZR_COLOR_TAB_HEADER,
ZR_COLOR_SHELF,
ZR_COLOR_SHELF_TEXT,
ZR_COLOR_SHELF_ACTIVE,
ZR_COLOR_SHELF_ACTIVE_TEXT,
ZR_COLOR_SCALER,
ZR_COLOR_COUNT
};
@ -2030,7 +2026,6 @@ const char *zr_style_property_name(enum zr_style_properties);
Window Tree API -- Tree widget that allows to visualize and mofify a tree
Window Combobox API -- Combobox widget for collapsable popup content
Window Group API -- Create a subwindow inside a window which again can be filled with widgets
Window Shelf API -- Group window with tabs which can be filled with widget
Window Popup API -- Popup window with either non-blocking or blocking capabilities
Window Menu API -- Popup menus with currently one single depth
*/
@ -2060,7 +2055,7 @@ enum zr_window_flags {
ZR_WINDOW_ACTIVE = 0x10000,
/* INTERNAL ONLY!: marks the window as active, used by the window stack */
ZR_WINDOW_TAB = 0x20000,
/* INTERNAL ONLY!: Marks the window as subwindow of another window(Groups/Tabs/Shelf)*/
/* INTERNAL ONLY!: Marks the window as subwindow of another window(Groups/Tabs)*/
ZR_WINDOW_COMBO_MENU = 0x40000,
/* INTERNAL ONLY!: Marks the window as an combo box or menu */
ZR_WINDOW_REMOVE_ROM = 0x80000,
@ -3141,47 +3136,6 @@ void zr_group_end(struct zr_context*, struct zr_context*, struct zr_vec2 *scroll
Output:
- The from user input updated group scrollbar pixel offset
*/
/* --------------------------------------------------------------
*
* SHELF
*
* --------------------------------------------------------------
SHELF
A shelf extends the concept of a group as an window inside a window
with the possibility to decide which content should be drawn into the group.
This is achieved by tabs on the top of the group window with one selected
tab. The selected tab thereby defines which content should be drawn inside
the group window by an index it returns. So you just have to check the returned
index and depending on it draw the wanted content.
shelf API
zr_shelf_begin -- begins a shelf with a number of selectable tabs
zr_shelf_end -- ends a previously started shelf build up process
*/
void zr_shelf_begin(struct zr_context*, struct zr_context*,
const char *tabs[], int size,
int *active, struct zr_vec2 offset);
/* this function adds a shelf child window into the parent window
IMPORTANT: You need to set the height of the shelf with zr_row_layout
Input:
- all possible selectible tabs of the shelf with names as a string array
- number of seletectible tabs
- current active tab array index
- scrollbar pixel offset for the shelf
Output:
- group layout to fill with widgets
- the from user input updated current shelf tab index
*/
void zr_shelf_end(struct zr_context *p, struct zr_context *s, struct zr_vec2 *scrollbar);
/* this function finishes the previously started shelf layout
Input:
- previously started group layout
Output:
- The from user input updated shelf scrollbar pixel offset
*/
/* --------------------------------------------------------------
*
* POPUP