From d32d2f9ea3fa2f18bd37bb78bc8a48e5024c3743 Mon Sep 17 00:00:00 2001 From: vurtun Date: Tue, 19 Jan 2016 15:25:08 +0100 Subject: [PATCH] loose 80 character column width limit --- zahnrad.c | 415 ++++++++++++++++++++++++++++++++++-------------------- zahnrad.h | 260 +++++++++++++++++++--------------- 2 files changed, 413 insertions(+), 262 deletions(-) diff --git a/zahnrad.c b/zahnrad.c index 8d8fa4c..11bb053 100644 --- a/zahnrad.c +++ b/zahnrad.c @@ -212,7 +212,8 @@ struct zr_pool { #define ZR_LEN(a) (sizeof(a)/sizeof(a)[0]) #define ZR_ABS(a) (((a) < 0) ? -(a) : (a)) #define ZR_BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) -#define ZR_INBOX(px, py, x, y, w, h) (ZR_BETWEEN(px,x,x+w) && ZR_BETWEEN(py,y,y+h)) +#define ZR_INBOX(px, py, x, y, w, h)\ + (ZR_BETWEEN(px,x,x+w) && ZR_BETWEEN(py,y,y+h)) #define ZR_INTERSECT(x0, y0, w0, h0, x1, y1, w1, h1) \ (!(((x1 > (x0 + w0)) || ((x1 + w1) < x0) || (y1 > (y0 + h0)) || (y1 + h1) < y0))) #define ZR_CONTAINS(x, y, w, h, bx, by, bw, bh)\ @@ -278,11 +279,11 @@ typedef int zr__check_byte[(sizeof(zr_byte) == 1) ? 1 : -1]; * * =============================================================== */ -/* Since zahnrad is supposed to work on all systems providing floating point math - without any dependencies I also had to implement my own math functions for - sqrt, sin and cos. Since the actual highly accurate implementations for the standard - library functions are quite complex and I do not need high precision for my use cases - I use approximations. +/* Since zahnrad is supposed to work on all systems providing floating point + math without any dependencies I also had to implement my own math functions + for sqrt, sin and cos. Since the actual highly accurate implementations for + the standard library functions are quite complex and I do not need high + precision for my use cases I use approximations. Sqrt ---- @@ -329,7 +330,7 @@ zr_sin(float x) static const float a5 = +2.08026600266304389e-2f; static const float a6 = -3.03996055049204407e-3f; static const float a7 = +1.38235642404333740e-4f; - return a0 + x * (a1 + x * (a2 + x * (a3 + x * (a4 + x * (a5 + x *(a6 + x * a7)))))); + return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*a7)))))); } static float @@ -343,7 +344,7 @@ zr_cos(float x) static const float a5 = -1.86637164165180873e-2f; static const float a6 = +9.90140908664079833e-4f; static const float a7 = -5.23022132118824778e-14f; - return a0 + x * (a1 + x * (a2 + x * (a3 + x * (a4 + x * (a5 + x *(a6 + x * a7)))))); + return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*a7)))))); } static zr_uint @@ -438,7 +439,8 @@ zr_memcopy(void *dst0, const void *src0, zr_size length) TLOOP1(*dst++ = *src++); } t = length / wsize; - TLOOP(*(word*)(void*)dst = *(const word*)(const void*)src; src += wsize; dst += wsize); + TLOOP(*(word*)(void*)dst = *(const word*)(const void*)src; + src += wsize; dst += wsize); t = length & wmask; TLOOP(*dst++ = *src++); } else { @@ -454,7 +456,8 @@ zr_memcopy(void *dst0, const void *src0, zr_size length) TLOOP1(*--dst = *--src); } t = length / wsize; - TLOOP(src -= wsize; dst -= wsize; *(word*)(void*)dst = *(const word*)(const void*)src); + TLOOP(src -= wsize; dst -= wsize; + *(word*)(void*)dst = *(const word*)(const void*)src); t = length & wmask; TLOOP(*--dst = *--src); } @@ -704,7 +707,7 @@ zr_ftos(char *s, float n) static zr_hash zr_murmur_hash(const void * key, int len, zr_hash seed) { - /* 32-Bit MurmurHash3 from: https://code.google.com/p/smhasher/wiki/MurmurHash3 */ + /* 32-Bit MurmurHash3: https://code.google.com/p/smhasher/wiki/MurmurHash3*/ #define ZR_ROTL(x,r) ((x) << (r) | ((x) >> (32 - r))) union {const zr_uint *i; const zr_byte *b;} conv = {0}; const zr_byte *data = (const zr_byte*)key; @@ -1327,9 +1330,9 @@ zr_use_font_glyph_clamp(const struct zr_user_font *font, const char *text, } static zr_size -zr_user_font_glyphs_fitting_in_space(const struct zr_user_font *font, const char *text, - zr_size text_len, float space, zr_size *row_len, zr_size *glyphs, - float *text_width, int has_newline) +zr_user_font_glyphs_fitting_in_space(const struct zr_user_font *font, + const char *text, zr_size text_len, float space, zr_size *row_len, + zr_size *glyphs, float *text_width, int has_newline) { zr_size glyph_len; float width = 0; @@ -1380,7 +1383,8 @@ zr_user_font_glyphs_fitting_in_space(const struct zr_user_font *font, const char * * ===============================================================*/ void -zr_buffer_init(struct zr_buffer *b, const struct zr_allocator *a, zr_size initial_size) +zr_buffer_init(struct zr_buffer *b, const struct zr_allocator *a, + zr_size initial_size) { ZR_ASSERT(b); ZR_ASSERT(a); @@ -1502,7 +1506,8 @@ zr_buffer_alloc(struct zr_buffer *b, enum zr_buffer_allocation_type type, /* buffer is full so allocate bigger buffer if dynamic */ ZR_ASSERT(b->type == ZR_BUFFER_DYNAMIC); ZR_ASSERT(b->pool.alloc && b->pool.free); - if (b->type != ZR_BUFFER_DYNAMIC || !b->pool.alloc || !b->pool.free) return 0; + if (b->type != ZR_BUFFER_DYNAMIC || !b->pool.alloc || !b->pool.free) + return 0; cap = (zr_size)((float)b->memory.size * b->grow_factor); cap = MAX(cap, zr_round_up_pow2((zr_uint)(b->allocated + size))); @@ -1654,7 +1659,7 @@ zr_command_buffer_push(struct zr_command_buffer* b, ZR_ASSERT(b->base); if (!b) return 0; - cmd = (struct zr_command*)zr_buffer_alloc(b->base, ZR_BUFFER_FRONT, size, align); + cmd = (struct zr_command*)zr_buffer_alloc(b->base,ZR_BUFFER_FRONT,size,align); if (!cmd) return 0; /* make sure the offset to the next command is aligned */ @@ -1864,7 +1869,8 @@ zr_draw_text(struct zr_command_buffer *b, struct zr_rect r, if (text_width > r.w){ float txt_width = (float)text_width; zr_size glyphs = 0; - length = zr_use_font_glyph_clamp(font, string, length, r.w, &glyphs, &txt_width); + length = zr_use_font_glyph_clamp(font, string, length, + r.w, &glyphs, &txt_width); } if (!length) return; @@ -1946,7 +1952,8 @@ zr_canvas_alloc_path(struct zr_canvas *list, zr_size count) static const zr_size point_align = ZR_ALIGNOF(struct zr_vec2); static const zr_size point_size = sizeof(struct zr_vec2); points = (struct zr_vec2*) - zr_buffer_alloc(list->buffer, ZR_BUFFER_FRONT, point_size * count, point_align); + zr_buffer_alloc(list->buffer, ZR_BUFFER_FRONT, + point_size * count, point_align); if (!points) return 0; if (!list->path_offset) { @@ -2049,7 +2056,7 @@ zr_canvas_alloc_vertexes(struct zr_canvas *list, zr_size count) if (!list) return 0; vtx = (struct zr_draw_vertex*) - zr_buffer_alloc(list->vertexes, ZR_BUFFER_FRONT, vtx_size * count, vtx_align); + zr_buffer_alloc(list->vertexes, ZR_BUFFER_FRONT, vtx_size*count, vtx_align); if (!vtx) return 0; list->vertex_count += (unsigned int)count; return vtx; @@ -2066,7 +2073,7 @@ zr_canvas_alloc_elements(struct zr_canvas *list, zr_size count) if (!list) return 0; ids = (zr_draw_index*) - zr_buffer_alloc(list->elements, ZR_BUFFER_FRONT, elem_size * count, elem_align); + zr_buffer_alloc(list->elements, ZR_BUFFER_FRONT, elem_size*count, elem_align); if (!ids) return 0; cmd = zr_canvas_command_last(list); list->element_count += (unsigned int)count; @@ -2315,7 +2322,8 @@ zr_canvas_add_poly_line(struct zr_canvas *list, struct zr_vec2 *points, static void zr_canvas_add_poly_convex(struct zr_canvas *list, struct zr_vec2 *points, - const unsigned int points_count, struct zr_color color, enum zr_anti_aliasing aliasing) + const unsigned int points_count, struct zr_color color, + enum zr_anti_aliasing aliasing) { static const zr_size pnt_align = ZR_ALIGNOF(struct zr_vec2); static const zr_size pnt_size = sizeof(struct zr_vec2); @@ -2623,7 +2631,8 @@ zr_canvas_add_curve(struct zr_canvas *list, struct zr_vec2 p0, static void zr_canvas_push_rect_uv(struct zr_canvas *list, struct zr_vec2 a, - struct zr_vec2 c, struct zr_vec2 uva, struct zr_vec2 uvc, struct zr_color color) + struct zr_vec2 c, struct zr_vec2 uva, struct zr_vec2 uvc, + struct zr_color color) { zr_draw_vertex_color col = zr_color32(color); struct zr_draw_vertex *vtx; @@ -2709,7 +2718,8 @@ zr_canvas_add_text(struct zr_canvas *list, const struct zr_user_font *font, /* query currently drawn glyph information */ next_glyph_len = zr_utf_decode(text + text_len, &next, len - text_len); - font->query(font->userdata, font->height, &g, unicode, (next == ZR_UTF_INVALID) ? '\0' : next); + font->query(font->userdata, font->height, &g, unicode, + (next == ZR_UTF_INVALID) ? '\0' : next); /* calculate and draw glyph drawing rectangle and image */ gx = x + g.offset.x * scale; @@ -2754,8 +2764,9 @@ zr_canvas_load(struct zr_canvas *list, struct zr_context *queue, case ZR_COMMAND_CURVE: { const struct zr_command_curve *q = zr_command(curve, cmd); zr_canvas_add_curve(list, zr_vec2(q->begin.x, q->begin.y), - zr_vec2(q->ctrl[0].x, q->ctrl[0].y), zr_vec2(q->ctrl[1].x, q->ctrl[1].y), - zr_vec2(q->end.x, q->end.y), q->color, curve_segments, line_thickness); + zr_vec2(q->ctrl[0].x, q->ctrl[0].y), zr_vec2(q->ctrl[1].x, + q->ctrl[1].y), zr_vec2(q->end.x, q->end.y), q->color, + curve_segments, line_thickness); } break; case ZR_COMMAND_RECT: { const struct zr_command_rect *r = zr_command(rect, cmd); @@ -2765,7 +2776,8 @@ zr_canvas_load(struct zr_canvas *list, struct zr_context *queue, case ZR_COMMAND_CIRCLE: { const struct zr_command_circle *c = zr_command(circle, cmd); zr_canvas_add_circle(list, zr_vec2((float)c->x + (float)c->w/2, - (float)c->y + (float)c->h/2), (float)c->w/2, c->color, curve_segments); + (float)c->y + (float)c->h/2), (float)c->w/2, c->color, + curve_segments); } break; case ZR_COMMAND_ARC: { const struct zr_command_arc *c = zr_command(arc, cmd); @@ -3077,7 +3089,7 @@ zr_font_bake_pack(zr_size *image_memory, int *width, int *height, int input_i = 0; int range_n = 0, rect_n = 0, char_n = 0; - /* pack custom user data first so it will be in the upper left corner */ + /* pack custom user data first so it will be in the upper left corner*/ if (custom) { stbrp_rect custom_space; zr_zero(&custom_space, sizeof(custom_space)); @@ -3221,7 +3233,8 @@ zr_font_bake(void *image_memory, int width, int height, /* fill own glyph type with data */ glyph = &glyphs[dst_font->glyph_offset + (unsigned int)char_idx]; glyph->codepoint = codepoint; - glyph->x0 = q.x0; glyph->y0 = q.y0; glyph->x1 = q.x1; glyph->y1 = q.y1; + glyph->x0 = q.x0; glyph->y0 = q.y0; + glyph->x1 = q.x1; glyph->y1 = q.y1; glyph->y0 += (dst_font->ascent + 0.5f); glyph->y1 += (dst_font->ascent + 0.5f); @@ -3371,8 +3384,8 @@ zr_font_text_width(zr_handle handle, float height, const char *text, zr_size len #if ZR_COMPILE_WITH_VERTEX_BUFFER static void -zr_font_query_font_glyph(zr_handle handle, float height, struct zr_user_font_glyph *glyph, - zr_rune codepoint, zr_rune next_codepoint) +zr_font_query_font_glyph(zr_handle handle, float height, + struct zr_user_font_glyph *glyph, zr_rune codepoint, zr_rune next_codepoint) { float scale; const struct zr_font_glyph *g; @@ -3440,7 +3453,8 @@ zr_edit_buffer_insert(struct zr_buffer *buffer, zr_size pos, zr_size copylen; ZR_ASSERT(buffer); if (!buffer || !str || !len || pos > buffer->allocated) return 0; - if (buffer->allocated + len >= buffer->memory.size && buffer->type == ZR_BUFFER_FIXED) return 0; + if ((buffer->allocated + len >= buffer->memory.size) && + (buffer->type == ZR_BUFFER_FIXED)) return 0; copylen = buffer->allocated - pos; if (!copylen) { @@ -3857,7 +3871,8 @@ zr_widget_text_wrap(struct zr_command_buffer *o, struct zr_rect b, zr_widget_text(o, line, &string[done], fitting, &text, ZR_TEXT_LEFT, f); done += fitting; line.y += f->height + 2 * t->padding.y; - fitting = zr_use_font_glyph_clamp(f, &string[done], len-done, line.w, &glyphs, &width); + fitting = zr_use_font_glyph_clamp(f, &string[done], len - done, + line.w, &glyphs, &width); } } @@ -4295,7 +4310,8 @@ zr_toggle_draw(struct zr_command_buffer *out, text.padding.y = 0; text.background = toggle->cursor; text.text = toggle->font; - zr_widget_text(out, inner, string, zr_strsiz(string), &text, ZR_TEXT_LEFT, font); + zr_widget_text(out, inner, string, zr_strsiz(string), + &text, ZR_TEXT_LEFT, font); } } @@ -4348,7 +4364,8 @@ zr_slider_behavior(enum zr_widget_status *state, struct zr_rect *cursor, { int inslider, incursor; inslider = in && zr_input_is_mouse_hovering_rect(in, slider); - incursor = in && zr_input_has_mouse_click_down_in_rect(in, ZR_BUTTON_LEFT, slider, zr_true); + incursor = in && zr_input_has_mouse_click_down_in_rect(in, ZR_BUTTON_LEFT, + slider, zr_true); *state = (inslider) ? ZR_HOVERED: ZR_INACTIVE; if (in && inslider && incursor) @@ -4359,10 +4376,12 @@ zr_slider_behavior(enum zr_widget_status *state, struct zr_rect *cursor, /* only update value if the next slider step is reached */ *state = ZR_ACTIVE; if (ZR_ABS(d) >= pxstep) { + float ratio = 0; const float steps = (float)((int)(ZR_ABS(d) / pxstep)); - slider_value += (d > 0) ? (slider_step * steps) : -(slider_step * steps); + slider_value += (d > 0) ? (slider_step*steps) : -(slider_step*steps); slider_value = CLAMP(slider_min, slider_value, slider_max); - cursor->x = slider.x + (cursor->w * ((slider_value - slider_min) / slider_step)); + ratio = (slider_value - slider_min)/slider_step; + cursor->x = slider.x + (cursor->w * ratio); } } return slider_value; @@ -4448,7 +4467,8 @@ zr_do_slider(enum zr_widget_status *state, slider_value = zr_slider_behavior(state, &cursor, in, s, slider, slider_min, slider_max, slider_value, step, slider_steps); - zr_slider_draw(out, *state, s, bar, cursor, slider_min, slider_max, slider_value); + zr_slider_draw(out, *state, s, bar, cursor, slider_min, + slider_max, slider_value); return slider_value; } @@ -4577,7 +4597,8 @@ zr_scrollbar_behavior(enum zr_widget_status *state, struct zr_input *in, scroll_offset = CLAMP(0, scroll_offset + delta, target - scroll.w); in->mouse.buttons[ZR_BUTTON_LEFT].clicked_pos.x += in->mouse.delta.x; } - } else if (s->has_scrolling && ((in->mouse.scroll_delta<0) || (in->mouse.scroll_delta>0))){ + } else if (s->has_scrolling && ((in->mouse.scroll_delta<0) || + (in->mouse.scroll_delta>0))) { /* update cursor by mouse scrolling */ scroll_offset = scroll_offset + scroll_step * (-in->mouse.scroll_delta); if (o == ZR_VERTICAL) @@ -4639,6 +4660,7 @@ zr_do_scrollbarv(enum zr_widget_status *state, cursor.w = scroll.w - 2; cursor.x = scroll.x + 1; + /* draw scrollbar */ scroll_offset = zr_scrollbar_behavior(state, i, s, scroll, cursor, scroll_offset, target, scroll_step, ZR_VERTICAL); scroll_off = scroll_offset / target; @@ -4679,6 +4701,7 @@ zr_do_scrollbarh(enum zr_widget_status *state, cursor.h = scroll.h - 2; cursor.y = scroll.y + 1; + /* draw scrollbar */ scroll_offset = zr_scrollbar_behavior(state, i, s, scroll, cursor, scroll_offset, target, scroll_step, ZR_HORIZONTAL); scroll_off = scroll_offset / target; @@ -4707,7 +4730,8 @@ struct zr_edit { }; static void -zr_edit_box_handle_input(struct zr_edit_box *box, const struct zr_input *in, int has_special) +zr_edit_box_handle_input(struct zr_edit_box *box, const struct zr_input *in, + int has_special) { char *buffer = zr_edit_box_get(box); zr_size len = zr_edit_box_len_char(box); @@ -4808,7 +4832,7 @@ zr_widget_edit_field(struct zr_command_buffer *out, struct zr_rect r, { /* text management */ struct zr_rect label; - zr_size cursor_w = font->width(font->userdata,font->height,(const char*)"X", 1); + zr_size cursor_w = font->width(font->userdata,font->height,"X", 1); zr_size text_len = len; zr_size glyph_off = 0; zr_size glyph_cnt = 0; @@ -4831,7 +4855,6 @@ zr_widget_edit_field(struct zr_command_buffer *out, struct zr_rect r, offset += frame_len; frame_len = zr_user_font_glyphs_fitting_in_space(font, &buffer[offset], text_len, space, &row_len, &glyphs, &text_width, 0); - glyph_off += glyphs; if (glyph_off > box->cursor || !frame_len) break; text_len -= frame_len; @@ -5011,7 +5034,7 @@ zr_widget_edit_box(struct zr_command_buffer *out, struct zr_rect r, if (!box->active || (!prev_state && box->active)) { /* make sure edit box points to the end of the buffer if not active */ if (total_rows > visible_rows) - box->scrollbar = (total_rows - visible_rows) * row_height; + box->scrollbar = (float)((total_rows - visible_rows) * row_height); } if ((in && in->keyboard.text_len && total_rows >= visible_rows && box->active) || @@ -5194,7 +5217,9 @@ zr_widget_edit_box(struct zr_command_buffer *out, struct zr_rect r, if (!row_off || !row_len) break; /* draw either unselected or selected row */ - if (glyph_off <= begin && glyph_off + glyphs >= begin && glyph_off + glyphs <= end+1 && box->active) { + if (glyph_off <= begin && glyph_off + glyphs >= begin && + glyph_off + glyphs <= end+1 && box->active) + { /* first case with selection beginning in current row */ zr_size l = 0, sel_begin, sel_len; zr_size unselected_text_width; @@ -5261,8 +5286,10 @@ zr_widget_edit_box(struct zr_command_buffer *out, struct zr_rect r, font, field->background, field->text); label.x -= (float)selected_text_width; label.w += (float)(selected_text_width); - } else if (glyph_off <= begin && glyph_off + glyphs >= begin && box->active && - glyph_off <= end && glyph_off + glyphs > end) { + } + else if (glyph_off <= begin && glyph_off + glyphs >= begin && + box->active && glyph_off <= end && glyph_off + glyphs > end) + { /* fourth case with selection beginning and ending in current row */ zr_size l = 0; zr_size cur_text_width; @@ -5283,12 +5310,15 @@ zr_widget_edit_box(struct zr_command_buffer *out, struct zr_rect r, sel_end = sel_end - offset; sel_len = (sel_end - sel_begin); if (!sel_len) { - sel_len = zr_utf_decode(&buffer[offset+sel_begin], &unicode, row_len); - sel_end += zr_utf_decode(&buffer[offset+sel_end], &unicode, row_len); + sel_len = zr_utf_decode(&buffer[offset+sel_begin], + &unicode, row_len); + sel_end += zr_utf_decode(&buffer[offset+sel_end], + &unicode, row_len); } /* draw beginning unselected text part */ - cur_text_width = font->width(font->userdata, font->height, &buffer[offset], sel_begin); + cur_text_width = font->width(font->userdata, font->height, + &buffer[offset], sel_begin); zr_draw_text(out, label, &buffer[offset], sel_begin, font, field->background, field->text); @@ -5297,13 +5327,15 @@ zr_widget_edit_box(struct zr_command_buffer *out, struct zr_rect r, label.w -= (float)(cur_text_width); zr_draw_text(out, label, &buffer[offset+sel_begin], sel_len, font, field->text, field->background); - cur_text_width = font->width(font->userdata, font->height, &buffer[offset+sel_begin], sel_len); + cur_text_width = font->width(font->userdata, font->height, + &buffer[offset+sel_begin], sel_len); /* draw ending unselected text part */ label.x += (float)cur_text_width; label.w -= (float)(cur_text_width); zr_draw_text(out , label, &buffer[offset+sel_end], - row_len - (sel_len + sel_begin), font, field->background, field->text); + row_len - (sel_len + sel_begin), font, + field->background, field->text); label.x = (float)label_x; label.w = (float)label_w; } else { @@ -5435,8 +5467,8 @@ zr_drag_behavior(enum zr_widget_status *state, const struct zr_input *in, struct zr_rect drag, float min, float val, float max, float inc_per_pixel) { int left_mouse_down = in && in->mouse.buttons[ZR_BUTTON_LEFT].down; - int left_mouse_click_in_cursor = in && zr_input_has_mouse_click_down_in_rect(in, - ZR_BUTTON_LEFT, drag, zr_true); + int left_mouse_click_in_cursor = in && + zr_input_has_mouse_click_down_in_rect(in, ZR_BUTTON_LEFT, drag, zr_true); *state = ZR_INACTIVE; if (zr_input_is_mouse_hovering_rect(in, drag)) @@ -5489,7 +5521,8 @@ zr_property_draw(struct zr_command_buffer *out, struct zr_symbol sym; /* background */ zr_draw_rect(out, property, p->rounding, p->border); - zr_draw_rect(out, zr_shrink_rect(property,p->border_size), p->rounding, p->normal); + zr_draw_rect(out, zr_shrink_rect(property, p->border_size), + p->rounding, p->normal); /* buttons */ sym.type = ZR_SYMBOL_TRIANGLE_LEFT; @@ -5521,8 +5554,8 @@ zr_do_property(enum zr_widget_status *ws, float property_min; float property_max; float property_value; - char *dst = 0; zr_size *length; + char *dst = 0; struct zr_edit field; struct zr_rect left; @@ -5536,13 +5569,13 @@ zr_do_property(enum zr_widget_status *ws, property_min = MIN(min, max); property_value = CLAMP(property_min, val, property_max); - /* left button */ + /* left decrement button */ left.h = f->height/2; left.w = left.h; left.x = property.x + p->border_size + p->padding.x; left.y = property.y + p->border_size + property.h/2.0f - left.h/2; - /* label */ + /* text label */ name_len = zr_strsiz(name); size = f->width(f->userdata, f->height, name, name_len); label.x = left.x + left.w + p->padding.x; @@ -5550,7 +5583,7 @@ zr_do_property(enum zr_widget_status *ws, label.y = property.y + p->border_size; label.h = property.h - 2 * p->border_size; - /* right button */ + /* right increment button */ right.y = left.y; right.w = left.w; right.h = left.h; @@ -5581,10 +5614,12 @@ zr_do_property(enum zr_widget_status *ws, empty.h = property.h; old = (*state == ZR_PROPERTY_EDIT); - property_value = zr_property_behavior(ws, in, property, left, right, label, edit, empty, - state, property_min, property_value, property_max, step, inc_per_pixel); + property_value = zr_property_behavior(ws, in, property, left, right, label, + edit, empty, state, property_min, property_value, + property_max, step, inc_per_pixel); zr_property_draw(out, p, property, left, right, label, name, name_len, f); + /* edit field */ field.border_size = 0; field.scrollbar_width = 0; field.rounding = 0; @@ -5598,6 +5633,7 @@ zr_do_property(enum zr_widget_status *ws, active = (*state == ZR_PROPERTY_EDIT); if (old != ZR_PROPERTY_EDIT && active) { + /* property has been activated so setup buffer */ zr_memcopy(buffer, dst, *length); *len = *length; length = len; @@ -5609,6 +5645,7 @@ zr_do_property(enum zr_widget_status *ws, (*state == ZR_PROPERTY_EDIT) ? in: 0, f); if (old && !active) { + /* property is now not active so convert edit text to value*/ *state = ZR_PROPERTY_DEFAULT; buffer[*len] = '\0'; zr_string_float_limit(buffer, ZR_MAX_FLOAT_PRECISION); @@ -5825,7 +5862,7 @@ int zr_input_is_mouse_released(const struct zr_input *i, enum zr_buttons id) { if (!i) return zr_false; - return (!i->mouse.buttons[id].down && i->mouse.buttons[id].clicked) ? zr_true : zr_false; + return (!i->mouse.buttons[id].down && i->mouse.buttons[id].clicked); } int @@ -6230,7 +6267,8 @@ static int zr_layout_begin(struct zr_context*, const char*); static void zr_layout_end(struct zr_context*); static void -zr_pool_init(struct zr_pool *pool, struct zr_allocator *alloc, unsigned int capacity) +zr_pool_init(struct zr_pool *pool, struct zr_allocator *alloc, + unsigned int capacity) { zr_zero(pool, sizeof(*pool)); pool->alloc = *alloc; @@ -6503,7 +6541,8 @@ zr_find_value(struct zr_window *win, zr_hash name) } static zr_uint* -zr_add_value(struct zr_context *ctx, struct zr_window *win, zr_hash name, zr_uint value) +zr_add_value(struct zr_context *ctx, struct zr_window *win, + zr_hash name, zr_uint value) { if (!win->tables || win->table_size == ZR_VALUE_PAGE_CAPACITY) { struct zr_table *tbl = zr_create_table(ctx); @@ -6539,6 +6578,7 @@ zr_finish_child(struct zr_context *ctx, struct zr_window *win) ZR_ASSERT(win); if (!ctx || !win) return; + /* */ buf = &win->layout->popup_buffer; buf->last = win->buffer.last; buf->end = win->buffer.end; @@ -6559,14 +6599,15 @@ zr_finish(struct zr_context *ctx, struct zr_window *win) win->buffer.end = ctx->memory.allocated; if (!win->layout->popup_buffer.active) return; + /* frome here this case is for popup windows */ buf = &win->layout->popup_buffer; memory = ctx->memory.memory.ptr; + /* redirect the sub-window buffer to the end of the window command buffer */ parent_last = zr_ptr_add(struct zr_command, memory, buf->parent); sublast = zr_ptr_add(struct zr_command, memory, buf->last); last = zr_ptr_add(struct zr_command, memory, win->buffer.last); - /* redirect the subbuffer to the end of the current command buffer */ parent_last->next = buf->end; sublast->next = last->next; last->next = buf->begin; @@ -6642,10 +6683,12 @@ zr_clear(struct zr_context *ctx) struct zr_window *iter; struct zr_window *next; ZR_ASSERT(ctx); + if (!ctx) return; if (ctx->pool) zr_buffer_clear(&ctx->memory); else zr_buffer_reset(&ctx->memory, ZR_BUFFER_FRONT); + ctx->build = 0; ctx->memory.calls = 0; #if ZR_COMPILE_WITH_VERTEX_BUFFER @@ -6655,11 +6698,13 @@ zr_clear(struct zr_context *ctx) /* garbage collector */ iter = ctx->begin; while (iter) { + /* make sure minimized windows do not get removed */ if (iter->flags & ZR_WINDOW_MINIMIZED) { iter = iter->next; continue; } + /* free unused popup windows */ if (iter->popup.win && iter->popup.win->seq != ctx->seq) { zr_free_window(ctx, iter->popup.win); iter->popup.win = 0; @@ -6667,7 +6712,7 @@ zr_clear(struct zr_context *ctx) {struct zr_table *n, *it = iter->tables; while (it) { - /* window state tables */ + /* remove unused window state tables */ n = it->next; if (it->seq != ctx->seq) { zr_remove_table(iter, it); @@ -6679,6 +6724,7 @@ zr_clear(struct zr_context *ctx) it = n; }} + /* window itself is not used anymore so free */ if (iter->seq != ctx->seq) { next = iter->next; zr_free_window(ctx, iter); @@ -7069,7 +7115,8 @@ zr_window_set_size(struct zr_context *ctx, struct zr_vec2 size) } void -zr_window_collapse(struct zr_context *ctx, const char *name, enum zr_collapse_states c) +zr_window_collapse(struct zr_context *ctx, const char *name, + enum zr_collapse_states c) { int title_len; zr_hash title_hash; @@ -7100,6 +7147,7 @@ zr_window_collapse_if(struct zr_context *ctx, const char *name, title_hash = zr_murmur_hash(name, (int)title_len, ZR_WINDOW_TITLE); win = zr_find_window(ctx, title_hash); if (!win) return; + if (c == ZR_MINIMIZED) win->flags |= ZR_WINDOW_HIDDEN; else win->flags &= ~(zr_flags)ZR_WINDOW_HIDDEN; @@ -7199,9 +7247,8 @@ zr_header_toggle(struct zr_context *ctx, struct zr_window_header *header, zr_rune active, zr_rune inactive, enum zr_style_header_align align, int state) { int ret = zr_header_button(ctx, header,(state) ? active : inactive, align); - if (ret) - return !state; - return state; + if (ret) return !state; + else return state; } static int @@ -7242,7 +7289,8 @@ zr_layout_begin(struct zr_context *ctx, const char *title) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; c = &ctx->style; in = &ctx->input; @@ -7325,11 +7373,12 @@ zr_layout_begin(struct zr_context *ctx, const char *title) struct zr_rect old_clip = out->clip; struct zr_window_header header; - /* This is a little bit of a performace hack. To make sure the header does - * not get overdrawn with text you do not have to push a scissor rect. This - * is possible because the command buffer automatically clips text by using - * its clipping rectangle. But since the clipping rect gets reused to calculate - * the window clipping rect the old clipping rect has to be stored and reset afterwards. */ + /* This is a little bit of a performace hack. To make sure the header + * does not get overdrawn with text you do not have to push a scissor rect. + * This is possible because the command buffer automatically clips text + * by using its clipping rectangle. But since the clipping rect gets + * reused to calculate the window clipping rect the old clipping rect + * has to be stored and reset afterwards. */ out->clip.x = header.x = layout->bounds.x + window_padding.x; out->clip.y = header.y = layout->bounds.y + item_padding.y; out->clip.w = header.w = MAX(layout->bounds.w, 2 * window_padding.x); @@ -7358,11 +7407,11 @@ zr_layout_begin(struct zr_context *ctx, const char *title) /* window header icons */ if (win->flags & ZR_WINDOW_CLOSABLE) - zr_header_flag(ctx, &header, c->header.close_symbol, c->header.close_symbol, - c->header.align, ZR_WINDOW_HIDDEN); + zr_header_flag(ctx, &header, c->header.close_symbol, + c->header.close_symbol, c->header.align, ZR_WINDOW_HIDDEN); if (win->flags & ZR_WINDOW_MINIMIZABLE) - zr_header_flag(ctx, &header, c->header.maximize_symbol, c->header.minimize_symbol, - c->header.align, ZR_WINDOW_MINIMIZED); + zr_header_flag(ctx, &header, c->header.maximize_symbol, + c->header.minimize_symbol, c->header.align, ZR_WINDOW_MINIMIZED); { /* window header title */ @@ -7409,7 +7458,8 @@ zr_layout_begin(struct zr_context *ctx, const char *title) } else { /* draw dynamic window body */ zr_draw_rect(out, zr_rect(layout->bounds.x, layout->bounds.y, - layout->bounds.w, layout->row.height + window_padding.y), 0, c->colors[ZR_COLOR_WINDOW]); + layout->bounds.w, layout->row.height + window_padding.y), 0, + c->colors[ZR_COLOR_WINDOW]); } /* draw top window border line */ @@ -7473,7 +7523,8 @@ zr_layout_end(struct zr_context *ctx) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; /* cache configuration data */ window = ctx->current; @@ -7581,7 +7632,8 @@ zr_layout_end(struct zr_context *ctx) bounds.y = footer.y; } else { bounds.h = MIN(scrollbar_size, layout->footer_h); - bounds.y = layout->bounds.y + window->bounds.h - MAX(layout->footer_h, scrollbar_size); + bounds.y = layout->bounds.y + window->bounds.h; + bounds.y -= MAX(layout->footer_h, scrollbar_size); bounds.w = layout->width - 2 * window_padding.x; } scroll_offset = layout->offset->x; @@ -7702,7 +7754,8 @@ zr_menubar_begin(struct zr_context *ctx) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; layout = ctx->current->layout; if (layout->flags & ZR_WINDOW_HIDDEN || layout->flags & ZR_WINDOW_MINIMIZED) @@ -7725,7 +7778,8 @@ zr_menubar_end(struct zr_context *ctx) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; layout = win->layout; @@ -7760,10 +7814,11 @@ zr_panel_layout(const struct zr_context *ctx, struct zr_window *win, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; - layout = win->layout; + if (!ctx || !ctx->current || !ctx->current->layout) + return; /* prefetch some configuration data */ + layout = win->layout; config = &ctx->style; out = &win->buffer; color = &config->colors[ZR_COLOR_WINDOW]; @@ -7790,7 +7845,8 @@ zr_row_layout(struct zr_context *ctx, enum zr_layout_format fmt, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; zr_panel_layout(ctx, win, height, cols); @@ -7823,7 +7879,8 @@ zr_layout_row_begin(struct zr_context *ctx, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; layout = win->layout; @@ -7849,7 +7906,8 @@ zr_layout_row_push(struct zr_context *ctx, float ratio_or_width) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; layout = win->layout; @@ -7872,7 +7930,8 @@ zr_layout_row_end(struct zr_context *ctx) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; layout = win->layout; @@ -7892,7 +7951,8 @@ zr_layout_row(struct zr_context *ctx, enum zr_layout_format fmt, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; layout = win->layout; @@ -7929,7 +7989,8 @@ zr_layout_space_begin(struct zr_context *ctx, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; layout = win->layout; @@ -7953,7 +8014,8 @@ zr_layout_space_end(struct zr_context *ctx) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; layout = win->layout; @@ -7972,7 +8034,8 @@ zr_layout_space_push(struct zr_context *ctx, struct zr_rect rect) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; layout = win->layout; @@ -8088,7 +8151,8 @@ zr_layout_widget_space(struct zr_rect *bounds, const struct zr_context *ctx, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; layout = win->layout; @@ -8207,7 +8271,8 @@ zr_panel_alloc_space(struct zr_rect *bounds, const struct zr_context *ctx) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; /* check if the end of the row has been hit and begin new row if so */ win = ctx->current; @@ -8231,7 +8296,8 @@ zr_layout_peek(struct zr_rect *bounds, struct zr_context *ctx) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; layout = win->layout; @@ -8247,8 +8313,8 @@ zr_layout_peek(struct zr_rect *bounds, struct zr_context *ctx) } int -zr_layout_push(struct zr_context *ctx, enum zr_layout_node_type type, const char *title, - enum zr_collapse_states initial_state) +zr_layout_push(struct zr_context *ctx, enum zr_layout_node_type type, + const char *title, enum zr_collapse_states initial_state) { struct zr_window *win; struct zr_layout *layout; @@ -8272,7 +8338,8 @@ zr_layout_push(struct zr_context *ctx, enum zr_layout_node_type type, const char ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return zr_false; + if (!ctx || !ctx->current || !ctx->current->layout) + return zr_false; /* cache some data */ win = ctx->current; @@ -8373,7 +8440,8 @@ zr_layout_pop(struct zr_context *ctx) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; layout = win->layout; @@ -8399,7 +8467,8 @@ zr_spacing(struct zr_context *ctx, zr_size cols) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; /* spacing over row boundries */ win = ctx->current; @@ -8994,7 +9063,8 @@ zr_option(struct zr_context *ctx, const char *text, int is_active) toggle.cursor = config->colors[ZR_COLOR_TOGGLE_CURSOR]; toggle.normal = config->colors[ZR_COLOR_TOGGLE]; toggle.hover = config->colors[ZR_COLOR_TOGGLE_HOVER]; - zr_do_toggle(&ws, &win->buffer, bounds, &is_active, text, ZR_TOGGLE_OPTION, &toggle, i, &config->font); + zr_do_toggle(&ws, &win->buffer, bounds, &is_active, text, ZR_TOGGLE_OPTION, + &toggle, i, &config->font); return is_active; } @@ -9024,7 +9094,8 @@ zr_slider_float(struct zr_context *ctx, float min_value, float *value, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; layout = win->layout; @@ -9073,7 +9144,8 @@ zr_progress(struct zr_context *ctx, zr_size *cur_value, zr_size max_value, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; layout = win->layout; @@ -9136,7 +9208,6 @@ zr_edit_string(struct zr_context *ctx, zr_flags flags, buffer.allocated = *len; active = zr_edit_buffer(ctx, flags, &buffer, filter); *len = buffer.allocated; - *len = MIN(*len, max-1); return active; } @@ -9292,7 +9363,8 @@ zr_property(struct zr_context *ctx, const char *name, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; win = ctx->current; layout = win->layout; @@ -9366,10 +9438,11 @@ zr_property_int(struct zr_context *ctx, const char *name, } float -zr_propertyf(struct zr_context *ctx, const char *name, float min, float val, float max, - float step, float inc_per_pixel) +zr_propertyf(struct zr_context *ctx, const char *name, float min, float val, + float max, float step, float inc_per_pixel) { - zr_property_float(ctx, name, (float)min, &val, (float)max, (float)step, (float)inc_per_pixel); + zr_property_float(ctx, name, (float)min, &val, (float)max, + (float)step, (float)inc_per_pixel); return val; } @@ -9621,7 +9694,8 @@ zr_group_begin(struct zr_context *ctx, struct zr_layout *layout, ZR_ASSERT(title); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout || !title) return 0; + if (!ctx || !ctx->current || !ctx->current->layout || !title) + return 0; /* allocate space for the group panel inside the panel */ win = ctx->current; @@ -9678,7 +9752,8 @@ zr_group_end(struct zr_context *ctx) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); - if (!ctx || !ctx->current) return; + if (!ctx || !ctx->current) + return; /* make sure zr_group_begin was called correctly */ ZR_ASSERT(ctx->current); @@ -9732,7 +9807,8 @@ zr_popup_begin(struct zr_context *ctx, struct zr_layout *layout, ZR_ASSERT(title); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; win = ctx->current; ZR_ASSERT(!(win->flags & ZR_WINDOW_POPUP)); @@ -9804,7 +9880,8 @@ zr_nonblock_begin(struct zr_layout *layout, struct zr_context *ctx, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; /* popups cannot have popups */ win = ctx->current; @@ -9873,7 +9950,8 @@ zr_popup_end(struct zr_context *ctx) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; popup = ctx->current; ZR_ASSERT(popup->parent); @@ -9906,7 +9984,8 @@ zr_tooltip_begin(struct zr_context *ctx, struct zr_layout *layout, float width) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; /* make sure that no nonblocking popup is currently active */ win = ctx->current; @@ -9930,7 +10009,8 @@ zr_tooltip_end(struct zr_context *ctx) { ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); - if (!ctx || !ctx->current) return; + if (!ctx || !ctx->current) + return; zr_popup_close(ctx); zr_popup_end(ctx); } @@ -9951,7 +10031,8 @@ zr_tooltip(struct zr_context *ctx, const char *text) ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); ZR_ASSERT(text); - if (!ctx || !ctx->current || !ctx->current->layout || !text) return; + if (!ctx || !ctx->current || !ctx->current->layout || !text) + return; /* fetch configuration data */ config = &ctx->style; @@ -9960,7 +10041,8 @@ zr_tooltip(struct zr_context *ctx, const char *text) /* calculate size of the text and tooltip */ text_len = zr_strsiz(text); - text_width = config->font.width(config->font.userdata, config->font.height, text, text_len); + text_width = config->font.width(config->font.userdata, + config->font.height, text, text_len); text_width += (zr_size)(2 * padding.x + 2 * item_padding.x); text_height = (zr_size)(config->font.height + 2 * item_padding.y); @@ -9996,7 +10078,9 @@ zr_contextual_begin(struct zr_context *ctx, struct zr_layout *layout, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + win = ctx->current; ++win->popup.con_count; @@ -10004,8 +10088,10 @@ zr_contextual_begin(struct zr_context *ctx, struct zr_layout *layout, popup = win->popup.win; is_open = (popup && (popup->flags & ZR_WINDOW_CONTEXTUAL) && win->popup.type == ZR_WINDOW_CONTEXTUAL); is_clicked = zr_input_mouse_clicked(&ctx->input, ZR_BUTTON_RIGHT, trigger_bounds); - if (win->popup.active_con && win->popup.con_count != win->popup.active_con) return 0; - if ((is_clicked && is_open && !is_active) || (!is_open && !is_active && !is_clicked)) return 0; + if (win->popup.active_con && win->popup.con_count != win->popup.active_con) + return 0; + if ((is_clicked && is_open && !is_active) || (!is_open && !is_active && !is_clicked)) + return 0; /* calculate contextual position on click */ win->popup.active_con = win->popup.con_count; @@ -10020,7 +10106,8 @@ zr_contextual_begin(struct zr_context *ctx, struct zr_layout *layout, body.h = size.y; /* start nonblocking contextual popup */ - ret = zr_nonblock_begin(layout, ctx, flags|ZR_WINDOW_CONTEXTUAL|ZR_WINDOW_NO_SCROLLBAR, body, null_rect); + ret = zr_nonblock_begin(layout, ctx, + flags|ZR_WINDOW_CONTEXTUAL|ZR_WINDOW_NO_SCROLLBAR, body, null_rect); if (ret) win->popup.type = ZR_WINDOW_CONTEXTUAL; else { win->popup.active_con = 0; @@ -10045,7 +10132,8 @@ zr_contextual_button(struct zr_context *ctx, const char *text, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; win = ctx->current; config = &ctx->style; @@ -10080,7 +10168,8 @@ zr_contextual_button_symbol(struct zr_context *ctx, enum zr_symbol_type symbol, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; win = ctx->current; state = zr_button(&button.base, &bounds, ctx, ZR_BUTTON_FITTING); @@ -10115,7 +10204,8 @@ zr_contextual_button_icon(struct zr_context *ctx, struct zr_image img, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; win = ctx->current; state = zr_button(&button.base, &bounds, ctx, ZR_BUTTON_FITTING); @@ -10141,7 +10231,8 @@ zr_contextual_item(struct zr_context *ctx, const char *title, enum zr_text_align ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; if (zr_contextual_button(ctx, title, align, ZR_BUTTON_DEFAULT)) { zr_contextual_close(ctx); @@ -10157,7 +10248,8 @@ zr_contextual_item_icon(struct zr_context *ctx, struct zr_image img, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; if (zr_contextual_button_icon(ctx, img, title, align, ZR_BUTTON_DEFAULT)){ zr_contextual_close(ctx); @@ -10173,7 +10265,8 @@ zr_contextual_item_symbol(struct zr_context *ctx, enum zr_symbol_type symbol, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; if (zr_contextual_button_symbol(ctx, symbol, title, align, ZR_BUTTON_DEFAULT)){ zr_contextual_close(ctx); @@ -10188,9 +10281,11 @@ zr_contextual_close(struct zr_context *ctx) ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return; + if (!ctx || !ctx->current || !ctx->current->layout) + return; - if (!ctx->current) return; + if (!ctx->current) + return; zr_popup_close(ctx); } @@ -10225,7 +10320,8 @@ zr_combo_begin(struct zr_layout *layout, struct zr_context *ctx, struct zr_windo ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; body.x = header.x; body.w = header.w; @@ -10261,7 +10357,8 @@ zr_combo_begin_text(struct zr_context *ctx, struct zr_layout *layout, ZR_ASSERT(selected); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout || !selected) return 0; + if (!ctx || !ctx->current || !ctx->current->layout || !selected) + return 0; win = ctx->current; s = zr_widget(&header, ctx); @@ -10321,7 +10418,8 @@ zr_combo_begin_color(struct zr_context *ctx, struct zr_layout *layout, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; win = ctx->current; s = zr_widget(&header, ctx); @@ -10351,8 +10449,8 @@ zr_combo_begin_color(struct zr_context *ctx, struct zr_layout *layout, zr_draw_rect(&win->buffer, content, 0, color); /* draw open/close symbol */ - bounds.y = (header.y + item_padding.y) + (header.h-2.0f*item_padding.y)/2.0f - - ctx->style.font.height/2; + bounds.y = (header.y + item_padding.y) + (header.h-2.0f*item_padding.y)/2.0f + -ctx->style.font.height/2; bounds.w = bounds.h = ctx->style.font.height; bounds.x = (header.x + header.w) - (bounds.w + 2 * item_padding.x); @@ -10380,7 +10478,8 @@ zr_combo_begin_image(struct zr_context *ctx, struct zr_layout *layout, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; win = ctx->current; s = zr_widget(&header, ctx); @@ -10408,8 +10507,8 @@ zr_combo_begin_image(struct zr_context *ctx, struct zr_layout *layout, zr_draw_image(&win->buffer, content, &img); /* draw open/close symbol */ - bounds.y = (header.y + item_padding.y) + (header.h-2.0f*item_padding.y)/2.0f - - ctx->style.font.height/2; + bounds.y = (header.y + item_padding.y) + (header.h-2.0f*item_padding.y)/2.0f + -ctx->style.font.height/2; bounds.w = bounds.h = ctx->style.font.height; bounds.x = (header.x + header.w) - (bounds.w + 2 * item_padding.x); @@ -10435,7 +10534,8 @@ zr_combo_begin_icon(struct zr_context *ctx, struct zr_layout *layout, const char ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; win = ctx->current; if (!zr_widget(&header, ctx)) @@ -10527,7 +10627,8 @@ zr_menu_begin(struct zr_layout *layout, struct zr_context *ctx, struct zr_window ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; body.x = header.x; body.w = width; @@ -10539,7 +10640,8 @@ zr_menu_begin(struct zr_layout *layout, struct zr_context *ctx, struct zr_window is_active = (popup && (win->popup.name == hash) && win->popup.type == ZR_WINDOW_MENU); if ((is_clicked && is_open && !is_active) || (is_open && !is_active) || (!is_open && !is_active && !is_clicked)) return 0; - if (!zr_nonblock_begin(layout, ctx, ZR_WINDOW_MENU|ZR_WINDOW_NO_SCROLLBAR, body, header)) return 0; + if (!zr_nonblock_begin(layout, ctx, ZR_WINDOW_MENU|ZR_WINDOW_NO_SCROLLBAR, body, header)) + return 0; win->popup.type = ZR_WINDOW_MENU; win->popup.name = hash; return 1; @@ -10550,6 +10652,7 @@ zr_menu_text_begin(struct zr_context *ctx, struct zr_layout *layout, const char *title, float width) { struct zr_window *win; + const struct zr_input *in; struct zr_rect header; int is_clicked = zr_false; enum zr_widget_status state; @@ -10557,14 +10660,17 @@ zr_menu_text_begin(struct zr_context *ctx, struct zr_layout *layout, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; win = ctx->current; + in = &ctx->input; { /* execute menu text button for open/closing the popup */ struct zr_button_text button; zr_zero(&button, sizeof(button)); - if (!zr_button(&button.base, &header, ctx, ZR_BUTTON_NORMAL)) return 0; + if (!zr_button(&button.base, &header, ctx, ZR_BUTTON_NORMAL)) + return 0; button.base.rounding = 0; button.base.border_width = 0; @@ -10575,8 +10681,9 @@ zr_menu_text_begin(struct zr_context *ctx, struct zr_layout *layout, button.normal = ctx->style.colors[ZR_COLOR_TEXT]; button.active = ctx->style.colors[ZR_COLOR_TEXT]; button.hover = ctx->style.colors[ZR_COLOR_TEXT]; - if (zr_do_button_text(&state, &win->buffer, header, title, ZR_BUTTON_DEFAULT, - &button,(win->layout->flags & ZR_WINDOW_ROM) ? 0: &ctx->input, &ctx->style.font)) + in = (win->layout->flags & ZR_WINDOW_ROM) ? 0: &ctx->input; + if (zr_do_button_text(&state, &win->buffer, header, + title, ZR_BUTTON_DEFAULT, &button, in, &ctx->style.font)) is_clicked = zr_true; } return zr_menu_begin(layout, ctx, win, title, is_clicked, header, width); @@ -10594,14 +10701,16 @@ zr_menu_icon_begin(struct zr_context *ctx, struct zr_layout *layout, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; win = ctx->current; { /* execute menu icon button for open/closing the popup */ struct zr_button_icon button; zr_zero(&button, sizeof(button)); - if (!zr_button(&button.base, &header, ctx, ZR_BUTTON_NORMAL)) return 0; + if (!zr_button(&button.base, &header, ctx, ZR_BUTTON_NORMAL)) + return 0; button.base.rounding = 1; button.base.border = ctx->style.colors[ZR_COLOR_BORDER]; @@ -10627,14 +10736,16 @@ zr_menu_symbol_begin(struct zr_context *ctx, struct zr_layout *layout, ZR_ASSERT(ctx); ZR_ASSERT(ctx->current); ZR_ASSERT(ctx->current->layout); - if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; win = ctx->current; { /* execute menu symbol button for open/closing the popup */ struct zr_button_symbol button; zr_zero(&button, sizeof(button)); - if (!zr_button(&button.base, &header, ctx, ZR_BUTTON_NORMAL)) return 0; + if (!zr_button(&button.base, &header, ctx, ZR_BUTTON_NORMAL)) + return 0; button.base.rounding = 1; button.base.border = ctx->style.colors[ZR_COLOR_BORDER]; @@ -10644,8 +10755,8 @@ zr_menu_symbol_begin(struct zr_context *ctx, struct zr_layout *layout, button.active = ctx->style.colors[ZR_COLOR_TEXT]; button.hover = ctx->style.colors[ZR_COLOR_TEXT]; if (zr_do_button_symbol(&state, &win->buffer, header, sym, ZR_BUTTON_DEFAULT, - &button, (win->layout->flags & ZR_WINDOW_ROM)?0:&ctx->input, &ctx->style.font)) - is_clicked = zr_true; + &button, (win->layout->flags & ZR_WINDOW_ROM) ? 0 : &ctx->input, + &ctx->style.font)) is_clicked = zr_true; } return zr_menu_begin(layout, ctx, win, id, is_clicked, header, width); } diff --git a/zahnrad.h b/zahnrad.h index b379144..02f4b86 100644 --- a/zahnrad.h +++ b/zahnrad.h @@ -36,13 +36,13 @@ extern "C" { #define ZR_INPUT_MAX 16 /* defines the max number of bytes to be added as text input in one frame */ #define ZR_MAX_COLOR_STACK 32 -/* defines the number of temporary configuration color changes that can be stored */ +/* Number of temporary configuration color changes that can be stored */ #define ZR_MAX_ATTRIB_STACK 32 -/* defines the number of temporary configuration attribute changes that can be stored */ +/* Number of temporary configuration attribute changes that can be stored */ #define ZR_MAX_FONT_STACK 32 -/* defines the number of temporary configuration user font changes that can be stored */ +/* Number of temporary configuration user font changes that can be stored */ #define ZR_MAX_FONT_HEIGHT_STACK 32 -/* defines the number of temporary configuration font height changes that can be stored */ +/* Number of temporary configuration font height changes that can be stored */ #define ZR_MAX_NUMBER_BUFFER 64 /* * ============================================================== @@ -56,14 +56,14 @@ extern "C" { * if 0 each type has to be set to the correct size*/ #define ZR_COMPILE_WITH_ASSERT 1 /* setting this define to 1 adds header for the assert macro - IMPORTANT: it also adds the standard library assert so only use it if wanted */ + IMPORTANT: it also adds the standard library assert so only use it if wanted*/ #define ZR_COMPILE_WITH_VERTEX_BUFFER 1 -/* setting this define to 1 adds a vertex draw command list backend to this library, - which allows you to convert queue commands into vertex draw commands. - If you do not want or need a default backend you can set this flag to zero - and the module of the library will not be compiled */ +/* setting this to 1 adds a vertex draw command list backend to this + library, which allows you to convert queue commands into vertex draw commands. + If you do not want or need a default backend you can set this flag to zero + and the module of the library will not be compiled */ #define ZR_COMPILE_WITH_FONT 1 -/* setting this define to 1 adds the `stb_truetype` and `stb_rect_pack` header +/* setting this to 1 adds the `stb_truetype` and `stb_rect_pack` header to this library and provides a default font for font loading and rendering. If you already have font handling or do not want to use this font handler you can just set this define to zero and the font module will not be compiled @@ -118,7 +118,7 @@ struct zr_rect {float x,y,w,h;}; struct zr_recti {short x,y,w,h;}; typedef char zr_glyph[ZR_UTF_SIZE]; typedef union {void *ptr; int id;} zr_handle; -struct zr_image {zr_handle handle; unsigned short w, h; unsigned short region[4];}; +struct zr_image {zr_handle handle;unsigned short w,h;unsigned short region[4];}; struct zr_scroll {unsigned short x, y;}; /* math */ @@ -145,7 +145,7 @@ zr_uint zr_color32(struct zr_color); void zr_colorf(float *r, float *g, float *b, float *a, struct zr_color); void zr_color_hsv(int *out_h, int *out_s, int *out_v, struct zr_color); void zr_color_hsv_f(float *out_h, float *out_s, float *out_v, struct zr_color); -void zr_color_hsva(int *out_h, int *out_s, int *out_v, int *out_a, struct zr_color); +void zr_color_hsva(int *h, int *s, int *v, int *a, struct zr_color); void zr_color_hsva_f(float *out_h, float *out_s, float *out_v, float *out_a, struct zr_color); @@ -154,9 +154,11 @@ zr_handle zr_handle_ptr(void*); zr_handle zr_handle_id(int); struct zr_image zr_image_ptr(void*); struct zr_image zr_image_id(int); -struct zr_image zr_subimage_ptr(void*, unsigned short w, unsigned short h, struct zr_rect); -struct zr_image zr_subimage_id(int, unsigned short w, unsigned short h, struct zr_rect); int zr_image_is_subimage(const struct zr_image* img); +struct zr_image zr_subimage_ptr(void*, unsigned short w, unsigned short h, + struct zr_rect sub_region); +struct zr_image zr_subimage_id(int, unsigned short w, unsigned short h, + struct zr_rect sub_region); /* ============================================================== * @@ -164,39 +166,40 @@ int zr_image_is_subimage(const struct zr_image* img); * * ===============================================================*/ /* A basic (double)-buffer with linear allocation and resetting as only - freeing policy. The buffers main purpose is to control all memory management inside - the GUI toolkit and still leave memory control as much as possible in the hand - of the user. The memory is provided in three different ways. + freeing policy. The buffers main purpose is to control all memory management + inside the GUI toolkit and still leave memory control as much as possible in + the hand of the user. The memory is provided in three different ways. The first way is to use a fixed size block of memory to be filled up. Biggest advantage is a simple memory model. Downside is that if the buffer - is full there is no way to accesses more memory, which fits target application - with a GUI with roughly known memory consumptions. - The second way to manage memory is by extending the fixed size block by querying - information from the buffer about the used size and needed size and allocate new - memory if the buffer is full. While this approach is still better than just using - a fixed size memory block the reallocation still has one invalid frame as consquence - since the used memory information is only available at the end of the frame which leads - to the last way of handling memory. - The last and most complicated way of handling memory is by allocator callbacks. - The user hereby registers callbacks to be called to allocate and free - memory if needed. While this solves most allocation problems it causes some - loss of flow control on the user side. + is full there is no way to accesses more memory, which fits target + application with a GUI with roughly known memory consumptions. + The second way to manage memory is by extending the fixed size block by + querying information from the buffer about the used size and needed size and + allocate new memory if the buffer is full. While this approach is still + better than just using a fixed size memory block the reallocation still has + one invalid frame as consquence since the used memory information is only + available at the end of the frame which leads to the last way of handling + memory. + The last and most complicated way of handling memory is by allocator + callbacks. The user hereby registers callbacks to be called to allocate and + free memory if needed. While this solves most allocation problems it causes + some loss of flow control on the user side. USAGE ---------------------------- - To instantiate the buffer you either have to call the fixed size or allocator - initialization function and provide a memory block in the first case and - an allocator in the second case. - To allocate memory from the buffer you would call zr_buffer_alloc with a request - memory block size as well as an alignment for the block. Finally to reset the memory - at the end of the frame and when the memory buffer inside the buffer is no longer - needed you would call zr_buffer_reset. To free all memory that has been allocated - by an allocator if the buffer is no longer being used you have to call - zr_buffer_clear. + To instantiate the buffer you either have to call the fixed size or + allocator initialization function and provide a memory block in the first + case and an allocator in the second case. + To allocate memory from the buffer you would call zr_buffer_alloc with a + request memory block size as well as an alignment for the block. + Finally to reset the memory at the end of the frame and when the memory + buffer inside the buffer is no longer needed you would call zr_buffer_reset. + To free all memory that has been allocated by an allocator if the buffer is + no longer being used you have to call zr_buffer_clear. */ struct zr_memory_status { void *memory; - /* pointer to the currently used memory block inside the referenced buffer */ + /* pointer to the currently used memory block inside the referenced buffer*/ unsigned int type; /* type of the buffer which is either fixed size or dynamic */ zr_size size; @@ -204,7 +207,7 @@ struct zr_memory_status { zr_size allocated; /* allocated amount of memory */ zr_size needed; - /* memory size that would have been allocated if enough memory was present */ + /* memory size that would have been allocated if enough memory was present*/ zr_size calls; /* number of allocation calls referencing this buffer */ }; @@ -256,14 +259,14 @@ struct zr_buffer { zr_size allocated; /* total amount of memory allocated */ zr_size needed; - /* total amount of memory allocated if enough memory would have been present */ + /* totally consumed memory given that enough memory is present */ zr_size calls; /* number of allocation calls */ zr_size size; /* current size of the buffer */ }; -void zr_buffer_init(struct zr_buffer*, const struct zr_allocator*, zr_size initial_size); +void zr_buffer_init(struct zr_buffer*, const struct zr_allocator*, zr_size size); void zr_buffer_init_fixed(struct zr_buffer*, void *memory, zr_size size); void zr_buffer_info(struct zr_memory_status*, struct zr_buffer*); void zr_buffer_free(struct zr_buffer*); @@ -283,9 +286,9 @@ zr_size zr_buffer_total(struct zr_buffer*); The second way of font handling is by using the same `zr_user_font` struct to referencing a font as before but providing a second callback for - `zr_user_font_glyph` querying which is used for text drawing in the optional vertex - buffer output. In addition to the callback it is also required to provide - a texture atlas from the font to draw. + `zr_user_font_glyph` querying which is used for text drawing in the optional + vertex buffer output. In addition to the callback it is also required to + provide a texture atlas from the font to draw. The final and most complex way is to use the optional font baker and font handling function, which requires two additional headers for @@ -295,11 +298,12 @@ zr_size zr_buffer_total(struct zr_buffer*); font baking API. The reason why it is complex is because there are multible ways of using the API. For example it must be possible to use the font for default command output as well as vertex buffer output. So for example - texture coordinates can either be UV for vertex buffer output or absolute pixel - for drawing function based on pixels. Furthermore it is possible to incoperate - custom user data into the resulting baked image (for example a white pixel for the - vertex buffer output). In addition and probably the most complex aspect of - the baking API was to incoperate baking of multible fonts into one image. + texture coordinates can either be UV for vertex buffer output or absolute + pixel for drawing function based on pixels. Furthermore it is possible to + incoperate custom user data into the resulting baked image (for example a + white pixel for the vertex buffer output). + In addition and probably the most complex aspect of the baking API was to + incoperate baking of multible fonts into one image. In general the font baking API can be understood as having a number of loaded in memory TTF-fonts, font baking configuration and optional custom @@ -307,10 +311,12 @@ zr_size zr_buffer_total(struct zr_buffer*); glyph array of all baked glyphs and the baked image. The API was designed that way to have a typical file format and not a perfectly ready in memory library instance of a font. The reason is more - control and seperates the font baking code from the in library used font format. + control and seperates the font baking code from the in library used font + format. */ -typedef zr_size(*zr_text_width_f)(zr_handle, float, const char*, zr_size); -typedef void(*zr_query_font_glyph_f)(zr_handle, float, struct zr_user_font_glyph*, +typedef zr_size(*zr_text_width_f)(zr_handle, float h, const char*, zr_size len); +typedef void(*zr_query_font_glyph_f)(zr_handle handle, float font_height, + struct zr_user_font_glyph *glyph, zr_rune codepoint, zr_rune next_codepoint); #if ZR_COMPILE_WITH_VERTEX_BUFFER @@ -344,7 +350,7 @@ struct zr_user_font { #ifdef ZR_COMPILE_WITH_FONT enum zr_font_coord_type { ZR_COORD_UV, - /* texture coordinates inside font glyphs are clamped between 0.0f and 1.0f */ + /* texture coordinates inside font glyphs are clamped between 0-1 */ ZR_COORD_PIXEL /* texture coordinates inside font glyphs are in absolute pixel */ }; @@ -374,7 +380,7 @@ struct zr_font_config { int pixel_snap; /* align very character to pixel boundry (if true set oversample (1,1)) */ enum zr_font_coord_type coord_type; - /* baked glyph texture coordinate format with either pixel or UV coordinates */ + /* texture coordinate format with either pixel or UV coordinates */ struct zr_vec2 spacing; /* extra pixel spacing between glyphs */ const zr_rune *range; @@ -389,7 +395,8 @@ struct zr_font_glyph { float xadvance; /* xoffset to the next character */ float x0, y0, x1, y1; - /* glyph bounding points in pixel inside the glyph image with top left and bottom right */ + /* glyph bounding points in pixel inside the glyph image with top + * left and bottom right */ float u0, v0, u1, v1; /* texture coordinates either in pixel or clamped (0.0 - 1.0) */ }; @@ -439,7 +446,7 @@ int zr_font_bake_pack(zr_size *img_memory, int *img_width, int *img_height, /* this function packs together all glyphs and optional space into one total image space and returns the needed image width and height. Input: - - NULL or custom space inside the image with width and height (will be updated!) + - NULL or custom space inside the image (will be modifed to fit!) - temporary memory block that will be used in the baking process - size of the temporary memory block - array of configuration for every font that should be baked into one image @@ -448,7 +455,8 @@ int zr_font_bake_pack(zr_size *img_memory, int *img_width, int *img_height, - calculated resulting size of the image in bytes - pixel width of the resulting image - pixel height of the resulting image - - custom space bounds with position and size inside image which can be filled by the user + - custom space bounds with position and size inside image which can be + filled by the user */ void zr_font_bake(void *image_memory, int image_width, int image_height, void *temporary_memory, zr_size temporary_memory_size, @@ -466,8 +474,8 @@ void zr_font_bake(void *image_memory, int image_width, int image_height, - filled glyph array */ void zr_font_bake_custom_data(void *img_memory, int img_width, int img_height, - struct zr_recti img_dst, const char *texture_data_mask, - int tex_width, int tex_height, char white, char black); + struct zr_recti img_dst, const char *image_data_mask, + int tex_width, int tex_height,char white,char black); /* this function bakes custom data in string format with white, black and zero alpha pixels into the font image. The zero alpha pixel is represented as any character beside the black and zero pixel character. @@ -481,10 +489,12 @@ void zr_font_bake_custom_data(void *img_memory, int img_width, int img_height, Output: - image filled with custom texture data */ -void zr_font_bake_convert(void *out_memory, int image_width, int image_height, const void *in_memory); -/* this function converts the alpha8 baking input image into a preallocated rgba8 output image.*/ +void zr_font_bake_convert(void *out_memory, int image_width, int image_height, + const void *in_memory); +/* this function converts alpha8 baking input image into a rgba8 output image.*/ void zr_font_init(struct zr_font*, float pixel_height, zr_rune fallback_codepoint, - struct zr_font_glyph*, const struct zr_baked_font*, zr_handle atlas); + struct zr_font_glyph*, const struct zr_baked_font*, + zr_handle atlas); struct zr_user_font zr_font_ref(struct zr_font*); const struct zr_font_glyph* zr_font_find_glyph(struct zr_font*, zr_rune unicode); @@ -499,7 +509,8 @@ const struct zr_font_glyph* zr_font_find_glyph(struct zr_font*, zr_rune unicode) are made of, are buffered into memory and make up a command queue. Each frame therefore fills the command buffer with draw commands that then need to be executed by the user and his own render backend. - After that the command buffer needs to be cleared and a new frame can be started. + After that the command buffer needs to be cleared and a new frame can be + started. The reason for buffering simple primitives as draw commands instead of directly buffering a hardware accessible format with vertex and element @@ -649,17 +660,21 @@ struct zr_draw_null_texture { /* drawing routines for custom widgets */ void zr_draw_scissor(struct zr_command_buffer*, struct zr_rect); -void zr_draw_line(struct zr_command_buffer*, float, float, float, float, struct zr_color); -void zr_draw_curve(struct zr_command_buffer*, float, float, float, float, float, float, +void zr_draw_line(struct zr_command_buffer*, float, float, float, + float, struct zr_color); +void zr_draw_curve(struct zr_command_buffer*, float, float, float, float, + float, float, float, float, struct zr_color); +void zr_draw_rect(struct zr_command_buffer*, struct zr_rect, + float rounding, struct zr_color); +void zr_draw_circle(struct zr_command_buffer*, struct zr_rect, struct zr_color); +void zr_draw_arc(struct zr_command_buffer*, float cx, float cy, float radius, + float a_min, float a_max, struct zr_color); +void zr_draw_triangle(struct zr_command_buffer*, float, float, float, float, float, float, struct zr_color); -void zr_draw_rect(struct zr_command_buffer*, struct zr_rect, float rounding, struct zr_color); -void zr_draw_circle(struct zr_command_buffer*, struct zr_rect, struct zr_color c); -void zr_draw_arc(struct zr_command_buffer*, float cx, float cy, float radius, float a_min, - float a_max, struct zr_color); -void zr_draw_triangle(struct zr_command_buffer*, float, float, float, float, float, float, struct zr_color); void zr_draw_image(struct zr_command_buffer*, struct zr_rect, struct zr_image*); -void zr_draw_text(struct zr_command_buffer*, struct zr_rect, const char*, zr_size, - const struct zr_user_font*, struct zr_color, struct zr_color); +void zr_draw_text(struct zr_command_buffer*, struct zr_rect, + const char *text, zr_size len, const struct zr_user_font*, + struct zr_color, struct zr_color); #endif /* =============================================================== @@ -733,10 +748,12 @@ struct zr_input { }; /* query input state */ -int zr_input_has_mouse_click_in_rect(const struct zr_input*,enum zr_buttons, struct zr_rect); +int zr_input_has_mouse_click_in_rect(const struct zr_input*, + enum zr_buttons, struct zr_rect); int zr_input_has_mouse_click_down_in_rect(const struct zr_input*, enum zr_buttons, struct zr_rect, int down); -int zr_input_is_mouse_click_in_rect(const struct zr_input*, enum zr_buttons, struct zr_rect); +int zr_input_is_mouse_click_in_rect(const struct zr_input*, + enum zr_buttons, struct zr_rect); int zr_input_any_mouse_click_in_rect(const struct zr_input*, struct zr_rect); int zr_input_is_mouse_prev_hovering_rect(const struct zr_input*, struct zr_rect); int zr_input_is_mouse_hovering_rect(const struct zr_input*, struct zr_rect); @@ -1021,12 +1038,13 @@ enum zr_edit_flags { enum zr_edit_types { ZR_EDIT_SIMPLE = 0, ZR_EDIT_FIELD = (ZR_EDIT_CURSOR|ZR_EDIT_SELECTABLE|ZR_EDIT_CLIPBOARD), - ZR_EDIT_BOX = (ZR_EDIT_CURSOR|ZR_EDIT_SELECTABLE|ZR_EDIT_CLIPBOARD|ZR_EDIT_MULTILINE) + ZR_EDIT_BOX = (ZR_EDIT_CURSOR|ZR_EDIT_SELECTABLE| + ZR_EDIT_CLIPBOARD|ZR_EDIT_MULTILINE) }; enum zr_chart_type { ZR_CHART_LINES, - /* Line chart with each data point being connected with its previous and next node */ + /* Line chart with data points connected by lines */ ZR_CHART_COLUMN, /* Histogram with value represented as bars */ ZR_CHART_MAX @@ -1125,12 +1143,13 @@ struct zr_menu { enum zr_window_flags { ZR_WINDOW_BORDER = ZR_FLAG(0), - /* Draws a border around the window to visually seperate the window from the background */ + /* Draws a border around the window to visually seperate the window + * from the background */ ZR_WINDOW_BORDER_HEADER = ZR_FLAG(1), /* Draws a border between window header and body */ ZR_WINDOW_MOVABLE = ZR_FLAG(2), - /* The moveable flag inidicates that a window can be moved by user input or by - * dragging the window header */ + /* The moveable flag inidicates that a window can be moved by user input or + * by dragging the window header */ ZR_WINDOW_SCALABLE = ZR_FLAG(3), /* The scaleable flag indicates that a window can be scaled by user input * by dragging a scaler icon at the button of the window */ @@ -1140,8 +1159,8 @@ enum zr_window_flags { /* adds a minimize icon into the header */ ZR_WINDOW_DYNAMIC = ZR_FLAG(6), /* special type of window which grows up in height while being filled to a - * certain maximum height. It is mainly used for combo boxes/menus but can be - * used to create perfectly fitting windows as well */ + * certain maximum height. It is mainly used for combo boxes/menus but can + * be used to create perfectly fitting windows as well */ ZR_WINDOW_NO_SCROLLBAR = ZR_FLAG(7), /* Removes the scrollbar from the window */ ZR_WINDOW_TITLE = ZR_FLAG(8) @@ -1210,7 +1229,6 @@ struct zr_canvas { /* texture with white pixel for easy primitive drawing */ struct zr_rect clip_rect; /* current clipping rectangle */ - /* cosine/sine calculation callback since this library does not use libc */ struct zr_buffer *buffer; /* buffer to store draw commands and temporarily store path */ struct zr_buffer *vertexes; @@ -1257,10 +1275,12 @@ struct zr_context { /*-------------------------------------------------------------- * CONTEXT * -------------------------------------------------------------*/ -int zr_init_fixed(struct zr_context*, void *memory, zr_size size, const struct zr_user_font*); +int zr_init_fixed(struct zr_context*, void *memory, zr_size size, + const struct zr_user_font*); int zr_init_custom(struct zr_context*, struct zr_buffer *cmds, struct zr_buffer *pool, const struct zr_user_font*); -int zr_init(struct zr_context*, struct zr_allocator*, const struct zr_user_font*); +int zr_init(struct zr_context*, struct zr_allocator*, + const struct zr_user_font*); void zr_clear(struct zr_context*); void zr_free(struct zr_context*); @@ -1287,9 +1307,11 @@ int zr_window_is_active(struct zr_context*, const char *name); void zr_window_set_bounds(struct zr_context*, struct zr_rect); void zr_window_set_position(struct zr_context*, struct zr_vec2); void zr_window_set_size(struct zr_context*, struct zr_vec2); -void zr_window_collapse(struct zr_context *ctx, const char *name, enum zr_collapse_states); -void zr_window_collapse_if(struct zr_context *ctx, const char *name, enum zr_collapse_states, int cond); void zr_window_set_focus(struct zr_context *ctx, const char *name); +void zr_window_collapse(struct zr_context *ctx, const char *name, + enum zr_collapse_states); +void zr_window_collapse_if(struct zr_context *ctx, const char *name, + enum zr_collapse_states, int cond); /*-------------------------------------------------------------- * DRAWING @@ -1317,10 +1339,13 @@ struct zr_convert_config { void zr_convert(struct zr_context*, struct zr_buffer *cmds, struct zr_buffer *vertexes, struct zr_buffer *elements, const struct zr_convert_config*); -#define zr_draw_foreach(cmd,ctx, b) for((cmd)=zr__draw_begin(ctx, b); (cmd)!=0; (cmd)=zr__draw_next(cmd, b, ctx)) -const struct zr_draw_command* zr__draw_begin(const struct zr_context*, const struct zr_buffer*); +#define zr_draw_foreach(cmd,ctx, b)\ + for((cmd)=zr__draw_begin(ctx, b); (cmd)!=0; (cmd)=zr__draw_next(cmd, b, ctx)) +const struct zr_draw_command* zr__draw_begin(const struct zr_context*, + const struct zr_buffer*); const struct zr_draw_command* zr__draw_next(const struct zr_draw_command*, - const struct zr_buffer*, const struct zr_context*); + const struct zr_buffer*, + const struct zr_context*); /*-------------------------------------------------------------- * INPUT @@ -1332,7 +1357,7 @@ void zr_input_button(struct zr_context*, enum zr_buttons, int x, int y, int down void zr_input_scroll(struct zr_context*, float y); void zr_input_glyph(struct zr_context*, const zr_glyph); void zr_input_char(struct zr_context*, char); -void zr_input_unicode(struct zr_context *in, zr_rune unicode); +void zr_input_unicode(struct zr_context *in, zr_rune); void zr_input_end(struct zr_context*); /*-------------------------------------------------------------- @@ -1372,7 +1397,8 @@ void zr_layout_peek(struct zr_rect *bounds, struct zr_context*); /* columns based layouting with generated position and width and fixed height*/ void zr_layout_row_dynamic(struct zr_context*, float height, zr_size cols); -void zr_layout_row_static(struct zr_context*, float height, zr_size item_width, zr_size cols); +void zr_layout_row_static(struct zr_context*, float height, zr_size item_width, + zr_size cols); /* widget layouting with custom widget width and fixed height */ void zr_layout_row_begin(struct zr_context*, enum zr_layout_format, @@ -1418,7 +1444,8 @@ void zr_text_colored(struct zr_context*, const char*, zr_size, enum zr_text_alig void zr_text_wrap(struct zr_context*, const char*, zr_size); void zr_text_wrap_colored(struct zr_context*, const char*, zr_size, struct zr_color); void zr_label(struct zr_context*, const char*, enum zr_text_align); -void zr_label_colored(struct zr_context*, const char*, enum zr_text_align, struct zr_color); +void zr_label_colored(struct zr_context*, const char*, enum zr_text_align, + struct zr_color); void zr_label_wrap(struct zr_context*, const char*); void zr_label_colored_wrap(struct zr_context*, const char*, struct zr_color); void zr_image(struct zr_context*, struct zr_image); @@ -1450,20 +1477,23 @@ int zr_slide_int(struct zr_context*, int min, int val, int max, int step); /* extended value modifier by dragging, increment/decrement and text input */ void zr_property_float(struct zr_context *layout, const char *name, - float min, float *val, float max, float step, float inc_per_pixel); + float min, float *val, float max, float step, + float inc_per_pixel); void zr_property_int(struct zr_context *layout, const char *name, int min, int *val, int max, int step, int inc_per_pixel); -float zr_propertyf(struct zr_context *layout, const char *name, float min, float val, float max, - float step, float inc_per_pixel); -int zr_propertyi(struct zr_context *layout, const char *name, int min, int val, int max, - int step, int inc_per_pixel); +float zr_propertyf(struct zr_context *layout, const char *name, float min, + float val, float max, float step, float inc_per_pixel); +int zr_propertyi(struct zr_context *layout, const char *name, int min, int val, + int max, int step, int inc_per_pixel); /* text manipulation */ -int zr_edit_string(struct zr_context*, zr_flags, char *buffer, zr_size *len, zr_size max, zr_filter); +int zr_edit_string(struct zr_context*, zr_flags, char *buffer, zr_size *len, + zr_size max, zr_filter); int zr_edit_buffer(struct zr_context*, zr_flags, struct zr_buffer*, zr_filter); /* simple chart */ -void zr_chart_begin(struct zr_context*, enum zr_chart_type, zr_size num, float min, float max); +void zr_chart_begin(struct zr_context*, enum zr_chart_type, zr_size num, + float min, float max); zr_flags zr_chart_push(struct zr_context*, float); void zr_chart_end(struct zr_context*); @@ -1485,8 +1515,10 @@ int zr_combo_begin_image(struct zr_context*, struct zr_layout*, const char *id, int zr_combo_begin_icon(struct zr_context*, struct zr_layout*, const char *id, const char *selected, struct zr_image img, int height); int zr_combo_item(struct zr_context*, const char*, enum zr_text_align); -int zr_combo_item_icon(struct zr_context*, struct zr_image, const char*, enum zr_text_align align); -int zr_combo_item_symbol(struct zr_context*, enum zr_symbol_type symbol, const char*, enum zr_text_align align); +int zr_combo_item_icon(struct zr_context*, struct zr_image, const char*, + enum zr_text_align align); +int zr_combo_item_symbol(struct zr_context*, enum zr_symbol_type symbol, + const char*, enum zr_text_align align); void zr_combo_close(struct zr_context*); void zr_combo_end(struct zr_context*); @@ -1494,8 +1526,10 @@ void zr_combo_end(struct zr_context*); int zr_contextual_begin(struct zr_context*, struct zr_layout*, zr_flags flags, struct zr_vec2 size, struct zr_rect trigger_bounds); int zr_contextual_item(struct zr_context*, const char*, enum zr_text_align align); -int zr_contextual_item_icon(struct zr_context*, struct zr_image, const char*, enum zr_text_align); -int zr_contextual_item_symbol(struct zr_context*, enum zr_symbol_type, const char*, enum zr_text_align); +int zr_contextual_item_icon(struct zr_context*, struct zr_image, + const char*, enum zr_text_align); +int zr_contextual_item_symbol(struct zr_context*, enum zr_symbol_type, + const char*, enum zr_text_align); void zr_contextual_close(struct zr_context*); void zr_contextual_end(struct zr_context*); @@ -1510,12 +1544,17 @@ void zr_tooltip_end(struct zr_context*); void zr_menubar_begin(struct zr_context*); void zr_menubar_end(struct zr_context*); -int zr_menu_text_begin(struct zr_context*, struct zr_layout*, const char *title, float width); -int zr_menu_icon_begin(struct zr_context*, struct zr_layout*, const char *id, struct zr_image, float width); -int zr_menu_symbol_begin(struct zr_context*, struct zr_layout*, const char *id, enum zr_symbol_type, float width); -int zr_menu_item(struct zr_context*, enum zr_text_align align, const char*); -int zr_menu_item_icon(struct zr_context*, struct zr_image, const char*, enum zr_text_align); -int zr_menu_item_symbol(struct zr_context*, enum zr_symbol_type, const char*, enum zr_text_align); +int zr_menu_text_begin(struct zr_context*, struct zr_layout*, + const char *title, float width); +int zr_menu_icon_begin(struct zr_context*, struct zr_layout*, const char *id, + struct zr_image, float width); +int zr_menu_symbol_begin(struct zr_context*, struct zr_layout*, const char *id, + enum zr_symbol_type, float width); +int zr_menu_item(struct zr_context*, enum zr_text_align align, const char *id); +int zr_menu_item_icon(struct zr_context*, struct zr_image, const char*, + enum zr_text_align); +int zr_menu_item_symbol(struct zr_context*, enum zr_symbol_type, const char *id, + enum zr_text_align); void zr_menu_close(struct zr_context*); void zr_menu_end(struct zr_context*); @@ -1524,3 +1563,4 @@ void zr_menu_end(struct zr_context*); #endif #endif /* ZR_H_ */ +