cursor_animation := 0.0f;
cursor_animation_speed := 0.02f;
- @HACK // Otherwise the backspace button deletes a character
- // every frame, which obviously is way too fast.
- backspace_timeout := 0.0f;
+ @HACK // Otherwise the action keys are evaluated every frame.
+ action_key_timeout := 0.0f;
}
textbox_editing_state := Textbox_Editing_State.{};
textbox_editing_state.cursor_position = screen_to_cursor(^font, text_x, text_y, text, ~~mx, ~~my);
}
- move_towards(^textbox_editing_state.backspace_timeout, 0, 0.05f);
+ move_towards(^textbox_editing_state.action_key_timeout, 0, 0.05f);
+ if textbox_editing_state.action_key_timeout == 0 {
+ keys := input_get_keys_this_frame();
+ for key: iter.as_iterator(^keys) {
+ textbox_editing_state.action_key_timeout = 0.17f;
- keys := input_get_keys_this_frame();
- for key: iter.as_iterator(^keys) {
- switch key.key {
- case GLFW_KEY_ESCAPE {
- set_active_item(0);
- input_release_keys();
- }
+ switch key.key {
+ case GLFW_KEY_ESCAPE {
+ set_active_item(0);
+ input_release_keys();
+ }
- case GLFW_KEY_LEFT do textbox_editing_state.cursor_position -= 1;
- case GLFW_KEY_RIGHT do textbox_editing_state.cursor_position += 1;
- case GLFW_KEY_END do textbox_editing_state.cursor_position = text_buffer.count;
- case GLFW_KEY_HOME do textbox_editing_state.cursor_position = 0;
+ case GLFW_KEY_LEFT do textbox_editing_state.cursor_position -= 1;
+ case GLFW_KEY_RIGHT do textbox_editing_state.cursor_position += 1;
+ case GLFW_KEY_END do textbox_editing_state.cursor_position = text_buffer.count;
+ case GLFW_KEY_HOME do textbox_editing_state.cursor_position = 0;
- case GLFW_KEY_BACKSPACE {
- if textbox_editing_state.backspace_timeout == 0 {
+ case GLFW_KEY_BACKSPACE {
if textbox_editing_state.cursor_position > 0 {
array.delete(text_buffer, textbox_editing_state.cursor_position - 1);
}
textbox_editing_state.cursor_position = math.max(~~0, textbox_editing_state.cursor_position - 1);
-
- textbox_editing_state.backspace_timeout = 0.20f;
}
- }
- case GLFW_KEY_DELETE {
- if textbox_editing_state.backspace_timeout == 0 {
+ case GLFW_KEY_DELETE {
array.delete(text_buffer, textbox_editing_state.cursor_position);
- textbox_editing_state.backspace_timeout = 0.20f;
}
}
}