app: draw the transport as icons and add a clip mode

The transport showed "Pause", "-10 s" and "+10 s" as words. It now shows
back, play or pause, and forward as shapes, with the words left to the
accessible label. The icons are SVG paths in `icons.rs`, so no font has
to carry them.

Clip mode: the Clip button opens a selection at the play head, the
scrubber drags either end (the end the press landed nearest), the span is
drawn on the track with a handle at each end, and the row under the
transport carries the range, Export clip and Done. Previewing stops at
the end of the selection.
This commit is contained in:
vhaudiquet committed 2026-11-19 00:48:32 +01:00
1 parent 4aac0ac70b
commit 4f2ee4256a
4 files changed
+286 -30

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
//! The few shapes the app draws itself: transport arrows, a play triangle and pause bars.
//!
//! Rune renders an [`Icon`] from SVG paths tinted with the element's colour, so these are plain
//! geometry at a 16 point box and need no font behind them.
use rune::Icon;
pub static PLAY: Icon = Icon {
name: "app-play",
view: 16.0,
body: r#"<path d="M5.4 3.4 12.6 8 5.4 12.6Z" fill="currentColor"/>"#,
};
pub static PAUSE: Icon = Icon {
name: "app-pause",
view: 16.0,
body: r#"<rect x="5" y="3.6" width="2.4" height="8.8" rx="0.6" fill="currentColor"/><rect x="8.6" y="3.6" width="2.4" height="8.8" rx="0.6" fill="currentColor"/>"#,
};
/// Two triangles pointing back: a step of ten seconds, as the button says.
pub static BACK: Icon = Icon {
name: "app-back",
view: 16.0,
body: r#"<path d="M2.8 8 7.2 4.6v6.8Z" fill="currentColor"/><path d="M7.6 8 12 4.6v6.8Z" fill="currentColor"/>"#,
};
pub static FORWARD: Icon = Icon {
name: "app-forward",
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"/>"#,
};
+1
View File
@@ -9,6 +9,7 @@ mod export;
mod format;
mod highlight;
mod history;
mod icons;
mod ipc;
mod os;
mod portraits;
+230 -30
View File
@@ -9,6 +9,7 @@ use crate::app::{App, Screen};
use crate::format;
use crate::highlight::{self, Highlight};
use crate::history::{self, Outcome, Timeline};
use crate::icons;
use crate::ui::{self, Paint, body, heading};
pub struct Review {
@@ -29,6 +30,8 @@ pub struct Review {
pub scrubber_width: f32,
pub show_details: bool,
pub highlights: Vec<Highlight>,
/// The clip being chosen on the scrubber, once the Clip button is pressed.
pub clip: Option<Clip>,
pub export: Option<Receiver<Result<String, String>>>,
pub export_note: Option<String>,
/// Soundtrack gain, 0 to 1; the transport bar sets it.
@@ -97,6 +100,36 @@ impl Review {
}
}
/// The Clip button: start a selection at the viewer's place, or drop the one on screen.
pub fn toggle_clip(&mut self) {
self.clip = match self.clip {
Some(_) => None,
None => {
let start = self.time.clamp(0.0, (self.duration - 1.0).max(0.0));
let end = (start + 30.0).min(self.duration.max(start + 1.0));
Some(Clip { start, end })
}
};
}
/// 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) {
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) {
clip.start = at.min(clip.end - 1.0).max(0.0);
clip.start
} else {
clip.end = at.max(clip.start + 1.0).min(duration);
clip.end
};
self.seek(place);
}
fn seek(&mut self, seconds: f64) {
let at = seconds.clamp(0.0, self.duration.max(0.0));
if let Some(player) = &self.player {
@@ -109,6 +142,24 @@ impl Review {
}
}
/// A clip being chosen on the scrubber: where it starts and where it ends.
#[derive(Clone, Copy)]
pub struct Clip {
pub start: f64,
pub end: f64,
}
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 {
fn default() -> Self {
Self {
@@ -121,6 +172,7 @@ impl Default for Review {
duration: 0.0,
scrubber_width: 0.0,
highlights: Vec::new(),
clip: None,
show_details: false,
export: None,
export_note: None,
@@ -272,6 +324,14 @@ pub fn tick(app: &mut App, tx: &mut Tx) -> bool {
}
follow_sound(app);
keep_in_step(app);
// A clip preview stops where the clip does: the selection is what is being watched.
if let Some(clip) = app.review.clip
&& playing(app)
&& app.review.time >= clip.end
{
app.review.playback();
changed = true;
}
if let Some(rx) = &app.review.export {
match rx.try_recv() {
Ok(Ok(path)) => {
@@ -473,30 +533,52 @@ fn volume(app: &App, p: Paint) -> El {
/// Play/pause, the ten-second steps and the clock, with the highlights toggle on the other
/// side: the list is one press away, not a column that always takes the clip's width.
/// Transport: back ten seconds, play or pause, forward ten seconds, then the clock and the
/// gain. The highlights toggle sits at the far end, one press away, and the Clip button opens
/// the selection row under the bar.
fn transport(app: &App, p: Paint) -> El {
let count = app.review.highlights.len();
let bar = row()
let mut bar = row()
.key("transport")
.w_full()
.center_y()
.gap(space::S2)
.child(ui::button(
.child(ui::media_button(
p,
"rewind",
&icons::BACK,
"Back 10 seconds",
false,
|app: &mut App| {
let at = app.review.time - 10.0;
app.review.seek(at);
},
))
.child(ui::media_button(
p,
"play-pause",
if playing(app) {
&icons::PAUSE
} else {
&icons::PLAY
},
if playing(app) { "Pause" } else { "Play" },
false,
true,
|app: &mut App| {
app.review.playback();
},
))
.child(ui::button(p, "rewind", "-10 s", false, |app: &mut App| {
let at = app.review.time - 10.0;
app.review.seek(at);
}))
.child(ui::button(p, "advance", "+10 s", false, |app: &mut App| {
let at = app.review.time + 10.0;
app.review.seek(at);
}))
.child(ui::media_button(
p,
"advance",
&icons::FORWARD,
"Forward 10 seconds",
false,
|app: &mut App| {
let at = app.review.time + 10.0;
app.review.seek(at);
},
))
.child(
text(format!(
"{} / {}",
@@ -509,30 +591,106 @@ fn transport(app: &App, p: Paint) -> El {
)
.child(volume(app, p))
.child(el().grow(1.0));
let bar = match &app.review.export_note {
Some(note) => bar.child(
if let Some(note) = &app.review.export_note {
bar = bar.child(
text(note.clone())
.key("export-note")
.font(body(11.5))
.color(p.muted()),
),
None => bar,
};
bar.child(ui::button(
p,
"toggle-details",
&if app.review.show_details {
"Hide details".to_string()
} else {
format!("Highlights · {count}")
},
false,
|app: &mut App| {
app.review.show_details = !app.review.show_details;
},
))
);
}
let bar = bar
.child(ui::button(
p,
"clip",
"Clip",
app.review.clip.is_some(),
|app: &mut App| app.review.toggle_clip(),
))
.child(ui::button(
p,
"toggle-details",
&if app.review.show_details {
"Hide details".to_string()
} else {
format!("Highlights · {count}")
},
false,
|app: &mut App| {
app.review.show_details = !app.review.show_details;
},
));
let mut column = col()
.key("transport-bar")
.w_full()
.gap(space::S2)
.child(bar);
if let Some(clip) = app.review.clip {
column = column.child(clip_row(app, p, clip));
}
column
}
/// The row under the transport while a clip is being chosen: the two ends, its length, and the
/// two things to do with it.
fn clip_row(app: &App, p: Paint, clip: Clip) -> El {
let video = app
.reviewed()
.and_then(|game| game.video_path())
.map(|path| path.display().to_string());
let name = app
.reviewed()
.map(|game| format!("{}-clip", game.recording_id))
.unwrap_or_default();
let mut actions = row()
.key("clip-actions")
.center_y()
.gap(space::S2)
.child(
text(format!(
"Clip {} to {} · {}",
format::clock(clip.start),
format::clock(clip.end),
format::clock(clip.length())
))
.key("clip-range")
.font(type_::MONO_CAPTION)
.color(p.muted()),
)
.child(el().grow(1.0));
if let Some(video) = video {
actions = actions.child(ui::button(
p,
"export-clip",
"Export clip",
true,
move |app: &mut App| {
let (tx, rx) = channel();
let video = video.clone();
let name = name.clone();
let (start, end) = match app.review.clip {
Some(clip) => (clip.start, clip.end),
None => return,
};
std::thread::spawn(move || {
let result =
crate::export::export_clip(&video, start, end, &name, true, "high");
let _ = tx.send(result);
});
app.review.export = Some(rx);
app.review.export_note = Some("Exporting clip…".into());
},
));
}
actions.child(ui::button(
p,
"clip-done",
"Done",
false,
|app: &mut App| app.review.clip = None,
))
}
fn playing(app: &App) -> bool {
app.review.player.as_ref().is_some_and(Player::is_playing)
}
@@ -565,7 +723,14 @@ 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;
app.review.seek(at);
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(
@@ -608,6 +773,41 @@ fn scrubber(app: &App, p: Paint, game: &Timeline) -> El {
.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 {
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(
el().key("clip-span")
.w((to - from).max(2.0))
.h(6.0)
.absolute(from, 12.0)
.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
// recording has, not only the player's own.
for (index, event) in game.events.iter().enumerate() {
+24
View File
@@ -434,6 +434,30 @@ pub fn button(
)
}
/// One transport control: an icon, its accessible label, round like the bar it sits in.
pub fn media_button(
p: Paint,
key: &str,
icon: &'static rune::Icon,
label: &str,
primary: bool,
on_press: impl Fn(&mut App) + Send + Sync + 'static,
) -> El {
let ink = if primary { p.accent_ink } else { p.t.text };
el().key(key)
.role("button")
.label(label)
.focusable(true)
.size(32.0, 32.0)
.center()
.radius(radius::MD)
.fill(if primary { p.accent } else { p.t.control_off })
.hover(p.t.hover)
.press(p.t.press)
.on_press(on_press)
.child(rune::icon(icon, 16.0).color(ink).a11y_hidden())
}
/// A small square button holding one glyph, for the corner of a card or a dialog.
pub fn icon_button(
p: Paint,