added flag checkbox

This commit is contained in:
vurtun 2016-03-27 22:07:25 +02:00
parent 87c70bab5a
commit 9aa4d6bd91
2 changed files with 50 additions and 11 deletions

View File

@ -4929,7 +4929,7 @@ zr_do_button(zr_flags *state, struct zr_command_buffer *out, struct zr_rect r,
content->w = r.w - 2 * style->padding.x;
content->h = r.h - 2 * style->padding.y;
/* execute and draw button */
/* execute button behavior */
bounds.x = r.x - style->touch_padding.x;
bounds.y = r.y - style->touch_padding.y;
bounds.w = r.w + 2 * style->touch_padding.x;
@ -10224,6 +10224,21 @@ zr_check_text(struct zr_context *ctx, const char *text, zr_size len, int active)
return active;
}
unsigned int
zr_check_flag_text(struct zr_context *ctx, const char *text, zr_size len,
unsigned int flags, unsigned int value)
{
int old_active, active;
ZR_ASSERT(ctx);
ZR_ASSERT(text);
if (!ctx || !text) return flags;
old_active = active = (int)(flags & value);
if (zr_check_text(ctx, text, len, old_active))
flags |= value;
else flags &= ~value;
return flags;
}
int
zr_checkbox_text(struct zr_context *ctx, const char *text, zr_size len, int *active)
{
@ -10237,12 +10252,38 @@ zr_checkbox_text(struct zr_context *ctx, const char *text, zr_size len, int *act
return old_val != *active;
}
int
zr_checkbox_flag_text(struct zr_context *ctx, const char *text, zr_size len,
unsigned int *flags, unsigned int value)
{
int active;
ZR_ASSERT(ctx);
ZR_ASSERT(text);
ZR_ASSERT(flags);
if (!ctx || !text || !flags) return 0;
active = (int)(*flags & value);
if (zr_checkbox_text(ctx, text, len, &active)) {
if (active) *flags |= value;
else *flags &= ~value;
return 1;
}
return 0;
}
int zr_check_label(struct zr_context *ctx, const char *label, int active)
{return zr_check_text(ctx, label, zr_strsiz(label), active);}
unsigned int zr_check_flag_label(struct zr_context *ctx, const char *label,
unsigned int flags, unsigned int value)
{return zr_check_flag_text(ctx, label, zr_strsiz(label), flags, value);}
int zr_checkbox_label(struct zr_context *ctx, const char *label, int *active)
{return zr_checkbox_text(ctx, label, zr_strsiz(label), active);}
int zr_checkbox_flag_label(struct zr_context *ctx, const char *label,
unsigned int *flags, unsigned int value)
{return zr_checkbox_flag_text(ctx, label, zr_strsiz(label), flags, value);}
/*----------------------------------------------------------------
* OPTION
* --------------------------------------------------------------*/

View File

@ -1680,16 +1680,6 @@ struct zr_edit_state {
int active, prev;
};
struct zr_combo_filter_state {
zr_hash name;
char filter[ZR_MAX_COMBO_EDIT_BUFFER];
zr_size length;
zr_size cursor;
unsigned int seq;
unsigned int old;
int active, prev;
};
struct zr_property_state {
int active, prev;
char buffer[ZR_MAX_NUMBER_BUFFER];
@ -1979,8 +1969,16 @@ int zr_button_image_text(struct zr_context*, struct zr_image img, const char*,
/* checkbox */
int zr_check_label(struct zr_context*, const char*, int active);
int zr_check_text(struct zr_context*, const char*, zr_size,int active);
unsigned int zr_check_flag_label(struct zr_context*, const char*,
unsigned int flags, unsigned int value);
unsigned int zr_check_flag_text(struct zr_context*, const char*, zr_size,
unsigned int flags, unsigned int value);
int zr_checkbox_label(struct zr_context*, const char*, int *active);
int zr_checkbox_text(struct zr_context*, const char*, zr_size, int *active);
int zr_checkbox_flag_label(struct zr_context*, const char*,
unsigned int *flags, unsigned int value);
int zr_checkbox_flag_text(struct zr_context*, const char*, zr_size,
unsigned int *flags, unsigned int value);
/* radio button */
int zr_radio_label(struct zr_context*, const char*, int *active);