Skip to content
Myr

better handle dragging mouse in single-line mode

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parent 4de75eb · Browse files · 1 file+21 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+21 added−1 removed

  • other:+21 added−1 removed

1 file+21 added−1 removed

modified:stb_textedit.h+21 added-1 removed
439 unmodified lines
440441// API click: on mouse down, move the cursor to the clicked location, and reset the selection442static void stb_textedit_click(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, float x, float y)443{444 // In single-line mode, just always make y = 0. This lets the drag keep working if the mouse445 // goes off the top or bottom of the text446 if( state->single_line )447 {448 StbTexteditRow r;449 STB_TEXTEDIT_LAYOUTROW(&r, str, 0);450 y = r.ymin;451 }452453 state->cursor = stb_text_locate_coord(str, x, y);454 state->select_start = state->cursor;455 state->select_end = state->cursor;456 state->has_preferred_x = 0;
1 unmodified line
458459// API drag: on mouse drag, move the cursor and selection endpoint to the clicked location460static void stb_textedit_drag(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, float x, float y)461{462 int p = 0;463464 // In single-line mode, just always make y = 0. This lets the drag keep working if the mouse465 // goes off the top or bottom of the text466 if( state->single_line )467 {468 StbTexteditRow r;469 STB_TEXTEDIT_LAYOUTROW(&r, str, 0);470 y = r.ymin;471 }472453 int p = stb_text_locate_coord(str, x, y);473 p = stb_text_locate_coord(str, x, y);474 state->cursor = state->select_end = p;475}476477/////////////////////////////////////////////////////////////////////////////
844 unmodified lines