mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-30 02:04:32 +01:00
fix(color-ui): the units cell keeps its first click in component memory, not the session escape hatch
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx
This commit is contained in:
1 parent
960c882d55
commit
4e48b7abc4
1 file changed
+7
-8
@@ -14,7 +14,7 @@ use craft_ui::form::{Field, SliderField, SliderFieldLayout};
|
||||
use craft_ui::layout_components::Row;
|
||||
use craft_ui::primitives::{PaintShape, StrokeWidth};
|
||||
use craft_ui::runtime::env::{Label, UnitKind};
|
||||
use craft_ui::runtime::memory::with_session;
|
||||
use craft_ui::runtime::memory::sub;
|
||||
use craft_ui::runtime::pointer;
|
||||
use craft_ui::style::{ComponentStyle, DataColor, StyleColor, StyleCx};
|
||||
use craft_ui::value_drag::{SliderThumb, TrackFace};
|
||||
@@ -350,23 +350,22 @@ impl Component for UnitsCell {
|
||||
}
|
||||
|
||||
fn update(&mut self, cx: &mut Cx<'_, Self>) {
|
||||
let first = cx.id.with("units-first-click");
|
||||
let ctx = &cx.response.ctx;
|
||||
let first = sub(cx.core.id, "units-first-click");
|
||||
// A press off the cell ends the cell's click run, even when it starts a new count that the next click on the
|
||||
// cell continues.
|
||||
if pointer::frame(ctx).press.is_some_and(|press| !cx.response.rect.contains(press.origin)) {
|
||||
with_session::<Option<(f64, u32)>, _>(ctx, first, |last| *last = None);
|
||||
if pointer::frame(&cx.response.ctx).press.is_some_and(|press| !cx.response.rect.contains(press.origin)) {
|
||||
*cx.core.memory.shown::<Option<(f64, u32)>>(first) = None;
|
||||
}
|
||||
let PressPhase::Release { start, click: true, .. } = cx.part(UNITS).press.phase else { return };
|
||||
// The click count also counts a press just beside the cell, on the number field, so a click is the second of a
|
||||
// double click only when the click just before it, by the count, was a click on this cell.
|
||||
let earlier = with_session::<Option<(f64, u32)>, _>(ctx, first, |last| *last);
|
||||
let earlier = *cx.core.memory.shown::<Option<(f64, u32)>>(first);
|
||||
let follows = earlier.is_some_and(|(time, clicks)| start.clicks == clicks + 1 && start.time - time <= MULTI_CLICK_TIME);
|
||||
if start.clicks >= 2 && follows {
|
||||
self.double_clicked = true;
|
||||
with_session::<Option<(f64, u32)>, _>(ctx, first, |last| *last = None);
|
||||
*cx.core.memory.shown::<Option<(f64, u32)>>(first) = None;
|
||||
} else {
|
||||
with_session::<Option<(f64, u32)>, _>(ctx, first, |last| *last = Some((start.time, start.clicks)));
|
||||
*cx.core.memory.shown::<Option<(f64, u32)>>(first) = Some((start.time, start.clicks));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user