fix(ui): scrubbing a prototype panel number sets it once (#256)

Delays, scroll offsets, overlay offsets and the overlay background alpha
were set on every frame of a scrub, an undo step each. They now set once,
when let go, like the custom size field.

Refs #256

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
RealtaNuaandClaude Opus 5.5 committed 2026-10-15 22:15:58 +07:00
1 parent 102429e6b5
commit 1593b163fb
2 files changed
+42 -25

No files matched your search

+25 -1
View File
@@ -2,7 +2,7 @@
//! a scrub and an arrow key move a value, and the Design panel's fields driven through egui
//! headless: scrubbing by the label with and without Shift and Alt, arrow keys, arithmetic on
//! commit, Tab and Shift+Tab, Escape, fields showing "Mixed", and one undo step per scrub or
//! commit (the colour picker's fields too).
//! commit (the colour picker's and the prototype panel's fields too).
use egui::accesskit::Role;
use egui::{Event, Id, Key, Modifiers, Pos2, pos2};
@@ -437,3 +437,27 @@ fn scrubbing_colour_picker_fields_is_live_and_one_undo_step() {
assert!(alpha < a0, "alpha {a0} → {alpha}");
assert_eq!(undo_steps(&u), steps + 2, "alpha");
}
#[test]
fn scrubbing_a_prototype_delay_sets_it_once_when_let_go() {
let mut s = Session::new();
let f1 = id(s.execute("frame.create", &json!({"x": 0, "y": 0, "width": 200, "height": 300})).unwrap());
let f2 = id(s.execute("frame.create", &json!({"x": 300, "y": 0, "width": 200, "height": 300})).unwrap());
let it = json!({"id": f1, "trigger": {"type": "afterDelay", "ms": 500}, "action": {"type": "navigate", "dest": f2}});
s.execute("proto.interaction.add", &it).unwrap();
s.execute("select.set", &json!({"ids": [f1]})).unwrap();
let mut u = Ui::new(s);
u.app.ui.right_tab = crate::RightTab::Prototype;
crate::proto_panel::open_editor(&u.ctx, Some((f1, 0)));
for _ in 0..3 {
u.frame(vec![]);
}
let steps = undo_steps(&u);
let from = lead(&u, Id::new(("proto_delay", f1, 0usize)));
drag(&mut u, from, 30.0, Modifiers::NONE);
let ms = match u.app.session.doc().unwrap().node(f1).unwrap().interactions[0].trigger {
figcraft_doc::proto::Trigger::AfterDelay { ms } => ms,
_ => panic!("still after a delay"),
};
assert_eq!((ms, undo_steps(&u)), (800, steps + 1));
}
+17 -24
View File
@@ -700,7 +700,7 @@ fn trigger_rows(app: &mut FigApp, ui: &mut Ui, node: NodeId, k: usize, it: &Inte
row(ui, 32.0, |ui| {
widgets::label(ui, tr("Delay"), t.text_secondary);
let id = Id::new(("proto_mouse_delay", node, k));
if let Some(FieldEdit::Set(v) | FieldEdit::Scrub(v, _)) =
if let Some(FieldEdit::Set(v) | FieldEdit::Scrub(v, true)) =
widgets::number_field(ui, id, Lead::None, Some(f64::from(it.delay_ms)), "ms", 96.0, 10.0)
&& v.is_finite()
{
@@ -711,13 +711,11 @@ fn trigger_rows(app: &mut FigApp, ui: &mut Ui, node: NodeId, k: usize, it: &Inte
Trigger::AfterDelay { ms } => {
row(ui, 32.0, |ui| {
widgets::label(ui, tr("Delay"), t.text_secondary);
if let Some(e) = widgets::number_field(ui, Id::new(("proto_delay", node, k)), Lead::None, Some(f64::from(*ms)), "ms", 96.0, 10.0) {
let v = match e {
FieldEdit::Set(v) | FieldEdit::Scrub(v, _) => v,
};
if v.is_finite() {
patch(app, node, k, json!({"trigger": {"type": "afterDelay", "ms": v.clamp(0.0, 600_000.0).round() as u32}}));
}
if let Some(FieldEdit::Set(v) | FieldEdit::Scrub(v, true)) =
widgets::number_field(ui, Id::new(("proto_delay", node, k)), Lead::None, Some(f64::from(*ms)), "ms", 96.0, 10.0)
&& v.is_finite()
{
patch(app, node, k, json!({"trigger": {"type": "afterDelay", "ms": v.clamp(0.0, 600_000.0).round() as u32}}));
}
});
}
@@ -851,9 +849,10 @@ pub(crate) fn action_fields(app: &mut FigApp, ui: &mut Ui, doc: &Document, page:
row(ui, 32.0, |ui| {
let w = ((ui.available_width() - 6.0) / 2.0).max(36.0);
for (i, (name, key)) in [("X", "proto_scroll_x"), ("Y", "proto_scroll_y")].into_iter().enumerate() {
let Some(e) = widgets::number_field(ui, slot.id(key), Lead::Text(name), offset.get(i).copied(), "", w, 1.0) else { continue };
let v = match e {
FieldEdit::Set(v) | FieldEdit::Scrub(v, _) => v,
let Some(FieldEdit::Set(v) | FieldEdit::Scrub(v, true)) =
widgets::number_field(ui, slot.id(key), Lead::Text(name), offset.get(i).copied(), "", w, 1.0)
else {
continue;
};
if v.is_finite() {
let mut o = offset;
@@ -901,7 +900,7 @@ pub(crate) fn action_fields(app: &mut FigApp, ui: &mut Ui, doc: &Document, page:
else {
continue;
};
let Some(FieldEdit::Set(v) | FieldEdit::Scrub(v, _)) = e.settled() else { continue };
let Some(FieldEdit::Set(v) | FieldEdit::Scrub(v, true)) = e.settled() else { continue };
if v.is_finite() {
let mut o = offset.unwrap_or([0.0, 0.0]);
if let Some(slot_v) = o.get_mut(i) {
@@ -932,18 +931,12 @@ pub(crate) fn action_fields(app: &mut FigApp, ui: &mut Ui, doc: &Document, page:
set_action(app, slot, Action::OpenOverlay { dest, position, close_on_outside, background: Some(c), offset });
}
let alpha = (bg.a * 100.0).round();
if let Some(e) = widgets::number_field(ui, slot.id("proto_ovbg_a"), Lead::None, Some(f64::from(alpha)), "%", 64.0, 1.0) {
let v = match e {
FieldEdit::Set(v) | FieldEdit::Scrub(v, _) => v,
};
if v.is_finite() {
let a = v.clamp(0.0, 100.0) as f32 / 100.0;
set_action(
app,
slot,
Action::OpenOverlay { dest, position, close_on_outside, background: Some(bg.with_alpha(a)), offset },
);
}
if let Some(FieldEdit::Set(v) | FieldEdit::Scrub(v, true)) =
widgets::number_field(ui, slot.id("proto_ovbg_a"), Lead::None, Some(f64::from(alpha)), "%", 64.0, 1.0)
&& v.is_finite()
{
let a = v.clamp(0.0, 100.0) as f32 / 100.0;
set_action(app, slot, Action::OpenOverlay { dest, position, close_on_outside, background: Some(bg.with_alpha(a)), offset });
}
});
}