diff --git a/demo/demo.c b/demo/demo.c index d7aec0c..28ada62 100644 --- a/demo/demo.c +++ b/demo/demo.c @@ -536,7 +536,7 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme) static size_t text_len[9]; static size_t field_len; static size_t box_len; - int active; + zr_flags active; zr_layout_row(ctx, ZR_STATIC, 25, 2, ratio); zr_label(ctx, "Default:", ZR_TEXT_LEFT); @@ -574,7 +574,9 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme) zr_layout_row(ctx, ZR_STATIC, 25, 2, ratio); active = zr_edit_string(ctx, ZR_EDIT_FIELD, text[7], &text_len[7], 64, zr_filter_ascii); if (zr_button_text(ctx, "Submit", ZR_BUTTON_DEFAULT) - ||(active && zr_input_is_key_pressed(&ctx->input, ZR_KEY_ENTER))) { + || ((active & ZR_EDIT_ACTIVE) && + zr_input_is_key_pressed(&ctx->input, ZR_KEY_ENTER))) + { text[7][text_len[7]] = '\n'; text_len[7]++; memcpy(&box_buffer[box_len], &text[7], text_len[7]); diff --git a/zahnrad.c b/zahnrad.c index 11bb053..5a178f0 100644 --- a/zahnrad.c +++ b/zahnrad.c @@ -4113,6 +4113,7 @@ zr_do_button_symbol(enum zr_widget_status *state, color = b->active; break; } + sym.type = symbol; sym.background = background; sym.foreground = color; @@ -9196,11 +9197,11 @@ zr_edit_base(struct zr_rect *bounds, struct zr_edit *field, return state; } -int +zr_flags zr_edit_string(struct zr_context *ctx, zr_flags flags, char *memory, zr_size *len, zr_size max, zr_filter filter) { - int active; + zr_flags active; struct zr_buffer buffer; max = MAX(1, max); *len = MIN(*len, max-1); @@ -9211,12 +9212,13 @@ zr_edit_string(struct zr_context *ctx, zr_flags flags, return active; } -int +zr_flags zr_edit_buffer(struct zr_context *ctx, zr_flags flags, struct zr_buffer *buffer, zr_filter filter) { struct zr_window *win; struct zr_input *i; + zr_flags old_flags, ret_flags = 0; enum zr_widget_state state; struct zr_rect bounds; @@ -9263,6 +9265,7 @@ zr_edit_buffer(struct zr_context *ctx, zr_flags flags, sel = &dummy_sel; } + old_flags = (*active) ? ZR_EDIT_ACTIVE: ZR_EDIT_INACTIVE; if (!flags || flags == ZR_EDIT_CURSOR) { int old = *active; if (!flags) { @@ -9319,6 +9322,7 @@ zr_edit_buffer(struct zr_context *ctx, zr_flags flags, if (box.active) { /* update hot edit widget state */ + *active = 1; win->edit.active = 1; win->edit.name = hash; win->edit.scrollbar = box.scrollbar; @@ -9329,7 +9333,14 @@ zr_edit_buffer(struct zr_context *ctx, zr_flags flags, win->edit.active = 0; } } - return *active; + + /* compress edit widget state and state changes into flags */ + ret_flags = (*active) ? ZR_EDIT_ACTIVE: ZR_EDIT_INACTIVE; + if (old_flags == ZR_EDIT_INACTIVE && ret_flags & ZR_EDIT_ACTIVE) + ret_flags |= ZR_EDIT_ACTIVATED; + else if (old_flags == ZR_EDIT_ACTIVE && ret_flags & ZR_EDIT_INACTIVE) + ret_flags |= ZR_EDIT_DEACTIVATED; + return ret_flags; } static void diff --git a/zahnrad.h b/zahnrad.h index 02f4b86..09c6853 100644 --- a/zahnrad.h +++ b/zahnrad.h @@ -1029,10 +1029,15 @@ enum zr_button_behavior { enum zr_edit_flags { ZR_EDIT_READ_ONLY = ZR_FLAG(0), + /* text inside the edit widget cannot be modified */ ZR_EDIT_CURSOR = ZR_FLAG(1), + /* edit widget will have a movable cursor */ ZR_EDIT_SELECTABLE = ZR_FLAG(2), + /* edit widget allows text selection */ ZR_EDIT_CLIPBOARD = ZR_FLAG(3), + /* edit widget tries to use the clipbard callback for copy & paste */ ZR_EDIT_MULTILINE = ZR_FLAG(4) + /* edit widget with text wrapping text editing */ }; enum zr_edit_types { @@ -1042,6 +1047,17 @@ enum zr_edit_types { ZR_EDIT_CLIPBOARD|ZR_EDIT_MULTILINE) }; +enum zr_edit_return_flags { + ZR_EDIT_ACTIVE = ZR_FLAG(0), + /* edit widget is currently being modified */ + ZR_EDIT_INACTIVE = ZR_FLAG(1), + /* edit widget is not active and is not being modified */ + ZR_EDIT_ACTIVATED = ZR_FLAG(2), + /* edit widget went from state inactive to state active */ + ZR_EDIT_DEACTIVATED = ZR_FLAG(3) + /* edit widget went from state active to state inactive */ +}; + enum zr_chart_type { ZR_CHART_LINES, /* Line chart with data points connected by lines */ @@ -1487,9 +1503,9 @@ 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_flags 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); +zr_flags 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,