Small textbox fixes #41

Merged
MartinFouilleul merged 1 commits from ilidemi/orca:textbox-fixes into main 2023-08-18 16:31:21 +00:00
1 changed files with 53 additions and 51 deletions

View File

@ -2663,10 +2663,6 @@ oc_ui_text_box_result oc_ui_text_box(const char* name, oc_arena* arena, oc_str8
oc_ui_sig sig = oc_ui_box_sig(frame);
if(sig.hovering)
{
oc_ui_box_set_hot(frame, true);
if(sig.pressed)
{
if(!oc_ui_box_active(frame))
@ -2703,7 +2699,7 @@ oc_ui_text_box_result oc_ui_text_box(const char* name, oc_arena* arena, oc_str8
}
//NOTE: put cursor the closest to new cursor (this maximizes the resulting selection,
// and seems to be the standard behaviour across a number of text editor)
if(abs(newCursor - ui->editCursor) > abs(newCursor - ui->editMark))
if(sig.pressed && abs(newCursor - ui->editCursor) > abs(newCursor - ui->editMark))
{
i32 tmp = ui->editCursor;
ui->editCursor = ui->editMark;
@ -2716,12 +2712,18 @@ oc_ui_text_box_result oc_ui_text_box(const char* name, oc_arena* arena, oc_str8
ui->editMark = ui->editCursor;
}
}
if(sig.hovering)
{
oc_ui_box_set_hot(frame, true);
}
else
{
oc_ui_box_set_hot(frame, false);
if(sig.pressed)
if(oc_mouse_pressed(&ui->input, OC_MOUSE_LEFT) ||
oc_mouse_pressed(&ui->input, OC_MOUSE_RIGHT) ||
oc_mouse_pressed(&ui->input, OC_MOUSE_MIDDLE))
{
if(oc_ui_box_active(frame))
{