summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik.ramaekers@protonmail.com>2020-02-04 15:21:28 +0100
committerAldrik Ramaekers <aldrik.ramaekers@protonmail.com>2020-02-04 15:21:28 +0100
commit976f6e0df372ccced14f7baca903ec9e483c89ae (patch)
tree137deb3e080c5ae78f764977bcd9ccd9b89fc04f /src
parente271c4518fd02c8dac2343ef0b9fd2cecd0812be (diff)
improve textbox
Diffstat (limited to 'src')
-rw-r--r--src/input.c60
-rw-r--r--src/ui.c12
2 files changed, 61 insertions, 11 deletions
diff --git a/src/input.c b/src/input.c
index 4ee795b..cd68ba5 100644
--- a/src/input.c
+++ b/src/input.c
@@ -199,9 +199,46 @@ void keyboard_handle_input_string(platform_window *window, keyboard_input *keybo
}
}
+ if (keyboard_is_key_pressed(keyboard, KEY_X))
+ {
+ bool is_lctrl_down = keyboard->keys[KEY_LEFT_CONTROL];
+
+ if (is_lctrl_down)
+ {
+ // copy selection
+ if (keyboard->has_selection)
+ {
+ char buffer[MAX_INPUT_LENGTH];
+ utf8_str_copy_range(keyboard->input_text,
+ keyboard->selection_begin_offset,
+ keyboard->selection_begin_offset+keyboard->selection_length,
+ buffer);
+
+ if (!string_equals(buffer, ""))
+ platform_set_clipboard(window, buffer);
+ }
+
+ // delete selection
+ if (keyboard->has_selection)
+ {
+ utf8_str_remove_range(keyboard->input_text, keyboard->selection_begin_offset,
+ keyboard->selection_begin_offset + keyboard->selection_length);
+ keyboard->has_selection = false;
+ keyboard->text_changed = true;
+
+ if (keyboard->selection_begin_offset < keyboard->cursor)
+ {
+ keyboard->cursor -= keyboard->selection_length;
+ }
+ }
+
+ keyboard->input_text_len = utf8len(keyboard->input_text);
+ }
+ }
+
if (keyboard_is_key_down(keyboard, KEY_BACKSPACE))
{
- current_keyboard_to_handle->keys[KEY_BACKSPACE] = false;
+ keyboard->keys[KEY_BACKSPACE] = false;
bool is_lctrl_down = keyboard->keys[KEY_LEFT_CONTROL];
@@ -214,16 +251,29 @@ void keyboard_handle_input_string(platform_window *window, keyboard_input *keybo
if (keyboard->selection_begin_offset < keyboard->cursor)
{
- keyboard->cursor -= keyboard->selection_length-1;
+ keyboard->cursor -= keyboard->selection_length;
}
}
else if (is_lctrl_down)
{
- for (s32 i = 0; i < keyboard->cursor; i++)
+ char *iter = keyboard->input_text;
+ s32 index = 0;
+ s32 found_index = 0;
+ utf8_int32_t br;
+ while((iter = utf8codepoint(iter, &br)) && index < keyboard->cursor && br)
+ {
+ index++;
+ if (br == ' ' && index+1 < keyboard->cursor)
+ {
+ found_index = index;
+ }
+ }
+
+ for (s32 i = found_index; i < keyboard->cursor; i++)
{
- utf8_str_remove_at(keyboard->input_text, 0);
+ utf8_str_remove_at(keyboard->input_text, found_index);
}
- keyboard->cursor = 0;
+ keyboard->cursor = found_index;
keyboard->text_changed = true;
}
else if (keyboard->cursor > 0)
diff --git a/src/ui.c b/src/ui.c
index ef71340..a06a4aa 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -839,21 +839,21 @@ bool ui_push_textbox(textbox_state *state, char *placeholder)
if (is_selecting)
{
// move text offset x when selecting so we can select more text than available on screen.
- if (global_ui_context.mouse->x < x + 20)
+ if (global_ui_context.mouse->x < x + 10)
{
s32 text_w = calculate_text_width(global_ui_context.font_small, state->buffer);
- if (text_w > TEXTBOX_WIDTH-20)
+ if (text_w > TEXTBOX_WIDTH-10)
{
state->diff -= TEXTBOX_SCROLL_X_SPEED;
if (state->diff < 0) state->diff = 0;
}
}
- if (global_ui_context.mouse->x > x + TEXTBOX_WIDTH - 25)
+ if (global_ui_context.mouse->x > x + TEXTBOX_WIDTH - 10)
{
s32 text_w = calculate_text_width(global_ui_context.font_small, state->buffer);
- s32 diff = text_w - TEXTBOX_WIDTH + 25;
+ s32 diff = text_w - TEXTBOX_WIDTH + 10;
- if (text_w > TEXTBOX_WIDTH-25)
+ if (text_w > TEXTBOX_WIDTH-10)
{
state->diff += TEXTBOX_SCROLL_X_SPEED;
if (state->diff > diff)
@@ -1440,7 +1440,7 @@ inline void ui_end_menu_bar()
global_ui_context.layout.offset_x = 0;
global_ui_context.layout.offset_y += MENU_BAR_HEIGHT;
- ui_push_separator();
+ //ui_push_separator();
}
inline void ui_destroy()