Skip to content

Commit cd988c3

Browse files
author
Evgeni Raikhel
committed
Fix arrow-key radio-button edits not starting the auto-commit debounce
A discrete edit's touch()+finalize() land in the same frame as the end_frame_and_maybe_commit() call that just parked the real deadline - unlike a mouse drag, which spans several frames with the widget still active in between. The focus-loss shortcut couldn't tell the two apart and was collapsing the just-set deadline back to "now" on that same frame, so changing the Downscale Ratio via arrow keys never actually waited out commit_delay (mouse clicks were unaffected, since a mouse press keeps the item active for that frame). Suppress the shortcut for the one frame finalize() just ran on.
1 parent 145b059 commit cd988c3

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

common/composite-control-editor.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,18 @@ namespace rs2
108108

109109
// Call once a field's edit is finalized (slider released, or immediately after a
110110
// checkbox/radio click). Schedules the real auto-commit commit_delay seconds out.
111-
void finalize() { _commit_deadline = ImGui::GetTime() + commit_delay; }
111+
void finalize()
112+
{
113+
_commit_deadline = ImGui::GetTime() + commit_delay;
114+
// A discrete edit (radio/checkbox click, keyboard arrow-key nudge) calls touch()+
115+
// finalize() together, synchronously, within the SAME frame as the
116+
// end_frame_and_maybe_commit() call below that just set this deadline - unlike a
117+
// mouse drag, which spans several frames with the widget genuinely active in
118+
// between, giving the focus-loss shortcut no chance to fire on that exact frame.
119+
// Suppress it for this one frame so it can't immediately collapse the deadline it
120+
// was never meant to see yet.
121+
_just_finalized = true;
122+
}
112123

113124
// Side-effect-free readout of the same progress end_frame_and_maybe_commit() animates
114125
// with: false if nothing is pending, true with `progress` in [0,1] (0 = just
@@ -185,9 +196,11 @@ namespace rs2
185196
// normal quiet gap between finishing one field and touching the next one in THIS
186197
// group, and must NOT cut the wait short). When that happens, don't make the user
187198
// wait out the rest of the countdown - finish it now, same as if it had lapsed
188-
// naturally.
189-
if( _dirty && ! any_field_active_this_frame && ImGui::IsAnyItemActive() )
199+
// naturally. Skipped on the one frame finalize() just ran on (see its comment) - a
200+
// discrete edit's own deadline must survive at least until the NEXT frame.
201+
if( _dirty && ! any_field_active_this_frame && ImGui::IsAnyItemActive() && ! _just_finalized )
190202
_commit_deadline = ImGui::GetTime();
203+
_just_finalized = false;
191204

192205
// Fires once the countdown elapses quietly - checked every frame, so any fresh
193206
// touch() (which re-parks the deadline at +infinity) naturally defers this for as
@@ -212,6 +225,7 @@ namespace rs2
212225
private:
213226
bool _dirty = false;
214227
double _commit_deadline = std::numeric_limits< double >::max();
228+
bool _just_finalized = false;
215229

216230
static constexpr double commit_delay = 1.7; // seconds of quiet before auto-sending
217231
static constexpr float border_start_scale = 4.0f; // 400% of normal width, right after an edit

0 commit comments

Comments
 (0)