added moveable cursor with inserting and removing to the editbox
This commit is contained in:
parent
13cb69388d
commit
44c89ddab9
10
demo/demo.c
10
demo/demo.c
|
@ -7,8 +7,8 @@ struct show_window {
|
|||
struct gui_panel hook;
|
||||
/* input buffer */
|
||||
gui_char input_buffer[MAX_BUFFER];
|
||||
gui_size input_length;
|
||||
gui_bool input_active;
|
||||
struct gui_edit_box input;
|
||||
|
||||
/* widgets state */
|
||||
gui_bool checkbox;
|
||||
gui_float slider;
|
||||
|
@ -114,10 +114,9 @@ widget_panel(struct gui_panel_layout *panel, struct show_window *demo)
|
|||
{
|
||||
const gui_float ratio[] = {0.7f, 0.3f};
|
||||
gui_panel_row_templated(panel, 30, 2, ratio);
|
||||
demo->input_length = gui_panel_edit(panel, demo->input_buffer, demo->input_length,
|
||||
MAX_BUFFER, &demo->input_active, GUI_INPUT_DEFAULT);
|
||||
gui_panel_editbox(panel, &demo->input);
|
||||
if (gui_panel_button_text(panel, "submit", GUI_BUTTON_DEFAULT)) {
|
||||
demo->input_length = 0;
|
||||
gui_edit_box_reset(&demo->input);
|
||||
fprintf(stdout, "command executed!\n");
|
||||
}
|
||||
}
|
||||
|
@ -177,6 +176,7 @@ init_show(struct show_window *win, struct gui_config *config,
|
|||
GUI_PANEL_CLOSEABLE|GUI_PANEL_SCALEABLE|
|
||||
GUI_PANEL_MINIMIZABLE|GUI_PANEL_HIDDEN, buffer, config);
|
||||
gui_stack_push(stack, &win->hook);
|
||||
gui_edit_box_init_fixed(&win->input, win->input_buffer, MAX_BUFFER, NULL, NULL);
|
||||
|
||||
win->widget_tab = GUI_MINIMIZED;
|
||||
win->combobox_tab = GUI_MINIMIZED;
|
||||
|
|
|
@ -262,13 +262,26 @@ font_get_text_width(gui_handle handle, const gui_char *t, gui_size l)
|
|||
}
|
||||
|
||||
static void
|
||||
font_draw_text(const struct font *font, float x, float y, float h,
|
||||
const gui_byte *color, const char *text, size_t len)
|
||||
draw_rect(float x, float y, float w, float h, const gui_byte *c)
|
||||
{
|
||||
glColor4ub(c[0], c[1], c[2], c[3]);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(x, y);
|
||||
glVertex2f(x + w, y);
|
||||
glVertex2f(x + w, y + h);
|
||||
glVertex2f(x, y + h);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
static void
|
||||
font_draw_text(const struct font *font, float x, float y, float w, float h,
|
||||
const gui_byte *bg, const gui_byte *color, const char *text, size_t len)
|
||||
{
|
||||
size_t text_len;
|
||||
long unicode;
|
||||
const struct font_glyph *g;
|
||||
|
||||
draw_rect(x, y, w, h, bg);
|
||||
text_len = gui_utf_decode(text, &unicode, len);
|
||||
glBindTexture(GL_TEXTURE_2D, font->texture);
|
||||
glColor4ub(color[0], color[1], color[2], color[3]);
|
||||
|
@ -365,18 +378,6 @@ draw_line(float x0, float y0, float x1, float y1, const gui_byte *c)
|
|||
glEnd();
|
||||
}
|
||||
|
||||
static void
|
||||
draw_rect(float x, float y, float w, float h, const gui_byte *c)
|
||||
{
|
||||
glColor4ub(c[0], c[1], c[2], c[3]);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(x, y);
|
||||
glVertex2f(x + w, y);
|
||||
glVertex2f(x + w, y + h);
|
||||
glVertex2f(x, y + h);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
static void
|
||||
draw_circle(float x, float y, float r, const gui_byte *c)
|
||||
{
|
||||
|
@ -451,7 +452,8 @@ execute(struct gui_command_buffer *list, int width, int height)
|
|||
} break;
|
||||
case GUI_COMMAND_TEXT: {
|
||||
const struct gui_command_text *t = gui_command(text, cmd);
|
||||
font_draw_text((const struct font*)t->font.ptr, t->x, t->y, t->h, t->fg, t->string, t->length);
|
||||
font_draw_text((const struct font*)t->font.ptr, t->x, t->y, t->w, t->h,
|
||||
t->bg, t->fg, t->string, t->length);
|
||||
} break;
|
||||
case GUI_COMMAND_IMAGE:
|
||||
case GUI_COMMAND_MAX:
|
||||
|
@ -490,6 +492,10 @@ key(struct gui_input *in, SDL_Event *evt, gui_bool down)
|
|||
gui_input_key(in, GUI_KEY_SPACE, down);
|
||||
else if (sym == SDLK_BACKSPACE)
|
||||
gui_input_key(in, GUI_KEY_BACKSPACE, down);
|
||||
else if (sym == SDLK_LEFT)
|
||||
gui_input_key(in, GUI_KEY_LEFT, down);
|
||||
else if (sym == SDLK_RIGHT)
|
||||
gui_input_key(in, GUI_KEY_RIGHT, down);
|
||||
else if (state[SDL_SCANCODE_LCTRL] && state[SDL_SCANCODE_C])
|
||||
gui_input_key(in, GUI_KEY_COPY, down);
|
||||
else if (state[SDL_SCANCODE_LCTRL] && state[SDL_SCANCODE_P])
|
||||
|
|
|
@ -390,6 +390,10 @@ key(struct XWindow *xw, struct gui_input *in, XEvent *evt, gui_bool down)
|
|||
gui_input_key(in, GUI_KEY_ENTER, down);
|
||||
else if (*code == XK_space)
|
||||
gui_input_key(in, GUI_KEY_SPACE, down);
|
||||
else if (*code == XK_Left)
|
||||
gui_input_key(in, GUI_KEY_LEFT, down);
|
||||
else if (*code == XK_Right)
|
||||
gui_input_key(in, GUI_KEY_RIGHT, down);
|
||||
else if (*code == XK_BackSpace)
|
||||
gui_input_key(in, GUI_KEY_BACKSPACE, down);
|
||||
else if (*code > 32 && *code < 128 && !down) {
|
||||
|
|
243
gui.c
243
gui.c
|
@ -42,7 +42,7 @@ template<typename T> struct gui_alignof{struct Big {T x; char c;}; enum {
|
|||
#endif
|
||||
|
||||
|
||||
#define GUI_ALIGN_PTR(x, mask) (void*)((gui_size)((gui_byte*)(x) + (mask-1)) & ~(mask-1))
|
||||
#define GUI_ALIGN_PTR(x, mask) (void*)((gui_ptr)((gui_byte*)(x) + (mask-1)) & ~(mask-1))
|
||||
#define GUI_ALIGN(x, mask) ((x) + (mask-1)) & ~(mask-1)
|
||||
#define GUI_OFFSETOF(st, m) ((gui_size)(&((st *)0)->m))
|
||||
|
||||
|
@ -345,6 +345,28 @@ gui_utf_encode(gui_long u, gui_char *c, gui_size clen)
|
|||
return len;
|
||||
}
|
||||
|
||||
gui_size
|
||||
gui_utf_len(const gui_char *str, gui_size len)
|
||||
{
|
||||
const gui_char *text;
|
||||
gui_size text_len;
|
||||
gui_size glyph_len;
|
||||
gui_size src_len = 0;
|
||||
gui_long unicode;
|
||||
|
||||
GUI_ASSERT(str);
|
||||
if (!str || !len) return 0;
|
||||
|
||||
text = str;
|
||||
text_len = len;
|
||||
glyph_len = gui_utf_decode(text, &unicode, text_len);
|
||||
while (glyph_len && src_len < len) {
|
||||
src_len = src_len + glyph_len;
|
||||
glyph_len = gui_utf_decode(text + src_len, &unicode, text_len - src_len);
|
||||
}
|
||||
return src_len;
|
||||
}
|
||||
|
||||
void
|
||||
gui_input_begin(struct gui_input *in)
|
||||
{
|
||||
|
@ -772,8 +794,9 @@ gui_edit_buffer_append(gui_edit_buffer *buffer, const char *str, gui_size len)
|
|||
gui_memcopy(mem, str, len * sizeof(char));
|
||||
}
|
||||
|
||||
void
|
||||
gui_edit_buffer_insert(gui_edit_buffer *buffer, gui_size pos, const char *str, gui_size len)
|
||||
int
|
||||
gui_edit_buffer_insert(gui_edit_buffer *buffer, gui_size pos,
|
||||
const char *str, gui_size len)
|
||||
{
|
||||
void *mem;
|
||||
gui_size i;
|
||||
|
@ -781,23 +804,24 @@ gui_edit_buffer_insert(gui_edit_buffer *buffer, gui_size pos, const char *str, g
|
|||
|
||||
gui_size copylen;
|
||||
GUI_ASSERT(buffer);
|
||||
if (!buffer || !str || !len || pos > buffer->allocated) return;
|
||||
if (!buffer || !str || !len || pos > buffer->allocated) return 0;
|
||||
|
||||
copylen = buffer->allocated - pos;
|
||||
if (!copylen) {
|
||||
gui_edit_buffer_append(buffer, str, len);
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* memmove */
|
||||
mem = gui_buffer_alloc(buffer, len * sizeof(char), 0);
|
||||
if (!mem) return;
|
||||
dst = gui_ptr_add(char, buffer->memory.ptr, pos + len + copylen);
|
||||
src = gui_ptr_add(char, buffer->memory.ptr, pos + copylen);
|
||||
for (i = 0; i < len; ++i)
|
||||
if (!mem) return 0;
|
||||
dst = gui_ptr_add(char, buffer->memory.ptr, pos + len + (copylen - 1));
|
||||
src = gui_ptr_add(char, buffer->memory.ptr, pos + (copylen-1));
|
||||
for (i = 0; i < copylen; ++i)
|
||||
*dst-- = *src--;
|
||||
mem = gui_ptr_add(void, buffer->memory.ptr, pos);
|
||||
gui_memcopy(mem, str, len * sizeof(char));
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -816,20 +840,59 @@ gui_edit_buffer_del(gui_edit_buffer *buffer, gui_size pos, gui_size len)
|
|||
if (!buffer || !len || pos > buffer->allocated ||
|
||||
pos + len > buffer->allocated) return;
|
||||
|
||||
/* memmove */
|
||||
dst = gui_ptr_add(char, buffer->memory.ptr, pos);
|
||||
src = gui_ptr_add(char, buffer->memory.ptr, pos + len);
|
||||
gui_memcopy(dst, src, len * sizeof(char));
|
||||
if (pos + len < buffer->allocated) {
|
||||
/* memmove */
|
||||
dst = gui_ptr_add(char, buffer->memory.ptr, pos);
|
||||
src = gui_ptr_add(char, buffer->memory.ptr, pos + len);
|
||||
gui_memcopy(dst, src, buffer->allocated - (pos + len));
|
||||
buffer->allocated -= len;
|
||||
} else gui_edit_buffer_remove(buffer, len);
|
||||
}
|
||||
|
||||
char*
|
||||
gui_edit_buffer_at(gui_edit_buffer *buffer, gui_size pos)
|
||||
gui_edit_buffer_at_char(gui_edit_buffer *buffer, gui_size pos)
|
||||
{
|
||||
GUI_ASSERT(buffer);
|
||||
if (!buffer || pos > buffer->allocated) return 0;
|
||||
return gui_ptr_add(char, buffer->memory.ptr, pos);
|
||||
}
|
||||
|
||||
char*
|
||||
gui_edit_buffer_at(gui_edit_buffer *buffer, gui_int pos, gui_long *unicode,
|
||||
gui_size *len)
|
||||
{
|
||||
gui_int i = 0;
|
||||
gui_size src_len = 0;
|
||||
gui_size glyph_len = 0;
|
||||
gui_char *text;
|
||||
gui_size text_len;
|
||||
|
||||
GUI_ASSERT(buffer);
|
||||
GUI_ASSERT(unicode);
|
||||
GUI_ASSERT(len);
|
||||
if (!buffer || !unicode || !len) return 0;
|
||||
if (pos < 0) {
|
||||
*unicode = 0;
|
||||
*len = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
text = buffer->memory.ptr;
|
||||
text_len = buffer->allocated;
|
||||
glyph_len = gui_utf_decode(text, unicode, text_len);
|
||||
while (glyph_len) {
|
||||
if (i == pos) {
|
||||
*len = glyph_len;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
src_len = src_len + glyph_len;
|
||||
glyph_len = gui_utf_decode(text + src_len, unicode, text_len - src_len);
|
||||
}
|
||||
if (i != pos) return 0;
|
||||
return text + src_len;
|
||||
}
|
||||
|
||||
void
|
||||
gui_edit_box_init(struct gui_edit_box *eb, struct gui_allocator *a, gui_size initial_size,
|
||||
gui_float grow_fac, const struct gui_clipboard *clip, gui_filter f)
|
||||
|
@ -842,7 +905,10 @@ gui_edit_box_init(struct gui_edit_box *eb, struct gui_allocator *a, gui_size ini
|
|||
gui_zero(eb, sizeof(*eb));
|
||||
gui_buffer_init(&eb->buffer, a, initial_size, grow_fac);
|
||||
if (clip) eb->clip = *clip;
|
||||
eb->filter = f;
|
||||
if (f) eb->filter = f;
|
||||
else eb->filter = gui_filter_input_default;
|
||||
eb->cursor = 0;
|
||||
eb->glyphes = 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -858,15 +924,32 @@ gui_edit_box_init_fixed(struct gui_edit_box *eb, void *memory, gui_size size,
|
|||
gui_zero(eb, sizeof(*eb));
|
||||
gui_buffer_init_fixed(&eb->buffer, memory, size);
|
||||
if (clip) eb->clip = *clip;
|
||||
eb->filter = f;
|
||||
if (f) eb->filter = f;
|
||||
else eb->filter = gui_filter_input_default;
|
||||
eb->cursor = 0;
|
||||
eb->glyphes = 0;
|
||||
}
|
||||
|
||||
void
|
||||
gui_edit_box_add(struct gui_edit_box *eb, const char *str, gui_size len)
|
||||
{
|
||||
gui_int res = 0;
|
||||
GUI_ASSERT(eb);
|
||||
if (!eb || !str || !len) return;
|
||||
gui_edit_buffer_insert(&eb->buffer, eb->buffer.allocated, str, len);
|
||||
if (eb->cursor == eb->glyphes) {
|
||||
res = gui_edit_buffer_insert(&eb->buffer, eb->buffer.allocated, str, len);
|
||||
} else {
|
||||
gui_size l = 0;
|
||||
gui_long unicode;
|
||||
gui_int cursor = (eb->cursor) ? (gui_int)(eb->cursor) : 0;
|
||||
gui_char *sym = gui_edit_buffer_at(&eb->buffer, cursor, &unicode, &l);
|
||||
gui_size offset = (gui_size)(sym - (gui_char*)eb->buffer.memory.ptr);
|
||||
res = gui_edit_buffer_insert(&eb->buffer, offset, str, len);
|
||||
}
|
||||
if (res) {
|
||||
eb->cursor++;
|
||||
eb->glyphes++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -875,8 +958,10 @@ gui_edit_box_buffer_input(struct gui_edit_box *box, const struct gui_input *i)
|
|||
gui_long unicode;
|
||||
gui_size src_len = 0;
|
||||
gui_size text_len = 0, glyph_len = 0;
|
||||
|
||||
GUI_ASSERT(buffer);
|
||||
GUI_ASSERT(i);
|
||||
if (!box || !i) return;
|
||||
|
||||
/* add user provided text to buffer until either no input or buffer space left*/
|
||||
glyph_len = gui_utf_decode(i->text, &unicode, i->text_len);
|
||||
|
@ -897,34 +982,98 @@ void
|
|||
gui_edit_box_remove(struct gui_edit_box *eb)
|
||||
{
|
||||
gui_long unicode;
|
||||
gui_size src_len = 0;
|
||||
gui_size last_glyph = 0;
|
||||
gui_size glyph_len = 0;
|
||||
gui_char *text = gui_edit_box_get(eb);
|
||||
gui_size text_len = gui_edit_box_len(eb);
|
||||
GUI_ASSERT(eb);
|
||||
gui_size len;
|
||||
gui_int cursor;
|
||||
gui_char *glyph;
|
||||
gui_size offset;
|
||||
|
||||
glyph_len = gui_utf_decode(text, &unicode, text_len);
|
||||
while (glyph_len) {
|
||||
src_len = src_len + glyph_len;
|
||||
last_glyph = glyph_len;
|
||||
glyph_len = gui_utf_decode(text + src_len, &unicode, text_len - src_len);
|
||||
}
|
||||
gui_edit_buffer_remove(&eb->buffer, last_glyph);
|
||||
GUI_ASSERT(eb);
|
||||
if (!eb) return;
|
||||
|
||||
cursor = (gui_int)eb->cursor - 1;
|
||||
glyph = gui_edit_buffer_at(&eb->buffer, cursor, &unicode, &len);
|
||||
if (!glyph || !len) return;
|
||||
offset = (gui_size)(glyph - (gui_char*)eb->buffer.memory.ptr);
|
||||
gui_edit_buffer_del(&eb->buffer, offset, len);
|
||||
eb->cursor--;
|
||||
eb->glyphes--;
|
||||
}
|
||||
|
||||
gui_char*
|
||||
gui_edit_box_get(struct gui_edit_box *eb)
|
||||
{
|
||||
GUI_ASSERT(eb);
|
||||
if (!eb) return 0;
|
||||
return (gui_char*)eb->buffer.memory.ptr;
|
||||
}
|
||||
|
||||
const gui_char*
|
||||
gui_edit_box_get_const(struct gui_edit_box *eb)
|
||||
{
|
||||
GUI_ASSERT(eb);
|
||||
if (!eb) return 0;
|
||||
return (gui_char*)eb->buffer.memory.ptr;
|
||||
}
|
||||
|
||||
gui_char
|
||||
gui_edit_box_at_byte(struct gui_edit_box *eb, gui_size pos)
|
||||
{
|
||||
gui_char *c;
|
||||
GUI_ASSERT(eb);
|
||||
if (!eb || pos >= eb->buffer.allocated) return 0;
|
||||
c = gui_edit_buffer_at_char(&eb->buffer, pos);
|
||||
return c ? *c : 0;
|
||||
}
|
||||
|
||||
void
|
||||
gui_edit_box_at(struct gui_edit_box *eb, gui_size pos, gui_glyph g, gui_size *len)
|
||||
{
|
||||
gui_char *sym;
|
||||
gui_long unicode;
|
||||
|
||||
GUI_ASSERT(eb);
|
||||
GUI_ASSERT(g);
|
||||
GUI_ASSERT(len);
|
||||
|
||||
if (!eb || !len || !g) return;
|
||||
if (pos >= eb->glyphes) {
|
||||
*len = 0;
|
||||
return;
|
||||
}
|
||||
sym = gui_edit_buffer_at(&eb->buffer, (gui_int)pos, &unicode, len);
|
||||
if (!sym) return;
|
||||
gui_memcopy(g, sym, *len);
|
||||
}
|
||||
|
||||
void
|
||||
gui_edit_box_at_cursor(struct gui_edit_box *eb, gui_glyph g, gui_size *len)
|
||||
{
|
||||
gui_size cursor = 0;
|
||||
GUI_ASSERT(eb);
|
||||
GUI_ASSERT(g);
|
||||
GUI_ASSERT(len);
|
||||
|
||||
if (!eb || !g || !len) return;
|
||||
if (!eb->cursor) {
|
||||
*len = 0;
|
||||
return;
|
||||
}
|
||||
cursor = (eb->cursor) ? eb->cursor-1 : 0;
|
||||
gui_edit_box_at(eb, 0, g, len);
|
||||
}
|
||||
|
||||
gui_size
|
||||
gui_edit_box_len_byte(struct gui_edit_box *eb)
|
||||
{
|
||||
GUI_ASSERT(eb);
|
||||
return eb->buffer.allocated;
|
||||
}
|
||||
|
||||
gui_size
|
||||
gui_edit_box_len(struct gui_edit_box *eb)
|
||||
{
|
||||
GUI_ASSERT(eb);
|
||||
return eb->buffer.allocated;
|
||||
return eb->glyphes;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1114,9 +1263,7 @@ gui_button_text_triangle(struct gui_command_buffer *out, gui_float x, gui_float
|
|||
if (align == GUI_TEXT_LEFT) {
|
||||
tri.x = (x + w) - (2 * button->padding.x + tri.w);
|
||||
tri.x = MAX(tri.x, 0);
|
||||
} else if (align == GUI_TEXT_RIGHT) {
|
||||
tri.x = x + 2 * button->padding.x;
|
||||
}
|
||||
} else tri.x = x + 2 * button->padding.x;
|
||||
|
||||
col = (i && GUI_INBOX(i->mouse_pos.x, i->mouse_pos.y, x, y, w, h)) ?
|
||||
button->highlight_content : button->content;
|
||||
|
@ -1149,9 +1296,7 @@ gui_button_text_image(struct gui_command_buffer *out, gui_float x, gui_float y,
|
|||
if (align == GUI_TEXT_LEFT) {
|
||||
icon.x = (x + w) - (2 * button->padding.x + icon.w);
|
||||
icon.x = MAX(icon.x, 0);
|
||||
} else if (align == GUI_TEXT_RIGHT) {
|
||||
icon.x = x + 2 * button->padding.x;
|
||||
} else return gui_false;
|
||||
} else icon.x = x + 2 * button->padding.x;
|
||||
gui_command_buffer_push_image(out, icon.x, icon.y, icon.w, icon.h, &img);
|
||||
return pressed;
|
||||
}
|
||||
|
@ -1393,6 +1538,8 @@ gui_editbox(struct gui_command_buffer *out, gui_float x, gui_float y, gui_float
|
|||
const struct gui_key *space = &in->keys[GUI_KEY_SPACE];
|
||||
const struct gui_key *copy = &in->keys[GUI_KEY_COPY];
|
||||
const struct gui_key *paste = &in->keys[GUI_KEY_PASTE];
|
||||
const struct gui_key *left = &in->keys[GUI_KEY_LEFT];
|
||||
const struct gui_key *right = &in->keys[GUI_KEY_RIGHT];
|
||||
|
||||
/* update input buffer by user input */
|
||||
if ((del->down && del->clicked) || (bs->down && bs->clicked))
|
||||
|
@ -1405,6 +1552,10 @@ gui_editbox(struct gui_command_buffer *out, gui_float x, gui_float y, gui_float
|
|||
box->buffer.allocated = box->clip.paste(box->clip.userdata, buffer, max);
|
||||
if (space->down && space->clicked)
|
||||
gui_edit_box_add(box, " ", 1);
|
||||
if (left->down && left->clicked)
|
||||
box->cursor = (gui_size)MAX(0, (gui_int)box->cursor-1);
|
||||
if (right->down && right->clicked)
|
||||
box->cursor = MIN((!box->glyphes) ? 0 : box->glyphes, box->cursor+1);
|
||||
if (in->text_len)
|
||||
gui_edit_box_buffer_input(box, in);
|
||||
}
|
||||
|
@ -1435,8 +1586,19 @@ gui_editbox(struct gui_command_buffer *out, gui_float x, gui_float y, gui_float
|
|||
|
||||
/* if wanted draw the cursor at the end of the text input */
|
||||
if (box->active && field->show_cursor) {
|
||||
gui_command_buffer_push_rect(out, label_x + (gui_float)text_width, label_y,
|
||||
if (box->cursor == box->glyphes) {
|
||||
gui_command_buffer_push_rect(out, label_x + (gui_float)text_width, label_y,
|
||||
(gui_float)cursor_w, label_h, 0, field->cursor);
|
||||
} else {
|
||||
gui_size l;
|
||||
gui_long unicode;
|
||||
const gui_char *cursor = gui_edit_buffer_at(&box->buffer, (gui_int)box->cursor, &unicode, &l);
|
||||
gui_size off = (gui_size)(cursor - (gui_char*)box->buffer.memory.ptr);
|
||||
label_x += font->width(font->userdata, buffer, off);
|
||||
label_w = font->width(font->userdata, cursor, l);
|
||||
gui_command_buffer_push_text(out , label_x, label_y, label_w, label_h,
|
||||
cursor, l, font, field->cursor, field->background);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1508,6 +1670,8 @@ gui_edit_filtered(struct gui_command_buffer *out, gui_float x, gui_float y, gui_
|
|||
gui_edit_box_init_fixed(&box, buffer, max, 0, filter);
|
||||
box.buffer.allocated = len;
|
||||
box.active = *active;
|
||||
box.glyphes = gui_utf_len(buffer, len);
|
||||
box.cursor = box.glyphes;
|
||||
gui_editbox(out, x, y, w, h, &box, field, in, font);
|
||||
*active = box.active;
|
||||
return gui_edit_box_len(&box);
|
||||
|
@ -3471,7 +3635,8 @@ gui_panel_tab_begin(struct gui_panel_layout *parent, struct gui_panel_layout *ta
|
|||
|
||||
/* create a fake panel to create a panel layout from */
|
||||
flags = GUI_PANEL_BORDER|GUI_PANEL_MINIMIZABLE|GUI_PANEL_TAB|GUI_PANEL_BORDER_HEADER;
|
||||
gui_panel_init(&panel,bounds.x,bounds.y,bounds.w,gui_null_rect.h,flags,out,parent->config);
|
||||
gui_panel_init(&panel, bounds.x, bounds.y, bounds.w,
|
||||
gui_null_rect.h,flags,out,parent->config);
|
||||
panel.minimized = minimized;
|
||||
gui_panel_begin(tab, &panel, title, parent->input);
|
||||
|
||||
|
|
24
gui.h
24
gui.h
|
@ -55,6 +55,7 @@ typedef uint32_t gui_flags;
|
|||
typedef uint8_t gui_byte;
|
||||
typedef uint32_t gui_flag;
|
||||
typedef uint64_t gui_size;
|
||||
typedef uintptr_t gui_ptr;
|
||||
#else
|
||||
typedef int gui_int;
|
||||
typedef int gui_bool;
|
||||
|
@ -69,6 +70,7 @@ typedef unsigned int gui_flags;
|
|||
typedef unsigned char gui_byte;
|
||||
typedef unsigned int gui_flag;
|
||||
typedef unsigned long gui_size;
|
||||
typedef unsigned long gui_ptr;
|
||||
#endif
|
||||
|
||||
/* Utilities */
|
||||
|
@ -120,6 +122,7 @@ typedef void(*gui_copy_f)(gui_handle, const char*, gui_size size);
|
|||
struct gui_rect gui_get_null_rect(void);
|
||||
gui_size gui_utf_decode(const gui_char*, gui_long*, gui_size);
|
||||
gui_size gui_utf_encode(gui_long, gui_char*, gui_size);
|
||||
gui_size gui_utf_len(const gui_char*, gui_size len);
|
||||
struct gui_image gui_image_ptr(void*);
|
||||
struct gui_image gui_image_id(gui_int);
|
||||
struct gui_image gui_subimage_ptr(void*, struct gui_rect);
|
||||
|
@ -201,6 +204,8 @@ enum gui_keys {
|
|||
GUI_KEY_SPACE,
|
||||
GUI_KEY_COPY,
|
||||
GUI_KEY_PASTE,
|
||||
GUI_KEY_LEFT,
|
||||
GUI_KEY_RIGHT,
|
||||
GUI_KEY_MAX
|
||||
};
|
||||
|
||||
|
@ -717,10 +722,11 @@ void gui_command_buffer_push_text(struct gui_command_buffer*, gui_float, gui_flo
|
|||
*/
|
||||
typedef struct gui_buffer gui_edit_buffer;
|
||||
void gui_edit_buffer_append(gui_edit_buffer*, const char*, gui_size);
|
||||
void gui_edit_buffer_insert(gui_edit_buffer*, gui_size pos, const char*, gui_size);
|
||||
int gui_edit_buffer_insert(gui_edit_buffer*, gui_size pos, const char*, gui_size);
|
||||
void gui_edit_buffer_remove(gui_edit_buffer*, gui_size);
|
||||
void gui_edit_buffer_del(gui_edit_buffer*, gui_size pos, gui_size len);
|
||||
char *gui_edit_buffer_at(gui_edit_buffer*, gui_size pos);
|
||||
char *gui_edit_buffer_at_char(gui_edit_buffer*, gui_size pos);
|
||||
char* gui_edit_buffer_at(gui_edit_buffer*, gui_int, gui_long*, gui_size*);
|
||||
|
||||
/*
|
||||
* ==============================================================
|
||||
|
@ -762,6 +768,8 @@ struct gui_clipboard {
|
|||
struct gui_edit_box {
|
||||
gui_edit_buffer buffer;
|
||||
gui_bool active;
|
||||
gui_size cursor;
|
||||
gui_size glyphes;
|
||||
struct gui_clipboard clip;
|
||||
gui_filter filter;
|
||||
};
|
||||
|
@ -775,15 +783,22 @@ gui_bool gui_filter_input_hex(gui_long unicode);
|
|||
gui_bool gui_filter_input_oct(gui_long unicode);
|
||||
gui_bool gui_filter_input_binary(gui_long unicode);
|
||||
|
||||
/* editbox */
|
||||
void gui_edit_box_init(struct gui_edit_box*, struct gui_allocator*, gui_size initial,
|
||||
gui_float grow_fac, const struct gui_clipboard*, gui_filter);
|
||||
void gui_edit_box_init_fixed(struct gui_edit_box*, void *memory, gui_size size,
|
||||
const struct gui_clipboard*, gui_filter);
|
||||
#define gui_edit_box_reset(b) gui_buffer_reset(&(b)->buffer)
|
||||
#define gui_edit_box_reset(b)\
|
||||
do {gui_buffer_reset(&(b)->buffer); (b)->cursor = (b)->glyphes = 0;} while(0);
|
||||
#define gui_edit_box_clear(b) gui_buffer_clear(&(b)->buffer)
|
||||
void gui_edit_box_add(struct gui_edit_box*, const char*, gui_size);
|
||||
void gui_edit_box_remove(struct gui_edit_box*);
|
||||
gui_char *gui_edit_box_get(struct gui_edit_box*);
|
||||
const gui_char *gui_edit_box_get_const(struct gui_edit_box*);
|
||||
gui_char gui_edit_box_at_byte(struct gui_edit_box*, gui_size pos);
|
||||
void gui_edit_box_at(struct gui_edit_box*, gui_size pos, gui_glyph, gui_size*);
|
||||
void gui_edit_box_at_cursor(struct gui_edit_box*, gui_glyph, gui_size*);
|
||||
gui_size gui_edit_box_len_byte(struct gui_edit_box*);
|
||||
gui_size gui_edit_box_len(struct gui_edit_box*);
|
||||
/*
|
||||
* ==============================================================
|
||||
|
@ -1327,6 +1342,7 @@ gui_float gui_scroll(struct gui_command_buffer*, gui_float x, gui_float y,
|
|||
|
||||
Configuration function API
|
||||
gui_config_default -- initializes a default panel configuration
|
||||
gui_config_set_font -- changes the used font
|
||||
gui_config_property -- returns the property value from an id
|
||||
gui_config_color -- returns the color value from an id
|
||||
gui_config_push_property -- push an old property onto a interal stack and sets a new value
|
||||
|
@ -1467,7 +1483,7 @@ void gui_config_default(struct gui_config*, gui_flags, const struct gui_font*);
|
|||
- configuration structure holding the default panel style
|
||||
*/
|
||||
void gui_config_set_font(struct gui_config*, const struct gui_font*);
|
||||
/* this function changes the used font
|
||||
/* this function changes the used font and can be used even inside a frame
|
||||
Input:
|
||||
- user font reference structure describing the font used inside the panel
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue