Merge pull request 'Small textbox fixes' (#41) from ilidemi/orca:textbox-fixes into main

Reviewed-on: #41
This commit is contained in:
MartinFouilleul 2023-08-18 16:31:20 +00:00
commit 0d920670a2
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); oc_ui_sig sig = oc_ui_box_sig(frame);
if(sig.hovering)
{
oc_ui_box_set_hot(frame, true);
if(sig.pressed) if(sig.pressed)
{ {
if(!oc_ui_box_active(frame)) 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, //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) // 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; i32 tmp = ui->editCursor;
ui->editCursor = ui->editMark; 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; ui->editMark = ui->editCursor;
} }
} }
if(sig.hovering)
{
oc_ui_box_set_hot(frame, true);
} }
else else
{ {
oc_ui_box_set_hot(frame, false); 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)) if(oc_ui_box_active(frame))
{ {