app: draw champion portraits, a 16:9 player and draggable scroll bars

Cards and the review header showed two initials where a champion
portrait belongs. Data Dragon is fetched from a worker thread and cached
under the user's cache directory, so the first sight of a champion puts
its face on the card and later runs read it from disk; offline, the tile
keeps its initials on the champion's colour.

The review screen put the clip in a small box above two list columns.
The clip now fills the window at 16:9 and the highlights and timeline
open beside it on demand, so nothing shrinks the video by default and
every event still marks the scrubber.

Scroll bars were a thumb drawn over the cards that could not be
dragged. They now sit in a strip the content leaves free, stay visible
while the list overflows, and scroll the viewport when dragged.
This commit is contained in:
vhaudiquet committed 2026-11-16 18:24:39 +01:00
1 parent 3d0cad3312
commit 227aecb8f6
10 files changed
+500 -181

No files matched your search

+99 -13
View File
@@ -11,6 +11,7 @@ pub struct Paint {
pub accent: Color,
pub dark: bool,
pub hair: f32,
pub scale: f32,
}
impl Paint {
@@ -20,6 +21,7 @@ impl Paint {
accent: tok::accent(0, dark),
dark,
hair: 1.0 / scale,
scale,
}
}
@@ -346,8 +348,70 @@ pub fn dot(color: Color) -> El {
.a11y_hidden()
}
/// A scroll viewport's scrollbar. The viewport reports where it is; the thumb follows in the
/// same frame, so a drag scrolls the list and the bar together.
/// A square champion portrait at `size` points: the Data Dragon file once it is on disk,
/// initials on a colour derived from the name until then (and offline).
pub fn champion_portrait(app: &App, p: Paint, champion: Option<&str>, size: f32) -> El {
let name = champion.unwrap_or_default();
let hue = name
.bytes()
.fold(2166136261u32, |hash, byte| {
hash.wrapping_mul(16777619) ^ byte as u32
})
.rem_euclid(360) as f32;
let (fill, ink) = if name.is_empty() {
(p.t.control_off, p.muted())
} else {
(rune::oklch(0.36, 0.075, hue), rune::oklch(0.94, 0.02, hue))
};
let radius = (size * 0.14).max(2.0);
let tile = el()
.key("portrait")
.size(size, size)
.radius(radius)
.fill(fill)
.border(p.hair, ink.alpha(0.18))
.a11y_hidden();
match app
.portraits
.as_ref()
.and_then(|portraits| portraits.image(name, size, p.scale))
{
Some(image) => tile.child(
el().key("portrait-image")
.w_full()
.h_full()
.radius(radius)
.pixels(image.pixels()),
),
None => tile.child(
text(initials(name))
.font(heading(size * 0.33))
.color(ink)
.center(),
),
}
}
/// Up to two letters from the champion's name: `Kai'Sa` is KS, `Jinx` is J.
fn initials(name: &str) -> String {
let letters: Vec<char> = name
.split(|c: char| !c.is_alphanumeric())
.filter(|word| !word.is_empty())
.filter_map(|word| word.chars().next())
.take(2)
.collect();
if letters.is_empty() {
"?".into()
} else {
letters.into_iter().collect()
}
}
/// A scroll viewport's scroll bar: a thumb in a strip of its own at the viewport's end edge,
/// shown whenever the content overflows, and dragged to scroll.
///
/// The screen lays the thumb where the viewport's strip is (the content leaves it room), so it
/// never draws over a card. `follow` takes where the viewport is, `thumb` draws it.
pub struct ScrollBar {
area: rune::Live<[f32; 4]>,
thumb: rune::Live<[f32; 4]>,
@@ -369,35 +433,57 @@ impl ScrollBar {
}
}
/// Make this viewport's scrolling move the thumb.
pub fn follow(&self, viewport: El) -> El {
/// Make this viewport's scrolling move the thumb, and its key one a drag can scroll to.
pub fn follow(&self, key: &'static str, viewport: El) -> El {
let reported = self.area.clone();
let area = self.area.clone();
let last = self.last.clone();
let on_layout_last = self.last.clone();
let on_layout_thumb = self.thumb.clone();
let thumb = self.thumb.clone();
let layout_thumb = self.thumb.clone();
let last = self.last.clone();
let layout_last = self.last.clone();
viewport
.on_layout_tx(move |_app: &mut App, rect, tx| {
reported.set(rect);
place(&on_layout_thumb, rect, on_layout_last.get());
place(&layout_thumb, rect, layout_last.get());
tx.live_only();
})
.on_scroll_offset(move |at: rune::ScrollPos| {
last.set(at);
place(&thumb, area.get(), at);
})
.key(key)
}
/// The thumb, drawn over the window. `key` must differ per bar on one screen.
pub fn thumb(&self, p: Paint, key: &str) -> El {
pub fn thumb(&self, p: Paint, key: &'static str, viewport: &'static str) -> El {
let last = self.last.clone();
let area = self.area.clone();
el().key(key)
.absolute(0.0, 0.0)
.size(6.0, 0.0)
.radius(3.0)
.fill(p.t.text_secondary.alpha(0.5))
.size(10.0, 0.0)
.radius(5.0)
.fill(p.t.text_secondary.alpha(0.45))
.hover(p.t.text_secondary.alpha(0.8))
.live_rect(&self.thumb)
.a11y_hidden()
.on_drag_any(move |d: &mut rune::Drag, tx: &mut rune::Tx| {
tx.live_only();
let at = last.get();
let max = at.max[1];
let [_, _, _, area_h] = area.get();
let travel = (area_h - d.h).max(1.0);
if max <= 0.5 || area_h <= 1.0 {
return;
}
match d.phase {
rune::Phase::Down => d.data = at.offset[1],
rune::Phase::Move => {
let y = (d.data + d.dy * max / travel).clamp(0.0, max);
tx.scroll_to(viewport, 0.0, y);
}
rune::Phase::Up => {}
}
})
}
}
@@ -410,5 +496,5 @@ fn place(thumb: &rune::Live<[f32; 4]>, [x, y, w, h]: [f32; 4], at: rune::ScrollP
}
let height = (h * at.viewport[1] / content).clamp(28.0, h);
let progress = (at.offset[1] / at.max[1]).clamp(0.0, 1.0);
thumb.set([x + w - 9.0, y + progress * (h - height), 6.0, height]);
thumb.set([x + w - 12.0, y + progress * (h - height), 10.0, height]);
}