app: unmute clips and put their controls on the picture

A clip opened muted, and its transport sat in a row under the stage.
Clips now start with sound on, and the controls sit over the bottom of
the video: a time bar that seeks by press or drag, the clock, play and
pause, two-second jumps either way, and mute. They rest visible while
the clip is paused and hide while it plays, coming back when the pointer
enters the player. The overlay follows the player's clock, so the bar
and the time move with the picture.
This commit is contained in:
vhaudiquet committed 2026-11-23 19:47:04 +01:00
1 parent 5377d88ca6
commit 531238039d
2 files changed
+284 -109

No files matched your search

+14
View File
@@ -50,6 +50,20 @@ pub static SHARE: Icon = Icon {
body: r#"<path d="M8 9.4V2.4" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/><path d="M5.3 4.7 8 2l2.7 2.7" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M5.7 6.9H4.8c-1 0-1.8.8-1.8 1.8v3.5c0 1 .8 1.8 1.8 1.8h6.4c1 0 1.8-.8 1.8-1.8V8.7c0-1-.8-1.8-1.8-1.8h-.9" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>"#, body: r#"<path d="M8 9.4V2.4" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/><path d="M5.3 4.7 8 2l2.7 2.7" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M5.7 6.9H4.8c-1 0-1.8.8-1.8 1.8v3.5c0 1 .8 1.8 1.8 1.8h6.4c1 0 1.8-.8 1.8-1.8V8.7c0-1-.8-1.8-1.8-1.8h-.9" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>"#,
}; };
/// A speaker with sound waves: the clip plays its sound.
pub static VOLUME: Icon = Icon {
name: "app-volume",
view: 16.0,
body: r#"<path d="M2.8 6.2h2.2L8 3.6v8.8L5 9.8H2.8Z" fill="currentColor"/><path d="M10.2 5.6a3.4 3.4 0 0 1 0 4.8" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/><path d="M12 3.8a5.8 5.8 0 0 1 0 8.4" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/>"#,
};
/// The same speaker crossed out: the clip is muted.
pub static VOLUME_OFF: Icon = Icon {
name: "app-volume-off",
view: 16.0,
body: r#"<path d="M2.8 6.2h2.2L8 3.6v8.8L5 9.8H2.8Z" fill="currentColor"/><path d="M10.4 6 13.8 9.4M13.8 6 10.4 9.4" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/>"#,
};
/// Three vertical dots: the button that opens a card's menu of actions. /// Three vertical dots: the button that opens a card's menu of actions.
pub static DOTS: Icon = Icon { pub static DOTS: Icon = Icon {
name: "app-dots", name: "app-dots",
+270 -109
View File
@@ -3,6 +3,8 @@
//! The grid opens it on a card, and an export opens it when the clip lands. The title is //! The grid opens it on a card, and an export opens it when the clip lands. The title is
//! the file's name: saving renames the clip, and the grid follows. //! the file's name: saving renames the clip, and the grid follows.
use std::time::Duration;
use rune::tok::{radius, space, type_}; use rune::tok::{radius, space, type_};
use rune::{ use rune::{
ClipboardContent, Color, El, Player, PlayerState, SurfaceFit, TextEdit, Tx, auto_grow, col, el, ClipboardContent, Color, El, Player, PlayerState, SurfaceFit, TextEdit, Tx, auto_grow, col, el,
@@ -24,12 +26,17 @@ pub struct ClipView {
pub player: Option<Player>, pub player: Option<Player>,
/// Shown over the stage when the file refuses to play. /// Shown over the stage when the file refuses to play.
pub error: Option<String>, pub error: Option<String>,
/// Whether the clip plays without sound; a clip opens muted. /// Whether the clip plays without sound. A clip opens with its sound on.
pub muted: bool, pub muted: bool,
/// The time bar width in points, from its layout, so a drag can read the pointer.
pub bar_width: f32,
/// Where the player is and how long the clip is, read in `tick` so the bar and clock move.
pub at: f64,
pub long: f64,
} }
/// Open a clip by name, from the grid's list. The screen switches here and the clip plays, /// Open a clip by name, from the grid's list. The screen switches here and the clip plays,
/// muted and looping, until the view is left. /// with sound and looping, until the view is left.
pub fn open(app: &mut App, name: &str) { pub fn open(app: &mut App, name: &str) {
if !app.clips.iter().any(|clip| clip.name == name) { if !app.clips.iter().any(|clip| clip.name == name) {
app.refresh_clips(); app.refresh_clips();
@@ -46,7 +53,7 @@ pub fn open(app: &mut App, name: &str) {
}; };
let player = Player::file(&video); let player = Player::file(&video);
player.set_looping(true); player.set_looping(true);
player.set_muted(true); player.set_muted(false);
if let Some(waker) = &app.waker { if let Some(waker) = &app.waker {
player.set_waker(waker.clone()); player.set_waker(waker.clone());
} }
@@ -56,15 +63,43 @@ pub fn open(app: &mut App, name: &str) {
title: TextEdit::new(clip.name.clone()), title: TextEdit::new(clip.name.clone()),
player: Some(player), player: Some(player),
error: None, error: None,
muted: true, muted: false,
bar_width: 0.0,
at: 0.0,
long: 0.0,
}); });
app.screen = Screen::Clip; app.screen = Screen::Clip;
} }
/// Hand a pending share to the clipboard worker, and say so. /// Follow the clip's clock so the bar and the time move, and hand a pending share to the
/// clipboard worker.
pub fn tick(app: &mut App, tx: &mut Tx) -> bool { pub fn tick(app: &mut App, tx: &mut Tx) -> bool {
let mut changed = false;
if let Some(view) = &mut app.clip {
let state = view
.player
.as_ref()
.map(|player| (player.time(), player.duration(), player.is_playing()));
if let Some((at, long, playing)) = state {
if (at - view.at).abs() > 0.001 {
view.at = at;
changed = true;
}
if let Some(long) = long
&& long > 0.0
&& (long - view.long).abs() > 0.05
{
view.long = long;
changed = true;
}
// The picture only moves when the window draws it, so keep drawing while it plays.
if playing {
tx.wake_after(Duration::from_millis(33));
}
}
}
let Some(path) = app.share_clip.take() else { let Some(path) = app.share_clip.take() else {
return false; return changed;
}; };
tx.copy_rich(ClipboardContent::default().with_files([path])); tx.copy_rich(ClipboardContent::default().with_files([path]));
app.notify("Clip copied. Paste it anywhere."); app.notify("Clip copied. Paste it anywhere.");
@@ -190,9 +225,7 @@ pub fn view(app: &App, p: Paint) -> El {
.grow(1.0) .grow(1.0)
.min_w(0.0) .min_w(0.0)
.min_h(0.0) .min_h(0.0)
.gap(space::S2) .child(video_stage(app, p)),
.child(video_stage(app, p))
.child(transport(app, p)),
) )
.child( .child(
col() col()
@@ -289,11 +322,9 @@ pub fn view(app: &App, p: Paint) -> El {
.child(body) .child(body)
} }
/// The stage: the clip's video on black, 16 points of nine everywhere it fits. /// The stage: the clip on black, the largest 16:9 box that fits, with the controls drawn over
/// it.
fn video_stage(app: &App, p: Paint) -> El { fn video_stage(app: &App, p: Paint) -> El {
let Some(view) = &app.clip else {
return col().key("stage").w_full().grow(1.0).min_h(0.0);
};
let stage = col() let stage = col()
.key("stage") .key("stage")
.w_full() .w_full()
@@ -302,118 +333,248 @@ fn video_stage(app: &App, p: Paint) -> El {
.fill(Color::BLACK) .fill(Color::BLACK)
.radius(radius::LG) .radius(radius::LG)
.clip_soft(radius::LG) .clip_soft(radius::LG)
.hover_group()
.center(); .center();
match &view.player { let Some(view) = &app.clip else {
Some(player) => { return stage;
if let PlayerState::Failed(message) = player.state() { };
stage.child( let Some(player) = &view.player else {
text(format!("The clip does not play: {message}")) return stage.child(
.key("stage-error")
.font(body(13.0))
.color(p.muted()),
)
} else {
stage.child(
el().key("video")
.aspect_fit(16.0 / 9.0)
.video(player, SurfaceFit::Fill),
)
}
}
None => stage.child(
text(view.error.clone().unwrap_or_else(|| "No clip open.".into())) text(view.error.clone().unwrap_or_else(|| "No clip open.".into()))
.key("stage-message") .key("stage-message")
.font(body(13.0)) .font(body(13.0))
.color(p.muted()), .color(p.muted()),
), );
};
if let PlayerState::Failed(message) = player.state() {
return stage.child(
text(format!("The clip does not play: {message}"))
.key("stage-error")
.font(body(13.0))
.color(p.muted()),
);
} }
stage.child(
el().key("player-frame")
.aspect_fit(16.0 / 9.0)
.radius(radius::LG)
.clip_soft(radius::LG)
.fill(Color::BLACK)
.child(
el().key("video")
.w_full()
.h_full()
.video(player, SurfaceFit::Fill),
)
.child(controls(app, p, player)),
)
} }
/// Play and pause, a couple of seconds either way, and the sound. /// The controls over the bottom of the picture: the time bar, play and pause, a couple of
fn transport(app: &App, p: Paint) -> El { /// seconds either way, and the sound. They rest visible while the clip stands still and hide
let playing = app /// while it plays, showing again when the pointer comes over the player.
.clip fn controls(app: &App, p: Paint, player: &Player) -> El {
.as_ref() let playing = player.is_playing();
.and_then(|view| view.player.as_ref())
.is_some_and(Player::is_playing);
let at = app
.clip
.as_ref()
.and_then(|view| view.player.as_ref())
.map(Player::time)
.unwrap_or(0.0);
let long = app
.clip
.as_ref()
.and_then(|view| view.player.as_ref())
.and_then(Player::duration)
.unwrap_or(0.0);
let muted = app.clip.as_ref().is_some_and(|view| view.muted); let muted = app.clip.as_ref().is_some_and(|view| view.muted);
row() let at = app.clip.as_ref().map_or(0.0, |view| view.at);
.key("transport") let long = app.clip.as_ref().map_or(0.0, |view| view.long);
.w_full() col()
.center_y() .key("controls")
.pin(Some(0.0), Some(0.0), Some(0.0), Some(0.0))
.justify_end()
.gap(space::S2) .gap(space::S2)
.child(ui::media_button( .px(16.0)
p, .pb(space::S3)
"rewind", .gradient(Color::TRANSPARENT, Color::BLACK.alpha(0.68))
&icons::BACK, .group_opacity(if playing { 0.0 } else { 1.0 }, 1.0)
"Back 2 seconds", .child(time_bar(app, p, at, long))
false,
|app: &mut App| seek(app, -2.0),
))
.child(ui::media_button(
p,
"play-pause",
if playing { &icons::PAUSE } else { &icons::PLAY },
if playing { "Pause" } else { "Play" },
true,
|app: &mut App| {
if let Some(player) = app.clip.as_ref().and_then(|view| view.player.as_ref()) {
if player.is_playing() {
player.pause();
} else {
player.play();
}
}
},
))
.child(ui::media_button(
p,
"advance",
&icons::FORWARD,
"Forward 2 seconds",
false,
|app: &mut App| seek(app, 2.0),
))
.child( .child(
text(format!("{} / {}", format::clock(at), format::clock(long))) row()
.key("clock") .key("transport")
.font(type_::MONO_CAPTION) .w_full()
.color(p.muted()), .center_y()
.gap(space::S2)
.child(overlay_button(
p,
"rewind",
&icons::BACK,
"Back 2 seconds",
false,
|app: &mut App| seek(app, -2.0),
))
.child(overlay_button(
p,
"play-pause",
if playing { &icons::PAUSE } else { &icons::PLAY },
if playing { "Pause" } else { "Play" },
true,
|app: &mut App| {
if let Some(player) =
app.clip.as_ref().and_then(|view| view.player.as_ref())
{
if player.is_playing() {
player.pause();
} else {
player.play();
}
}
},
))
.child(overlay_button(
p,
"advance",
&icons::FORWARD,
"Forward 2 seconds",
false,
|app: &mut App| seek(app, 2.0),
))
.child(
text(format!("{} / {}", format::clock(at), format::clock(long)))
.key("clock")
.font(type_::MONO_CAPTION)
.color(Color::WHITE.alpha(0.9)),
)
.child(el().grow(1.0))
.child(overlay_button(
p,
"mute",
if muted {
&icons::VOLUME_OFF
} else {
&icons::VOLUME
},
if muted { "Unmute" } else { "Mute" },
false,
|app: &mut App| {
if let Some(view) = &mut app.clip {
view.muted = !view.muted;
if let Some(player) = &view.player {
player.set_muted(view.muted);
}
}
},
)),
)
}
/// An icon button for the dark picture: the theme's control colours are made for surfaces,
/// and the picture is black in either appearance.
fn overlay_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 { Color::WHITE };
el().key(key)
.role("button")
.label(label)
.focusable(true)
.size(32.0, 32.0)
.center()
.radius(radius::MD)
.fill(if primary {
p.accent
} else {
Color::WHITE.alpha(0.16)
})
.hover(Color::WHITE.alpha(0.1))
.press(Color::WHITE.alpha(0.18))
.on_press(on_press)
.child(rune::icon(icon, 16.0).color(ink).a11y_hidden())
}
/// The clip's progress, over the picture. A press or a drag anywhere on it seeks.
fn time_bar(app: &App, p: Paint, at: f64, long: f64) -> El {
// The width the bar was last given; a drag reads the pointer against it.
let width = app.clip.as_ref().map_or(0.0, |view| view.bar_width);
let w = if width > 0.0 { width } else { 600.0 };
let progress = if long > 0.0 {
(at / long).clamp(0.0, 1.0) as f32
} else {
0.0
};
let (height, bar, knob) = (18.0, 4.0, 11.0);
el().key("time-bar")
.role("slider")
.label("Playback position")
.range_value(at, 0.0, long.max(0.001))
.range_step(5.0)
.w_full()
.h(height)
.on_layout(|app: &mut App, [_, _, w, _]| {
if let Some(view) = &mut app.clip {
view.bar_width = w;
}
})
.on_step(|app: &mut App, steps, _| seek(app, steps as f64 * 5.0))
.on_drag(|app: &mut App, d: &mut rune::Drag, tx| {
let long = app.clip.as_ref().map_or(0.0, |view| view.long);
let width = app
.clip
.as_ref()
.map_or(0.0, |view| view.bar_width)
.max(1.0);
if long <= 0.0 {
return;
}
let at = (d.x / width).clamp(0.0, 1.0) as f64 * long;
if let Some(player) = app.clip.as_ref().and_then(|view| view.player.as_ref()) {
player.seek(at);
}
if let Some(view) = &mut app.clip {
view.at = at;
}
tx.instant();
})
.child(
el().key("track")
.w_full()
.h(bar)
.absolute(0.0, (height - bar) / 2.0)
.radius(bar / 2.0)
.fill(Color::WHITE.alpha(0.22))
.a11y_hidden(),
)
.child(
el().key("played")
.w(w * progress)
.h(bar)
.absolute(0.0, (height - bar) / 2.0)
.radius(bar / 2.0)
.fill(p.accent.alpha(0.9))
.a11y_hidden(),
)
.child(
el().key("knob")
.size(knob, knob)
.absolute(
(progress * (w - knob)).clamp(0.0, (w - knob).max(1.0)),
(height - knob) / 2.0,
)
.radius(knob / 2.0)
.fill(Color::WHITE)
.shadow(0.0, 1.0, Color::BLACK.alpha(0.35))
.a11y_hidden(),
) )
.child(el().grow(1.0))
.child(ui::button(
p,
"mute",
if muted { "Unmute" } else { "Mute" },
false,
|app: &mut App| {
if let Some(view) = &mut app.clip {
view.muted = !view.muted;
if let Some(player) = &view.player {
player.set_muted(view.muted);
}
}
},
))
} }
/// Move the clip's player by `seconds`, held to the clip's length. /// Move the clip's player by `seconds`, held to the clip's length.
fn seek(app: &mut App, seconds: f64) { fn seek(app: &mut App, seconds: f64) {
if let Some(player) = app.clip.as_ref().and_then(|view| view.player.as_ref()) { let at = app
let long = player.duration().unwrap_or(0.0); .clip
player.seek((player.time() + seconds).clamp(0.0, long)); .as_ref()
.and_then(|view| view.player.as_ref())
.map(|player| {
let long = player.duration().unwrap_or(0.0);
let at = (player.time() + seconds).clamp(0.0, long);
player.seek(at);
at
});
if let (Some(at), Some(view)) = (at, app.clip.as_mut()) {
view.at = at;
} }
} }