The widget half of the widget catalogue's later work, ported onto makepad-widgets-core and the family crates. - libs/tween: a dependency-free tween and timeline engine -- nested timelines with positions and labels, stagger, repeat and yoyo, seek and reverse, time scale, a ticker with lag smoothing, a global pause and reduced motion, colour-space interpolation, keyframes and motion paths. The core binds it to the widget tree (tween, a widget's TweenHost), gives script a mod.tween (tween_script) and a live inspector (tween_inspect, tween_inspector). The Animator's Ease now answers from the engine's easing, so the curves have one source; the Animator keeps its states, its keyframe timelines and its own clock. - libs/gizmo and a Gizmo3d / ViewCube widget. - core: the ease editor, the sequencer, diagonal headings, hotkeys, the hotkey editor and keyboard map, the overlay layer host, a conceding row and the width a widget would take without drawing; a theme mix and a person's own theme edits that survive a style reload (theme_mix, set_theme_edit), both taken off by set_base_theme. - the surface material: buttons, check boxes, toggles, sliders and knobs carry the moulded material behind one uniform, a press idiom per sign of material_press, and four sheets that raise it: neumorphic, molded, glossy and milled. - the sheets: a row of fields is one height under every sheet. A sheet line that names a widget the app did not register (a family left out) is skipped when the sheet installs, so the date fields a sheet sizes need the dates family only where it is linked. - extras: the gradient editor, registered with the colour picker it builds on. - tweaker: the designer (a widget's literal located and edited in its source as hunks), the theme lab and the theme builder. The window reads the docked panel's band through the tweaker's hooks. - the panel no longer wears the app's theme (the design surface keeps its own palette), so the worn-theme tests go with it. Five theme builder tests fail here as they do on the branch this comes from (every_built_theme_reads and four more on text contrast); radial_menu's tab_under_an_open_menu_finds_nowhere_to_go fails here as it does on dev.
121 lines
3.9 KiB
Rust
121 lines
3.9 KiB
Rust
//! The read-only inspection walk: order, depth, starts, labels, tracks.
|
|
|
|
use makepad_tween::*;
|
|
|
|
const OPACITY: PropKey = PropKey(1);
|
|
const SHIFT: PropKey = PropKey(2);
|
|
const INTRO: Tag = Tag(11);
|
|
const OUTRO: Tag = Tag(12);
|
|
const SHOW: Tag = Tag(13);
|
|
|
|
#[test]
|
|
fn inspect_walks_a_timeline_parent_first_with_local_starts() {
|
|
let mut e = TweenEngine::new();
|
|
for i in 0..2 {
|
|
e.seed(TargetId(i), OPACITY, 0.0.into());
|
|
e.seed(TargetId(i), SHIFT, 10.0.into());
|
|
}
|
|
let tl = e.timeline(TimelineOpts::new().tag(SHOW));
|
|
e.tl(tl)
|
|
.add_label(INTRO, 0.0)
|
|
.to(
|
|
TargetId(0).into(),
|
|
&[PropTo::to_f64(OPACITY, 1.0), PropTo::to_f64(SHIFT, 0.0)],
|
|
TweenOpts::new().duration(0.5),
|
|
INTRO,
|
|
)
|
|
.add_label(OUTRO, Position::rel(0.25))
|
|
.to(
|
|
TargetId(1).into(),
|
|
&[PropTo::to_f64(OPACITY, 1.0)],
|
|
TweenOpts::new().duration(0.3),
|
|
OUTRO,
|
|
);
|
|
|
|
let mut nodes = Vec::new();
|
|
e.inspect(&mut nodes);
|
|
assert_eq!(nodes.len(), 3, "the timeline and its two tweens");
|
|
|
|
let top = nodes[0];
|
|
assert_eq!(top.id, tl);
|
|
assert_eq!(top.parent, TweenId::NONE);
|
|
assert_eq!(top.depth, 0);
|
|
assert_eq!(top.kind, InspectKind::Timeline);
|
|
assert_eq!(top.tag, SHOW);
|
|
assert_eq!(top.local_start, 0.0);
|
|
assert!((top.duration - 1.05).abs() < 1e-9);
|
|
|
|
let (a, b) = (nodes[1], nodes[2]);
|
|
assert_eq!((a.parent, a.depth, a.kind), (tl, 1, InspectKind::Tween));
|
|
assert_eq!((b.parent, b.depth), (tl, 1));
|
|
assert_eq!(a.local_start, 0.0);
|
|
assert!(
|
|
(b.local_start - 0.75).abs() < 1e-9,
|
|
"starts at the outro label"
|
|
);
|
|
assert_eq!(a.tracks, 2);
|
|
assert_eq!(a.first_track, Some((TargetId(0), OPACITY)));
|
|
assert_eq!(b.first_track, Some((TargetId(1), OPACITY)));
|
|
|
|
let mut labels = Vec::new();
|
|
e.inspect_labels(tl, &mut labels);
|
|
assert_eq!(labels.len(), 2);
|
|
assert_eq!(labels[0], (INTRO, 0.0));
|
|
assert_eq!(labels[1].0, OUTRO);
|
|
assert!((labels[1].1 - 0.75).abs() < 1e-9);
|
|
|
|
let mut tracks = Vec::new();
|
|
e.inspect_tracks(a.id, &mut tracks);
|
|
assert_eq!(tracks, vec![(TargetId(0), OPACITY), (TargetId(0), SHIFT)]);
|
|
|
|
// Read-only: the playhead has not moved.
|
|
assert_eq!(e.anim_ref(tl).total_time(), 0.0);
|
|
}
|
|
|
|
#[test]
|
|
fn inspect_reports_a_stale_handle_as_nothing() {
|
|
let mut e = TweenEngine::new();
|
|
let mut labels = vec![(Tag(1), 1.0)];
|
|
let mut tracks = vec![(TargetId(1), OPACITY)];
|
|
e.inspect_labels(TweenId::NONE, &mut labels);
|
|
e.inspect_tracks(TweenId::NONE, &mut tracks);
|
|
assert!(labels.is_empty() && tracks.is_empty());
|
|
let mut nodes = vec![];
|
|
e.inspect(&mut nodes);
|
|
assert!(nodes.is_empty(), "an engine that never built has no nodes");
|
|
e.seed(TargetId(0), OPACITY, 0.0.into());
|
|
e.inspect(&mut nodes);
|
|
assert!(nodes.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn inspect_keeps_listing_a_completed_kept_timeline() {
|
|
let mut e = TweenEngine::new();
|
|
e.seed(TargetId(0), OPACITY, 0.0.into());
|
|
let tl = e.timeline(TimelineOpts::new().keep(true));
|
|
e.tl(tl).to(
|
|
TargetId(0).into(),
|
|
&[PropTo::to_f64(OPACITY, 1.0)],
|
|
TweenOpts::new().duration(0.25),
|
|
0.0,
|
|
);
|
|
let mut nodes = Vec::new();
|
|
e.inspect(&mut nodes);
|
|
assert!(nodes[0].linked);
|
|
|
|
while e.is_active() {
|
|
e.advance(1.0 / 60.0);
|
|
e.clear_events();
|
|
}
|
|
e.inspect(&mut nodes);
|
|
assert_eq!(nodes.len(), 2, "the completed timeline and its tween");
|
|
assert_eq!((nodes[0].id, nodes[0].depth), (tl, 0));
|
|
assert!(!nodes[0].linked, "detached from the root once complete");
|
|
assert!(nodes[1].linked, "still on its own timeline");
|
|
assert!((nodes[0].total_time - 0.25).abs() < 1e-9);
|
|
|
|
e.anim(tl).restart(false, Emit::Suppress);
|
|
e.inspect(&mut nodes);
|
|
assert_eq!(nodes.len(), 2, "listed once after a restart");
|
|
assert!(nodes[0].linked);
|
|
}
|