app: give the clip's ends an arrow each on the scrubber

The clip's ends were 3 point bars that took whichever end the pointer
pressed nearest, so a drag near the middle of the track moved an end
instead of the picture, and the two bars were easy to miss on a long
recording.

Each end is now a round gold arrow over the knob, one per end, and only
a drag that starts on an arrow moves that end. The track and the knob
seek as before, in clip mode too. The played part of the track goes
neutral while a clip is chosen, so gold marks the selection alone.

The knob is centered on the play head now, so an arrow at the same
second sits on it rather than a few points beside.
This commit is contained in:
vhaudiquet committed 2026-11-19 19:26:09 +01:00
1 parent 5ab3161bf5
commit 409be9d31a
2 files changed
+128 -45

No files matched your search

+13
View File
@@ -29,3 +29,16 @@ pub static FORWARD: Icon = Icon {
view: 16.0,
body: r#"<path d="M13.2 8 8.8 4.6v6.8Z" fill="currentColor"/><path d="M8.4 8 4 4.6v6.8Z" fill="currentColor"/>"#,
};
/// One end of the clip: a single chevron, drawn on the scrubber over the knob.
pub static CHEVRON_LEFT: Icon = Icon {
name: "app-chevron-left",
view: 16.0,
body: r#"<path d="M10 3.6 5.4 8 10 12.4" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>"#,
};
pub static CHEVRON_RIGHT: Icon = Icon {
name: "app-chevron-right",
view: 16.0,
body: r#"<path d="M6 3.6 10.6 8 6 12.4" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>"#,
};
+115 -45
View File
@@ -25,6 +25,9 @@ pub struct Review {
pub time: f64,
pub duration: f64,
pub scrubber_width: f32,
/// Where the scrubber starts in the window, in points, so an arrow drag can read the
/// pointer against the track.
pub scrubber_x: f32,
pub show_details: bool,
pub highlights: Vec<Highlight>,
/// The clip being chosen on the scrubber, once the Clip button is pressed.
@@ -180,15 +183,15 @@ impl Review {
};
}
/// Move the end of the selection nearest `press` to `at`, a second apart at least, and show
/// the picture there.
pub fn drag_clip(&mut self, press: f64, at: f64) {
/// Move one end of the selection to `at`, a second away from the other end at least, and
/// show the picture there. Only the arrows on the scrubber call this.
pub fn drag_clip_end(&mut self, start: bool, at: f64) {
let duration = self.duration.max(0.0);
let Some(clip) = &mut self.clip else {
return;
};
let at = at.clamp(0.0, duration);
let place = if clip.nearer_start(press) {
let place = if start {
clip.start = at.min(clip.end - 1.0).max(0.0);
clip.start
} else {
@@ -243,11 +246,6 @@ impl Clip {
pub fn length(&self) -> f64 {
(self.end - self.start).max(0.0)
}
/// Whether the pointer at `at` is nearer the clip's start than its end.
fn nearer_start(&self, at: f64) -> bool {
(at - self.start).abs() <= (at - self.end).abs()
}
}
impl Default for Review {
@@ -261,6 +259,7 @@ impl Default for Review {
time: 0.0,
duration: 0.0,
scrubber_width: 0.0,
scrubber_x: 0.0,
highlights: Vec::new(),
clip: None,
show_details: false,
@@ -850,7 +849,8 @@ fn scrubber(app: &App, p: Paint, game: &Timeline) -> El {
.range_value(app.review.time, 0.0, duration)
.w_full()
.h(34.0)
.on_layout(|app: &mut App, [_, _, w, _]| {
.on_layout(|app: &mut App, [x, _, w, _]| {
app.review.scrubber_x = x;
app.review.scrubber_width = w;
})
.on_step(|app: &mut App, steps, _| {
@@ -860,14 +860,7 @@ fn scrubber(app: &App, p: Paint, game: &Timeline) -> El {
.on_drag(move |app: &mut App, d: &mut rune::Drag, tx| {
let w = app.review.scrubber_width.max(1.0);
let at = (d.x / w).clamp(0.0, 1.0) as f64 * app.review.duration;
if app.review.clip.is_some() {
// In clip mode the pointer takes the end it pressed near, and the clip
// follows the drag; the transport keeps the play head.
let press = (d.start_x / w).clamp(0.0, 1.0) as f64 * app.review.duration;
app.review.drag_clip(press, at);
} else {
app.review.seek(at);
}
tx.instant();
})
.child(
@@ -900,22 +893,32 @@ fn scrubber(app: &App, p: Paint, game: &Timeline) -> El {
);
}
// The played part of the track. In clip mode it goes neutral: gold there marks the
// selection and nothing else.
let played = if app.review.clip.is_some() {
p.muted().alpha(0.4)
} else {
p.accent.alpha(0.55)
};
bar = bar.child(
el().key("played")
.w((width * progress).max(2.0))
.h(6.0)
.absolute(0.0, 12.0)
.radius(3.0)
.fill(p.accent.alpha(0.55))
.fill(played)
.a11y_hidden(),
);
// The clip being chosen: its span on the track, with a handle at each end to take hold of.
if let Some(clip) = app.review.clip {
// The clip being chosen: only its span is gold. The two ends are drawn after the knob, so
// their arrows stay visible over it.
let bounds = app.review.clip.map(|clip| {
let from = (clip.start / duration).clamp(0.0, 1.0) as f32 * width;
let to = (clip.end / duration).clamp(0.0, 1.0) as f32 * width;
bar = bar
.child(
(from, to)
});
if let Some((from, to)) = bounds {
bar = bar.child(
el().key("clip-span")
.w((to - from).max(2.0))
.h(6.0)
@@ -923,26 +926,6 @@ fn scrubber(app: &App, p: Paint, game: &Timeline) -> El {
.radius(3.0)
.fill(p.accent)
.a11y_hidden(),
)
.child(
el().key("clip-start-handle")
.w(3.0)
.h(16.0)
.absolute(from - 1.5, 7.0)
.radius(1.5)
.fill(p.accent_ink)
.shadow(0.0, 1.0, p.t.edge)
.a11y_hidden(),
)
.child(
el().key("clip-end-handle")
.w(3.0)
.h(16.0)
.absolute(to - 1.5, 7.0)
.radius(1.5)
.fill(p.accent_ink)
.shadow(0.0, 1.0, p.t.edge)
.a11y_hidden(),
);
}
// One tick per timeline event, below the track: every kill, objective and change the
@@ -984,16 +967,63 @@ fn scrubber(app: &App, p: Paint, game: &Timeline) -> El {
);
}
bar.child(
// The knob is centred on the play head, so an arrow at the same second sits on it.
let knob_x = (progress * width - knob / 2.0).clamp(0.0, width - knob);
bar = bar.child(
el().key("knob")
.size(knob, knob)
.absolute(progress * (width - knob), 8.0)
.absolute(knob_x, 8.0)
.radius(knob / 2.0)
.fill(p.t.knob)
.shadow(1.0, 3.0, p.t.knob_shadow)
.shadow(0.0, 0.5, p.t.edge)
.a11y_hidden(),
)
);
// The two ends of the selection, over the knob: an arrow each, and a drag that starts on
// one of them moves that end. A drag anywhere else still scrubs the video.
if let Some((from, to)) = bounds {
bar = bar
.child(clip_end(
p,
"clip-start-arrow",
&icons::CHEVRON_LEFT,
true,
from,
))
.child(clip_end(
p,
"clip-end-arrow",
&icons::CHEVRON_RIGHT,
false,
to,
));
}
bar
}
/// One end of the clip: a round gold arrow on the track, wide enough to take hold of. A drag
/// that starts on it moves that end and shows the picture there.
fn clip_end(p: Paint, key: &str, icon: &'static rune::Icon, start: bool, x: f32) -> El {
const SIZE: f32 = 18.0;
el().key(key)
.w(SIZE)
.h(SIZE)
.absolute(x - SIZE / 2.0, 15.0 - SIZE / 2.0)
.center()
.radius(SIZE / 2.0)
.fill(p.accent)
.border(1.0, p.t.bg)
.shadow(0.0, 1.0, p.t.edge)
.on_drag(move |app: &mut App, d: &mut rune::Drag, tx| {
let w = app.review.scrubber_width.max(1.0);
let track = (d.window_point()[0] - app.review.scrubber_x) / w;
let at = track.clamp(0.0, 1.0) as f64 * app.review.duration;
app.review.drag_clip_end(start, at);
tx.instant();
})
.child(rune::icon(icon, 12.0).color(p.accent_ink).a11y_hidden())
.a11y_hidden()
}
fn highlights(app: &App, p: Paint, game: &Timeline) -> El {
@@ -1224,3 +1254,43 @@ fn events(_app: &App, p: Paint, game: &Timeline) -> El {
),
)
}
#[cfg(test)]
mod tests {
use super::*;
fn review(start: f64, end: f64) -> Review {
Review {
duration: 100.0,
clip: Some(Clip { start, end }),
..Review::default()
}
}
#[test]
fn an_arrow_moves_its_own_end() {
let mut review = review(10.0, 20.0);
review.drag_clip_end(true, 4.0);
assert_eq!(review.clip.unwrap().start, 4.0);
review.drag_clip_end(false, 30.0);
assert_eq!(review.clip.unwrap().end, 30.0);
}
#[test]
fn the_ends_keep_a_second_apart() {
let mut review = review(10.0, 20.0);
review.drag_clip_end(true, 50.0);
assert_eq!(review.clip.unwrap().start, 19.0);
review.drag_clip_end(false, 0.0);
assert_eq!(review.clip.unwrap().end, 20.0);
}
#[test]
fn the_end_stops_at_the_recording_end() {
let mut review = review(10.0, 20.0);
review.drag_clip_end(false, 500.0);
assert_eq!(review.clip.unwrap().end, 100.0);
review.drag_clip_end(true, 0.0);
assert_eq!(review.clip.unwrap().start, 0.0);
}
}