added multiline editbox + fixed some bugs

This commit is contained in:
vurtun 2015-12-01 00:17:26 +01:00
parent 869270dc94
commit 2b2b33fc0b
6 changed files with 883 additions and 375 deletions

View File

@ -25,6 +25,7 @@ struct demo {
size_t w, h;
enum theme theme;
struct zr_edit_box text;
struct zr_edit_box field;
};
static void
@ -41,7 +42,7 @@ zr_labelf(struct zr_context *panel, enum zr_text_align align, const char *fmt, .
static int
show_test_window(struct zr_window *window, struct zr_style *config, enum theme *theme,
struct zr_edit_box *edit_box)
struct zr_edit_box *edit_field, struct zr_edit_box *edit_box)
{
zr_flags ret;
struct zr_context layout;
@ -576,7 +577,7 @@ show_test_window(struct zr_window *window, struct zr_style *config, enum theme *
/* progressbar combobox */
sum = x + y + z + w;
sprintf(buffer, "%" PRIu64, sum);
sprintf(buffer, "%lu", sum);
zr_combo_begin(&layout, &combo, buffer, &prog_active);
{
zr_layout_row_dynamic(&combo, 30, 1);
@ -589,7 +590,7 @@ show_test_window(struct zr_window *window, struct zr_style *config, enum theme *
/* checkbox combobox */
sum = (size_t)(check_values[0] + check_values[1] + check_values[2] + check_values[3] + check_values[4]);
sprintf(buffer, "%" PRIu64, sum);
sprintf(buffer, "%lu", sum);
zr_combo_begin(&layout, &combo, buffer, &check_active);
{
zr_layout_row_dynamic(&combo, 30, 1);
@ -623,12 +624,21 @@ show_test_window(struct zr_window *window, struct zr_style *config, enum theme *
zr_edit(&layout, text[5], &text_len[5], 64, &text_active[5], &text_cursor[5], ZR_INPUT_OCT);
zr_label(&layout, "Binary:", ZR_TEXT_LEFT);
zr_edit(&layout, text[6], &text_len[6], 64, &text_active[6], &text_cursor[6], ZR_INPUT_BIN);
zr_label(&layout, "Editbox:", ZR_TEXT_LEFT);
zr_editbox(&layout, edit_box);
zr_label(&layout, "Field:", ZR_TEXT_LEFT);
zr_edit_field(&layout, edit_field);
zr_label(&layout, "Box:", ZR_TEXT_LEFT);
zr_layout_row_static(&layout, 75, 228, 1);
zr_edit_box(&layout, edit_box, ZR_MODIFYABLE);
zr_layout_row(&layout, ZR_STATIC, 25, 2, ratio);
zr_edit(&layout, text[7], &text_len[7], 64, &text_active[7], &text_cursor[7], ZR_INPUT_ASCII);
if (zr_button_text(&layout, "Submit", ZR_BUTTON_DEFAULT)
||(text_active[7] && zr_input_is_key_pressed(window->input, ZR_KEY_ENTER))) {
text[7][text_len[7]] = '\n';
text_len[7]++;
zr_edit_box_add(edit_box, text[7], text_len[7]);
text_active[7] = 0;
text_cursor[7] = 0;
text_len[7] = 0;
@ -1003,8 +1013,18 @@ init_demo(struct demo *gui)
clip.userdata.ptr = 0;
clip.paste = paste_callback;
clip.copy = copy_callback;
zr_edit_box_init_fixed(&gui->text, text, 64, &clip, 0);
zr_edit_box_init_fixed(&gui->text, text, sizeof(text), &clip, 0);
}
{
/* edit field */
static char field[512];
struct zr_clipboard clip;
clip.userdata.ptr = 0;
clip.paste = paste_callback;
clip.copy = copy_callback;
zr_edit_box_init_fixed(&gui->field, field, sizeof(field), &clip, 0);
}
}
static void
@ -1012,7 +1032,7 @@ run_demo(struct demo *gui)
{
struct zr_context layout;
struct zr_style *current = (gui->theme == THEME_BLACK) ? &gui->config_black : &gui->config_white;
gui->running = show_test_window(&gui->panel, current, &gui->theme, &gui->text);
gui->running = show_test_window(&gui->panel, current, &gui->theme, &gui->text, &gui->field);
/* ussage example */
gui->sub.style = current;

View File

@ -393,6 +393,8 @@ input_key(GLFWwindow *window, int key, int scancode, int action, int mods)
zr_input_key(&gui.input, ZR_KEY_DEL, down);
else if (key == GLFW_KEY_ENTER)
zr_input_key(&gui.input, ZR_KEY_ENTER, down);
else if (key == GLFW_KEY_TAB)
zr_input_key(&gui.input, ZR_KEY_TAB, down);
else if (key == GLFW_KEY_BACKSPACE)
zr_input_key(&gui.input, ZR_KEY_BACKSPACE, down);
else if (key == GLFW_KEY_LEFT)

View File

@ -379,6 +379,8 @@ input_key(struct zr_input *in, SDL_Event *evt, int down)
zr_input_key(in, ZR_KEY_DEL, down);
else if (sym == SDLK_RETURN)
zr_input_key(in, ZR_KEY_ENTER, down);
else if (sym == SDLK_TAB)
zr_input_key(in, ZR_KEY_TAB, down);
else if (sym == SDLK_BACKSPACE)
zr_input_key(in, ZR_KEY_BACKSPACE, down);
else if (sym == SDLK_LEFT)

View File

@ -367,6 +367,8 @@ input_key(struct XWindow *xw, struct zr_input *in, XEvent *evt, int down)
zr_input_key(in, ZR_KEY_DEL, down);
else if (*code == XK_Return)
zr_input_key(in, ZR_KEY_ENTER, down);
else if (*code == XK_Tab)
zr_input_key(in, ZR_KEY_TAB, down);
else if (*code == XK_space && !down)
zr_input_char(in, ' ');
else if (*code == XK_Left)

1190
zahnrad.c

File diff suppressed because it is too large Load Diff

View File

@ -240,6 +240,7 @@ enum zr_keys {
ZR_KEY_SHIFT,
ZR_KEY_DEL,
ZR_KEY_ENTER,
ZR_KEY_TAB,
ZR_KEY_BACKSPACE,
ZR_KEY_COPY,
ZR_KEY_CUT,
@ -1593,7 +1594,7 @@ const struct zr_font_glyph* zr_font_find_glyph(struct zr_font*, zr_rune unicode)
/*
* ===============================================================
*
* EDITBOX
* EDIT BOX
*
* ===============================================================
*/
@ -1668,6 +1669,9 @@ struct zr_edit_box {
/* input filter callback */
struct zr_selection sel;
/* text selection */
float scrollbar;
/* edit field scrollbar */
int text_inserted;
};
/* filter function */
@ -2060,7 +2064,7 @@ const char *zr_style_property_name(enum zr_style_properties);
*
* WINDOW
*
* ===============================================================
* =============================================================
WINDOW
The window groups widgets together and allows collective operation
on these widgets like movement, scrolling, window minimizing and closing.
@ -2113,7 +2117,7 @@ enum zr_window_flags {
ZR_WINDOW_BORDER_HEADER = ZR_FLAG(3),
/* Draws a border between window header and body */
ZR_WINDOW_MOVEABLE = ZR_FLAG(4),
/* The moveable flag inidicates that a window can be move by user input by
/* The moveable flag inidicates that a window can be moved by user input or by
* dragging the window header */
ZR_WINDOW_SCALEABLE = ZR_FLAG(5),
/* The scaleable flag indicates that a window can be scaled by user input
@ -2126,16 +2130,16 @@ enum zr_window_flags {
/* sets the window into a read only mode and does not allow input changes */
ZR_WINDOW_DYNAMIC = ZR_FLAG(9),
/* special type of window which grows up in height while being filled to a
* certain maximum height. It is mainly used for combo boxes but can be
* 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(10),
/* Removes the scrollbar from the window */
ZR_WINDOW_ACTIVE = ZR_FLAG(11),
/* INTERNAL ONLY!: marks the window as active, used by the window stack */
ZR_WINDOW_TAB = ZR_FLAG(12),
/* INTERNAL ONLY!: Marks the window as subwindow of another window(Groups/Tabs)*/
/* INTERNAL ONLY!: marks the window as subwindow of another window(Groups/Tabs)*/
ZR_WINDOW_COMBO_MENU = ZR_FLAG(13),
/* INTERNAL ONLY!: Marks the window as a combo box or menu */
/* INTERNAL ONLY!: marks the window as a combo box or menu */
ZR_WINDOW_REMOVE_ROM = ZR_FLAG(14)
/* INTERNAL ONLY!: removes the read only mode at the end of the window */
};
@ -2574,9 +2578,12 @@ void zr_layout_pop(struct zr_context*);
zr_slider_int -- integer slider widget with min,max,step value
zr_slider_float -- float slider widget with min,max,step value
zr_progress -- progressbar widget
zr_drag_float -- float value draggable
zr_drag_int -- integer value dragable
zr_edit -- edit textbox widget for text input
zr_edit_filtered -- edit textbox widget for text input with filter input
zr_editbox -- edit textbox with cursor, clipboard and filter
zr_edit_field -- edit text field with cursor, clipboard and filter
zr_edit_box -- edit text box with cursor, clipboard and filter
zr_spinner_int -- integer spinner widget with keyboard or mouse modification
zr_spinner_float -- float spinner widget with keyboard or mouse modification
*/
@ -2861,8 +2868,11 @@ void zr_progress(struct zr_context*, zr_size *cur, zr_size max, int modifyable);
Output:
- the from user input updated progressbar value if modifyable progressbar
*/
void zr_editbox(struct zr_context*, struct zr_edit_box*);
void zr_edit_field(struct zr_context*, struct zr_edit_box*);
/* this function creates an editbox with copy & paste functionality and text buffering */
void zr_edit_box(struct zr_context*, struct zr_edit_box*, int modifyable);
/* this function creates an multiline editbox with copy & paste functionality and text
buffering. NOTE: this is interhintly slow so please do not use it for heavy workloads. */
void zr_edit(struct zr_context*, char *buffer, zr_size *len, zr_size max,
int *active, zr_size *cursor, enum zr_input_filter);
/* this function creates an editbox to updated/insert user text input
@ -3062,7 +3072,7 @@ void zr_graph_end(struct zr_context *layout, struct zr_graph*);
/* --------------------------------------------------------------
*
* Group
* GROUP
*
* --------------------------------------------------------------
GROUP