fixed input widget bug
This commit is contained in:
parent
00d08896f4
commit
8565b10159
@ -35,7 +35,7 @@ while (1) {
|
||||
/* record input */
|
||||
gui_input_end(&input);
|
||||
|
||||
if (gui_button_text(&canvas, 0, 0, 100, 30, &style, "ok", GUI_BUTTON_DEFAULT, &input))
|
||||
if(gui_button_text(&canvas, 0, 0, 100, 30, &style, "ok", GUI_BUTTON_DEFAULT, &input))
|
||||
fprintf(stdout, "button pressed!\n");
|
||||
}
|
||||
```
|
||||
|
13
demo/xlib.c
13
demo/xlib.c
@ -379,22 +379,22 @@ resize(struct XWindow *xw, XSurface *surf)
|
||||
static void
|
||||
demo_panel(struct gui_panel *panel, struct demo *demo)
|
||||
{
|
||||
gui_int i = 0;
|
||||
enum {HISTO, PLOT};
|
||||
const char *shelfs[] = {"Histogram", "Lines"};
|
||||
const gui_float values[] = {8.0f, 15.0f, 20.0f, 12.0f, 30.0f};
|
||||
const char *items[] = {"Fist", "Pistol", "Shotgun", "Railgun", "BFG"};
|
||||
const char *options[] = {"easy", "normal", "hard", "hell", "doom", "godlike"};
|
||||
struct gui_panel tab;
|
||||
|
||||
/* Tabs */
|
||||
gui_panel_layout(panel, 100, 1);
|
||||
demo->tab_minimized = gui_panel_tab_begin(panel, &tab, "Difficulty", demo->tab_minimized);
|
||||
gui_panel_layout(&tab, 30, 3);
|
||||
if (gui_panel_option(&tab, "easy", demo->option == 0)) demo->option = 0;
|
||||
if (gui_panel_option(&tab, "normal", demo->option == 1)) demo->option = 1;
|
||||
if (gui_panel_option(&tab, "hard", demo->option == 2)) demo->option = 2;
|
||||
if (gui_panel_option(&tab, "hell", demo->option == 3)) demo->option = 3;
|
||||
if (gui_panel_option(&tab, "doom", demo->option == 4)) demo->option = 4;
|
||||
if (gui_panel_option(&tab, "godlike", demo->option == 5)) demo->option = 5;
|
||||
for (i = 0; i < (gui_int)LEN(options); i++) {
|
||||
if (gui_panel_option(&tab, options[i], demo->option == i))
|
||||
demo->option = i;
|
||||
}
|
||||
gui_panel_tab_end(panel, &tab);
|
||||
|
||||
/* Shelf */
|
||||
@ -418,6 +418,7 @@ demo_panel(struct gui_panel *panel, struct demo *demo)
|
||||
demo->prog = gui_panel_progress(&tab, demo->prog, 100, gui_true);
|
||||
demo->item_cur = gui_panel_selector(&tab, items, LEN(items), demo->item_cur);
|
||||
demo->spin_act = gui_panel_spinner(&tab, 0, &demo->spinner, 250, 10, demo->spin_act);
|
||||
demo->in_len = gui_panel_input(&tab, demo->in_buf, demo->in_len, MAX_BUFFER, &demo->in_act, GUI_INPUT_DEFAULT);
|
||||
demo->group_offset = gui_panel_group_end(panel, &tab);
|
||||
}
|
||||
|
||||
|
6
gui.c
6
gui.c
@ -660,7 +660,7 @@ gui_buffer_input(gui_char *buffer, gui_size length, gui_size max,
|
||||
assert(in);
|
||||
|
||||
glyph_len = utf_decode(in->text, &unicode, in->text_len);
|
||||
while (glyph_len && (text_len + glyph_len) <= in->text_len && (length + text_len) < max) {
|
||||
while (glyph_len && ((text_len + glyph_len) <= in->text_len) && (length + text_len) < max) {
|
||||
if (gui_filter_input(unicode, glyph_len, filter)) {
|
||||
gui_size i = 0;
|
||||
for (i = 0; i < glyph_len; i++)
|
||||
@ -714,7 +714,7 @@ gui_input(const struct gui_canvas *canvas, gui_float x, gui_float y, gui_float w
|
||||
len += gui_buffer_input(buffer, len, max, field->filter, in);
|
||||
}
|
||||
|
||||
if (font && buffer && len) {
|
||||
if (font && buffer) {
|
||||
gui_size offset = 0;
|
||||
gui_float label_x, label_y, label_h;
|
||||
gui_float label_w = input_w - 2 * field->padding.x;
|
||||
@ -725,7 +725,7 @@ gui_input(const struct gui_canvas *canvas, gui_float x, gui_float y, gui_float w
|
||||
while (text_len && (text_width + cursor_width) > (gui_size)label_w) {
|
||||
gui_long unicode;
|
||||
offset += utf_decode(&buffer[offset], &unicode, text_len);
|
||||
text_len -= offset;
|
||||
text_len = len - offset;
|
||||
text_width = font->width(font->userdata, &buffer[offset], text_len);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user