app: cherry-pick rune's pause and sound fixes onto the checkout

Rune comes from app/vendor/rune now, a checkout of 63ad0209 on branch
ported, carrying the four commits of upstream issues 1320 (a pause while
a clip is layered holds the layer's picture and time) and 1325 (a video's
sound is read ahead of the clock and leads it). Both were written against
eb9f1104 and ported across the refactors since. The faults are the first
two and the third in docs/rune-upstream.md; the app's workarounds in
review.rs stay until the fixes arrive upstream.
This commit is contained in:
vhaudiquet committed 2026-11-22 22:16:30 +01:00
1 parent 80fef698ce
commit 5bf262b82b
3795 files changed
+663463 -28

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
[package]
name = "sketch"
version = "0.0.1"
edition.workspace = true
license.workspace = true
[dependencies]
rune = { workspace = true, default-features = true, features = ["keys-overlay"] }
[lints]
workspace = true
Binary file not shown.

After

Width:  |  Height:  |  Size: 787 B

+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/env python3
"""Draws assets/pencil.png: a 64x64 px (32x32 pt at 2x) pencil cursor, tip at (4, 60) px."""
import math, os, struct, zlib
SIZE, SS = 64, 4
TIP, W = (4.0, 60.0), 6.5
D = (1 / math.sqrt(2), -1 / math.sqrt(2))
N = (-D[1], D[0])
# The silhouette in pencil space (u along the pencil from the tip, v across it): convex.
HULL = [(0.0, 0.0), (16.0, -W), (74.0, -W), (74.0, W), (16.0, W)]
def hexc(h): return tuple(int(h[i:i + 2], 16) / 255 for i in (0, 2, 4))
INK, HALO = hexc("1d1d1f"), (1.0, 1.0, 1.0)
def inside(u, v): return 0 <= u <= 74 and abs(v) <= min(W, W * u / 16)
def edge_dist(u, v):
best = 1e9
for (au, av), (bu, bv) in zip(HULL, HULL[1:] + HULL[:1]):
eu, ev = bu - au, bv - av
t = max(0.0, min(1.0, ((u - au) * eu + (v - av) * ev) / (eu * eu + ev * ev)))
best = min(best, math.hypot(u - au - t * eu, v - av - t * ev))
return best
def fill(u, v):
if u < 5: return INK
if u < 16: return hexc("e8c39e")
if u < 62: return hexc("d9a800") if v < -W / 3 else hexc("ffd84d") if v > W / 3 else hexc("f5c518")
if u < 66: return hexc("a9a9b2")
return hexc("f08a9a")
def sample(x, y):
px, py = x - TIP[0], y - TIP[1]
u, v = px * D[0] + py * D[1], px * N[0] + py * N[1]
d = edge_dist(u, v)
if inside(u, v):
return (INK if d < 0.8 or 61.6 < u < 62.4 or 65.6 < u < 66.4 else fill(u, v)) + (1.0,)
if d < 0.8: return INK + (1.0,)
if d < 2.0: return HALO + (1.0,)
return (0.0, 0.0, 0.0, 0.0)
rows = []
for y in range(SIZE):
row = bytearray([0])
for x in range(SIZE):
acc = [0.0] * 4
for j in range(SS):
for i in range(SS):
r, g, b, a = sample(x + (i + 0.5) / SS, y + (j + 0.5) / SS)
acc[0] += r * a; acc[1] += g * a; acc[2] += b * a; acc[3] += a
a = acc[3] / (SS * SS)
rgb = [c / acc[3] if acc[3] else 0.0 for c in acc[:3]]
row += bytes(round(c * 255) for c in rgb + [a])
rows.append(bytes(row))
def chunk(kind, data):
return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data))
png = b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", SIZE, SIZE, 8, 6, 0, 0, 0)) \
+ chunk(b"IDAT", zlib.compress(b"".join(rows), 9)) + chunk(b"IEND", b"")
out = os.path.join(os.path.dirname(__file__), "..", "assets", "pencil.png")
open(out, "wb").write(png)
print(f"{out}: {len(png)} bytes")
+61
View File
@@ -0,0 +1,61 @@
//! A pencil over a canvas: `Cursor::Image` with a 2x PNG, its hot spot on the tip. Drag to
//! draw. `cargo run -p sketch`. `scripts/pencil.py` draws `assets/pencil.png`.
#![forbid(unsafe_code)]
use rune::tok::{self, radius, space, type_};
use rune::{AppSpec, Color, Cursor, CursorImage, Cx, El, LineCap, Phase, Shape, canvas, col, text};
/// 64×64 px, so 32×32 pt, with the graphite tip at (2, 30) pt.
const PENCIL: CursorImage = CursorImage::png(include_bytes!("../assets/pencil.png"), [2.0, 30.0]);
const INK: Color = Color { r: 0.11, g: 0.11, b: 0.12, a: 1.0 };
#[derive(Default)]
struct State {
strokes: Vec<Vec<[f32; 2]>>,
}
fn drawing(s: &State) -> Shape {
s.strokes.iter().fold(Shape::new(), |shape, stroke| match stroke.as_slice() {
[p] => shape.line(*p, *p, 2.5, LineCap::Round, INK),
points => shape.stroke(points.to_vec(), 2.5, INK),
})
}
fn view(s: &State, _: &mut Cx<State>) -> El {
let t = tok::theme(false);
col().w_full().h_full().padding(space::S6).gap(space::S3).fill(t.bg)
.child(text("Drag to draw").font(type_::BODY).color(t.text_secondary))
.child(canvas(drawing(s)).key("paper").w_full().grow(1.0).radius(radius::LG)
.fill(Color::WHITE).border(1.0, t.card_border)
.cursor(Cursor::Image(PENCIL))
.on_drag(|s: &mut State, d, _| match d.phase {
Phase::Down => s.strokes.push(vec![[d.x, d.y]]),
_ => if let Some(stroke) = s.strokes.last_mut() { stroke.push([d.x, d.y]) },
}))
}
fn main() {
rune::run(AppSpec::new("Sketch", (560.0, 420.0), State::default, view));
}
#[cfg(test)]
mod tests {
use super::*;
use rune::{Env, Runtime};
#[test]
fn the_paper_shows_the_pencil_and_takes_strokes() {
let mut rt = Runtime::new(State::default(), view, (560.0, 420.0), Env { system_dark: false, scale: 2.0 });
rt.frame(0.0);
let (x, y) = rt.find("paper").unwrap();
rt.pointer_move(x, y);
assert_eq!(rt.cursor(), Cursor::Image(PENCIL));
rt.pointer_down(x, y);
rt.pointer_move(x + 30.0, y + 10.0);
rt.pointer_up(x + 30.0, y + 10.0);
rt.frame(0.0);
assert_eq!(rt.state.strokes.len(), 1);
assert!(rt.state.strokes[0].len() >= 2, "{:?}", rt.state.strokes);
}
}