Skip to content

Commit 1d2d9b8

Browse files
committed
[update] insert
1 parent 7471e55 commit 1d2d9b8

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

include/ekg/handler/input.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ namespace ekg {
7171
bool has_motion {};
7272
bool was_wheel {};
7373
bool was_typed {};
74+
std::string_view typed {};
7475
};
7576

7677
struct input_key_t {

include/ekg/ui/textbox/widget.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ namespace ekg::ui {
5454
ekg::textbox_t::cursor_t &cursor
5555
);
5656

57+
void handle_insert(
58+
ekg::textbox_t &textbox,
59+
ekg::textbox_t::cursor_t &cursor,
60+
std::string_view typed
61+
);
62+
5763
void reload(
5864
ekg::property_t &property,
5965
ekg::textbox_t &textbox

src/handler/input/handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,12 @@ void ekg::handler::input::poll_event() {
261261
case ekg::io::event_type::text_input: {
262262
this->input.was_pressed = true;
263263
this->input.was_typed = true;
264+
this->input.typed = platform_event.text_input;
264265
break;
265266
}
266267

267268
case ekg::io::event_type::key_down: {
268269
this->input.was_pressed = true;
269-
this->input.was_typed = true;
270270

271271
this->string_builder.clear();
272272

src/handler/theme/handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void ekg::handler::theme::init() {
142142
black_light_pinky_theme.textbox_color_scheme.text_select_outline = {245, 169, 184, 100};
143143

144144
this->registry(black_light_pinky_theme.tag) = black_light_pinky_theme;
145-
this->set_current_theme(black_light_pinky_theme.tag);
145+
//this->set_current_theme(black_light_pinky_theme.tag);
146146
}
147147

148148
void ekg::handler::theme::quit() {

src/ui/textbox/widget.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,28 @@ void ekg::ui::handle_erase(
326326
cursor.delta = cursor.a;
327327
}
328328

329+
void ekg::ui::handle_insert(
330+
ekg::textbox_t &textbox,
331+
ekg::textbox_t::cursor_t &cursor,
332+
std::string_view typed
333+
) {
334+
if (cursor.a != cursor.b) {
335+
ekg::ui::handle_erase(textbox, cursor);
336+
}
337+
338+
std::string line {textbox.text.at(cursor.a.y)};
339+
340+
line.insert(
341+
line.begin() + cursor.a.x,
342+
typed.begin(),
343+
typed.end()
344+
);
345+
346+
textbox.text.set(cursor.a.y, line);
347+
cursor.a.x += ekg::utf8_length(typed);
348+
cursor.b = cursor.a;
349+
}
350+
329351
void ekg::ui::reload(
330352
ekg::property_t &property,
331353
ekg::textbox_t &textbox
@@ -513,7 +535,7 @@ void ekg::ui::event(
513535
);
514536
}
515537

516-
if (!input.was_typed) {
538+
if (!input.was_typed && !input.was_pressed) {
517539
return;
518540
}
519541

@@ -534,7 +556,7 @@ void ekg::ui::event(
534556
bool is_down_fired {ekg::fired("textbox-action-down")};
535557
bool is_modifier_down_fired {is_down_fired && is_modifier_fired};
536558

537-
if (is_left_fired || is_right_fired || is_up_fired || is_down_fired || is_action_erase_fired) {
559+
if (is_left_fired || is_right_fired || is_up_fired || is_down_fired || is_action_erase_fired || input.was_typed) {
538560
textbox.widget.set_cursor_static = true;
539561
}
540562

@@ -551,6 +573,7 @@ void ekg::ui::event(
551573
ekg::vec2_t<float> cursor_pos {};
552574
std::string line {};
553575

576+
ekg_log_low_level(input.was_typed);
554577

555578
for (ekg::textbox_t::cursor_t &cursor : textbox.widget.cursors) {
556579
is_ab_equals = cursor.a == cursor.b;
@@ -769,6 +792,10 @@ void ekg::ui::event(
769792
if (is_action_erase_fired) {
770793
ekg::ui::handle_erase(textbox, cursor);
771794
}
795+
796+
if (input.was_typed) {
797+
ekg::ui::handle_insert(textbox, cursor, input.typed);
798+
}
772799
}
773800

774801
break;

0 commit comments

Comments
 (0)