diff options
| author | aura <nw@moneybot.cc> | 2026-03-17 12:04:30 +0100 |
|---|---|---|
| committer | aura <nw@moneybot.cc> | 2026-03-17 12:04:30 +0100 |
| commit | a156bc15880e9e250c9c40f0dde431e077109dc1 (patch) | |
| tree | 64b6461b0d0e9cad6ff7fdcfba563e103fad9067 /src/gui | |
| parent | 991352b0d2767e6bd1a46f554db4ac9d208c13ad (diff) | |
multi select
Diffstat (limited to 'src/gui')
| -rw-r--r-- | src/gui/base.h | 5 | ||||
| -rw-r--r-- | src/gui/floatinput.cpp | 12 | ||||
| -rw-r--r-- | src/gui/vectorinput.cpp | 12 |
3 files changed, 28 insertions, 1 deletions
diff --git a/src/gui/base.h b/src/gui/base.h index 293de74..0418afd 100644 --- a/src/gui/base.h +++ b/src/gui/base.h @@ -229,6 +229,8 @@ struct GUI_FLOATINPUT : GUI_BASE { F32 max; F32 step; + F32 lastchange; + I32 lastmx; U8 heldoutbounds; U8 held; @@ -239,6 +241,7 @@ struct GUI_FLOATINPUT : GUI_BASE { U8 wraparound; GUI_CALLBACK cb; + void* cbextra; }; struct GUI_VECTORINPUT : GUI_VIEW { @@ -253,8 +256,10 @@ struct GUI_VECTORINPUT : GUI_VIEW { GUI_VIEW* inputview; LIST<GUI_FLOATINPUT*> inputs; + LIST<F32> lastchange; GUI_CALLBACK cb; + void* cbextra; }; struct GUI_COLORINPUT : GUI_VECTORINPUT {}; diff --git a/src/gui/floatinput.cpp b/src/gui/floatinput.cpp index 5746758..5ce92fe 100644 --- a/src/gui/floatinput.cpp +++ b/src/gui/floatinput.cpp @@ -166,6 +166,7 @@ void gui_floatinput_input_bound( GUI_FLOATINPUT* input ) { if( !gui_mbutton_down( GUI_MBTNLEFT ) ) return; + F32 oldval = *input->pval; I32 x = gui_relx( input ); I32 w = gui_floatinput_content_w( input ); @@ -182,6 +183,8 @@ void gui_floatinput_input_bound( GUI_FLOATINPUT* input ) { F32 nval = min + (max - min) * progress; F32 rmn = remainderf( nval, input->step ); *input->pval = nval - rmn; + if( oldval != *input->pval ) + input->lastchange = *input->pval - oldval; } void gui_floatinput_input_unbound( GUI_FLOATINPUT* input ) { @@ -191,6 +194,7 @@ void gui_floatinput_input_unbound( GUI_FLOATINPUT* input ) { I32 mx, my; gui_cursor_pos( &mx, &my ); + F32 oldval = *input->pval; I32 dx = mx - input->lastmx; if( dx ) *input->pval += dx * input->step; @@ -205,6 +209,8 @@ void gui_floatinput_input_unbound( GUI_FLOATINPUT* input ) { F32 rmn = remainderf( *input->pval, input->step ); *input->pval -= rmn; + if( oldval != *input->pval ) + input->lastchange = *input->pval - oldval; } void gui_floatinput_input_scroll( GUI_FLOATINPUT* input ) { @@ -229,6 +235,7 @@ void gui_floatinput_input_scroll( GUI_FLOATINPUT* input ) { F32 rmn = remainderf( nval, input->step ); *input->pval = nval - rmn; + input->lastchange = *input->pval - oldval; if( input->cb ) input->cb( input ); } @@ -261,13 +268,15 @@ void gui_floatinput_input_fn( void* ptr ) { return; } - if( !input->held ) { + if( !input->held && !input->heldoutbounds ) { U8 fine = !!m2; I32 split_y = y + 1 + ( h - 2 ) / 2; U8 inc = my < split_y; F32 step = fine ? 0.1f : 1.f; + F32 val = *input->pval; *input->pval += inc ? step : -step; gui_floatinput_clamp_and_snap( input ); + input->lastchange = *input->pval - val; if( input->cb ) input->cb( input ); input->held = 1; @@ -320,6 +329,7 @@ struct GUI_FLOATINPUT* gui_floatinput( I32 x, I32 y, I32 w, const char* title, F input->input_fn = gui_floatinput_input_fn; input->draw_fn = gui_floatinput_draw_fn; + input->lastchange = 0; input->cb = 0; input->pval = pval; input->min = min; diff --git a/src/gui/vectorinput.cpp b/src/gui/vectorinput.cpp index 9ebb0fa..daed540 100644 --- a/src/gui/vectorinput.cpp +++ b/src/gui/vectorinput.cpp @@ -25,6 +25,16 @@ void gui_vectorinput_child_cb( void* ptr ) { GUI_FLOATINPUT* child = (GUI_FLOATINPUT*)ptr; // slider -> child view -> vectorinput GUI_VECTORINPUT* parent = (GUI_VECTORINPUT*)child->parent->parent; + for( auto& it : parent->lastchange ) + it = 0.f; + + for( U32 i = 0; i < parent->inputs.size; ++i ) { + if( parent->inputs.data[i] == child ) { + parent->lastchange.data[i] = child->lastchange; + break; + } + } + if( parent->cb ) parent->cb( parent ); } @@ -54,6 +64,7 @@ void __gui_internal_vectorinput_init( GUI_VIEW* parent = gui_get_view(); parent->children.push( input ); input->parent = parent; + input->lastchange.resize( valc ); gui_set_view( input ); @@ -77,6 +88,7 @@ void __gui_internal_vectorinput_init( printfmt ); + input->inputs.push( slider ); slider->cb = gui_vectorinput_child_cb; } |
