fixed text image button + fixed internal font baker alignment

This commit is contained in:
vurtun 2015-10-21 18:43:31 +02:00
parent d050b444ef
commit 083152c6b9
3 changed files with 47 additions and 40 deletions

View File

@ -567,6 +567,7 @@ widget_panel(struct zr_context *panel, struct state *demo)
zr_label(panel, "text right", ZR_TEXT_RIGHT);
{
/* Tooltip */
struct zr_rect bounds;
const struct zr_input *in = zr_input(panel);
zr_layout_peek(&bounds, panel);
@ -614,10 +615,10 @@ widget_panel(struct zr_context *panel, struct state *demo)
zr_tiled_begin_local(&tiled, fmt, 250, 150);
if (!demo->scaleable) {
zr_tiled_slot(&tiled, ZR_SLOT_LEFT, 100, ZR_SLOT_VERTICAL, 4);
zr_tiled_slot(&tiled, ZR_SLOT_RIGHT, 150, ZR_SLOT_VERTICAL, 4);
zr_tiled_slot(&tiled, ZR_SLOT_RIGHT, 150, ZR_SLOT_VERTICAL, 4);
} else {
zr_tiled_slot(&tiled, ZR_SLOT_LEFT, 0.50, ZR_SLOT_VERTICAL, 4);
zr_tiled_slot(&tiled, ZR_SLOT_RIGHT, 0.50, ZR_SLOT_VERTICAL, 4);
zr_tiled_slot(&tiled, ZR_SLOT_LEFT, 0.50, ZR_SLOT_VERTICAL, 4);
zr_tiled_slot(&tiled, ZR_SLOT_RIGHT, 0.50, ZR_SLOT_VERTICAL, 4);
}
zr_tiled_end(&tiled);
@ -885,7 +886,7 @@ run_demo(struct demo_gui *gui)
/* popup panel */
if (state->popup)
{
zr_popup_begin(&layout, &tab, ZR_POPUP_STATIC, 0, zr_rect(20, 100, 220, 150), zr_vec2(0,0));
zr_popup_begin(&layout, &tab, ZR_POPUP_STATIC, 0, zr_rect(20, 100, 220, 180), zr_vec2(0,0));
{
if (zr_header(&tab, "Popup", ZR_CLOSEABLE, ZR_CLOSEABLE, ZR_HEADER_LEFT)) {
zr_popup_close(&tab);

View File

@ -3062,7 +3062,7 @@ zr_font_bake(void *image_memory, zr_size width, zr_size height,
return;
/* second font pass: render glyphes */
baker = (struct zr_font_baker*)temp;
baker = (struct zr_font_baker*)ZR_ALIGN_PTR(temp, zr_baker_align);
zr_zero(image_memory, width * height);
baker->spc.pixels = (unsigned char*)image_memory;
baker->spc.height = (zr_int)height;
@ -3926,9 +3926,9 @@ zr_widget_button_text_symbol(struct zr_command_buffer *out, struct zr_rect r,
zr_bool
zr_widget_button_text_image(struct zr_command_buffer *out, struct zr_rect r,
struct zr_image img, const char* text, enum zr_text_align align,
enum zr_button_behavior behavior, const struct zr_button_text *button,
const struct zr_user_font *f, const struct zr_input *i)
struct zr_image img, const char* text, enum zr_button_behavior behavior,
const struct zr_button_text *button, const struct zr_user_font *f,
const struct zr_input *i)
{
zr_bool pressed;
struct zr_rect icon;
@ -3940,7 +3940,7 @@ zr_widget_button_text_image(struct zr_command_buffer *out, struct zr_rect r,
pressed = zr_widget_button_text(out, r, text, behavior, button, i, f);
icon.y = r.y + button->base.padding.y;
icon.w = icon.h = r.h - 2 * button->base.padding.y;
if (align == ZR_TEXT_LEFT) {
if (button->alignment == ZR_TEXT_LEFT) {
icon.x = (r.x + r.w) - (2 * button->base.padding.x + icon.w);
icon.x = MAX(icon.x, 0);
} else icon.x = r.x + 2 * button->base.padding.x;
@ -4730,7 +4730,7 @@ zr_widget_spinner(struct zr_command_buffer *out, struct zr_rect r,
/*
* ==============================================================
*
* Config
* Style
*
* ===============================================================
*/
@ -4948,7 +4948,7 @@ zr_tiled_begin_local(struct zr_tiled_layout *layout, enum zr_layout_format fmt,
void
zr_tiled_begin(struct zr_tiled_layout *layout, enum zr_layout_format fmt,
struct zr_rect bounds, struct zr_vec2 spacing)
struct zr_rect bounds, struct zr_vec2 spacing, zr_float scaler_width)
{
ZR_ASSERT(layout);
if (!layout) return;
@ -4956,6 +4956,21 @@ zr_tiled_begin(struct zr_tiled_layout *layout, enum zr_layout_format fmt,
layout->fmt = fmt;
layout->bounds = bounds;
layout->spacing = spacing;
layout->scaler_width = scaler_width;
}
void
zr_tiled_begin_inside(struct zr_tiled_layout *parent, struct zr_tiled_layout *child,
enum zr_layout_format fmt, enum zr_tiled_layout_slot_index slot, zr_uint index)
{
struct zr_rect bounds;
ZR_ASSERT(parent);
ZR_ASSERT(child);
zr_tiled_bounds(&bounds, parent, slot, index);
child->fmt = fmt;
child->bounds = bounds;
child->spacing = parent->spacing;
child->scaler_width = parent->scaler_width;
}
void
@ -5024,19 +5039,6 @@ zr_tiled_bounds(struct zr_rect *bounds, const struct zr_tiled_layout *layout,
}
}
void
zr_tiled_load(struct zr_tiled_layout *parent, struct zr_tiled_layout *child,
enum zr_layout_format fmt, enum zr_tiled_layout_slot_index slot, zr_uint index)
{
struct zr_rect bounds;
ZR_ASSERT(parent);
ZR_ASSERT(child);
zr_tiled_bounds(&bounds, parent, slot, index);
child->fmt = fmt;
child->bounds = bounds;
child->spacing = parent->spacing;
}
void
zr_tiled_end(struct zr_tiled_layout *layout)
{
@ -6851,10 +6853,11 @@ zr_button_text_image(struct zr_context *layout, struct zr_image img,
i = (state == ZR_WIDGET_ROM || layout->flags & ZR_WINDOW_ROM) ? 0 : layout->input;
config = layout->style;
button.alignment = align;
button.normal = config->colors[ZR_COLOR_TEXT];
button.hover = config->colors[ZR_COLOR_TEXT_HOVERING];
button.active = config->colors[ZR_COLOR_TEXT_ACTIVE];
return zr_widget_button_text_image(layout->buffer, bounds, img, text, align,
return zr_widget_button_text_image(layout->buffer, bounds, img, text,
behavior, &button, &config->font, i);
}
@ -8040,7 +8043,8 @@ zr_contextual_button_icon(struct zr_context *layout, struct zr_image img,
button.normal = config->colors[ZR_COLOR_TEXT];
button.hover = config->colors[ZR_COLOR_TEXT_HOVERING];
button.active = config->colors[ZR_COLOR_TEXT_ACTIVE];
return zr_widget_button_text_image(layout->buffer, bounds, img, text, align,
button.alignment = align;
return zr_widget_button_text_image(layout->buffer, bounds, img, text,
behavior, &button, &config->font, i);
}

View File

@ -2105,8 +2105,7 @@ zr_bool zr_widget_button_text_symbol(struct zr_command_buffer*, struct zr_rect,
- returns zr_true if the button was pressed zr_false otherwise
*/
zr_bool zr_widget_button_text_image(struct zr_command_buffer*, struct zr_rect,
struct zr_image, const char*, enum zr_text_align,
enum zr_button_behavior,
struct zr_image, const char*, enum zr_button_behavior,
const struct zr_button_text*,
const struct zr_user_font*, const struct zr_input*);
/* this function executes a button widget with text and an icon
@ -2589,6 +2588,8 @@ struct zr_tiled_slot {
};
struct zr_tiled_layout {
zr_float scaler_width;
/* widht of the scaling line between slots */
struct zr_tiled_slot slots[ZR_SLOT_MAX];
/* tiled layout slots */
enum zr_layout_format fmt;
@ -2599,7 +2600,8 @@ struct zr_tiled_layout {
};
void zr_tiled_begin(struct zr_tiled_layout*, enum zr_layout_format,
struct zr_rect bounds, struct zr_vec2 spacing);
struct zr_rect bounds, struct zr_vec2 spacing,
zr_float scaler_width);
/* this functions begins the definitions of a tiled layout
Input:
- layout format with either dynamic ratio based or fixed pixel based slots
@ -2616,6 +2618,17 @@ void zr_tiled_begin_local(struct zr_tiled_layout*, enum zr_layout_format,
- pixel width of the tiled layout space (IMPORTANT: not used for dynamic tiled layouts)
- pixel height of the tiled layout space
*/
void zr_tiled_begin_inside(struct zr_tiled_layout *parent, struct zr_tiled_layout *child,
enum zr_layout_format fmt, enum zr_tiled_layout_slot_index slot,
zr_uint index);
/* this functions load a tiled layout from another tiled layout slot
Input:
- slot filling format with either horizontal or vertical filling
- slot identifier
- index of the widget inside the slot
Output:
- loaded child tiled layout inside the parent tiled layout
*/
void zr_tiled_slot(struct zr_tiled_layout *layout,
enum zr_tiled_layout_slot_index, zr_float ratio,
enum zr_tiled_slot_format, zr_uint widget_count);
@ -2646,17 +2659,6 @@ void zr_tiled_bounds(struct zr_rect*, const struct zr_tiled_layout*,
Output:
- rectangle with position and size of the slot entry
*/
void zr_tiled_load(struct zr_tiled_layout *parent, struct zr_tiled_layout *child,
enum zr_layout_format fmt, enum zr_tiled_layout_slot_index slot,
zr_uint index);
/* this functions load a tiled layout from another tiled layout slot
Input:
- slot filling format with either horizontal or vertical filling
- slot identifier
- index of the widget inside the slot
Output:
- loaded child tiled layout inside the parent tiled layout
*/
/*
* ==============================================================
*