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:
1 parent
80fef698ce
commit
5bf262b82b
3795 files changed
+663463
-28
No files matched your search
+17
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "web-hello"
|
||||
version = "0.0.1"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
rune = { workspace = true, default-features = true, features = ["keys-overlay"] }
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
wasm-bindgen = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 289 B |
Binary file not shown.
|
After Width: | Height: | Size: 83 B |
@@ -0,0 +1,57 @@
|
||||
//! Browser image-decode fixture, selected only by ?image-proof: a JPEG the browser decodes and a
|
||||
//! PNG Rune decodes, both from bytes, and the PNG again as the cursor over it.
|
||||
use rune::{AppSpec, Cursor, CursorImage, Cx, El, Image, ImageCache, col, el};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(inline_js = "
|
||||
export function imageProof() { return new URLSearchParams(location.search).has('image-proof'); }
|
||||
export function imageReport(name, width, height, error) {
|
||||
(window.__imageProof ||= {})[name] = error ? { error } : { width, height };
|
||||
}
|
||||
")]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_name = imageProof)]
|
||||
pub fn enabled() -> bool;
|
||||
#[wasm_bindgen(js_name = imageReport)]
|
||||
fn report(name: &str, width: u32, height: u32, error: &str);
|
||||
}
|
||||
|
||||
const PNG: &[u8] = include_bytes!("../assets/proof.png");
|
||||
const CURSOR: CursorImage = CursorImage::png(PNG, [1.0, 2.0]);
|
||||
|
||||
#[derive(Default)]
|
||||
struct State {
|
||||
cache: Option<ImageCache>,
|
||||
images: Vec<(&'static str, Image)>,
|
||||
}
|
||||
|
||||
fn view(s: &State, _: &mut Cx<State>) -> El {
|
||||
let mut out = col().w_full().h_full().padding(16.0).gap(8.0);
|
||||
for (name, image) in &s.images {
|
||||
out = out.child(el().key(*name).w(120.0).h(60.0).pixels(image.pixels())
|
||||
.cursor(Cursor::Image(CURSOR)).on_press(|_: &mut State| {}));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
pub fn run() {
|
||||
let mut spec = AppSpec::new("Image proof", (390.0, 760.0), State::default, view);
|
||||
spec.setup = Some(|s, waker| {
|
||||
let cache = s.cache.insert(ImageCache::new(waker));
|
||||
s.images = vec![
|
||||
("jpeg", cache.load(&include_bytes!("../assets/proof.jpg")[..])),
|
||||
("png", cache.load(PNG)),
|
||||
];
|
||||
});
|
||||
spec.poll = Some(|s, _, _| {
|
||||
for (name, image) in &s.images {
|
||||
match (image.size(), image.error()) {
|
||||
(Some([w, h]), _) => report(name, w, h, ""),
|
||||
(_, Some(e)) => report(name, 0, 0, &e.0),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
false
|
||||
});
|
||||
rune::run(spec);
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
//! Browser input regression fixture, selected only by ?input-proof (and ?input-proof&audit).
|
||||
use std::{cell::Cell, rc::Rc};
|
||||
|
||||
use rune::{
|
||||
App, AppHandle, AppSpec, Cx, Drag, El, Key, Phase, PhysicalInput, ScrollPos, TextEdit, col, el,
|
||||
row, text, text_input, tok,
|
||||
};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(inline_js = "
|
||||
export function enabled() { return new URLSearchParams(location.search).has('input-proof'); }
|
||||
export function auditEnabled() { return new URLSearchParams(location.search).has('audit'); }
|
||||
export function queryZoom() {
|
||||
const z = parseFloat(new URLSearchParams(location.search).get('zoom') ?? '1');
|
||||
return Number.isFinite(z) && z > 0 ? z : 1;
|
||||
}
|
||||
export function report(plain, display, single, secretLength, submits, shortcuts, visible) {
|
||||
window.__inputProof = { plain, display, single, secretLength, submits, shortcuts, visible,
|
||||
polls: (window.__inputProof?.polls ?? 0) + 1 };
|
||||
}
|
||||
export function reportAudit(json) {
|
||||
const prev = window.__auditProof?.polls ?? 0;
|
||||
const data = JSON.parse(json);
|
||||
data.polls = prev + 1;
|
||||
window.__auditProof = data;
|
||||
}
|
||||
export function reportScroll(x, y) {
|
||||
window.__auditScroll = { x, y };
|
||||
}
|
||||
")]
|
||||
extern "C" {
|
||||
pub fn enabled() -> bool;
|
||||
#[wasm_bindgen(js_name = auditEnabled)]
|
||||
fn audit_enabled() -> bool;
|
||||
#[wasm_bindgen(js_name = queryZoom)]
|
||||
fn query_zoom() -> f32;
|
||||
fn report(plain: &str, display: &str, single: &str, secret_length: usize, submits: u32, shortcuts: u32, visible: bool);
|
||||
#[wasm_bindgen(js_name = reportAudit)]
|
||||
fn report_audit(json: &str);
|
||||
#[wasm_bindgen(js_name = reportScroll)]
|
||||
fn report_scroll(x: f32, y: f32);
|
||||
}
|
||||
|
||||
struct State {
|
||||
plain: TextEdit,
|
||||
single: TextEdit,
|
||||
secret: TextEdit,
|
||||
submits: u32,
|
||||
shortcuts: u32,
|
||||
handle: Option<AppHandle<State>>,
|
||||
}
|
||||
|
||||
impl Default for State {
|
||||
fn default() -> Self {
|
||||
Self { plain: TextEdit::default(), single: TextEdit::default(), secret: TextEdit::default().secure(),
|
||||
submits: 0, shortcuts: 0, handle: None }
|
||||
}
|
||||
}
|
||||
|
||||
fn view(s: &State, _: &mut Cx<State>) -> El {
|
||||
let field = |edit: &TextEdit| text_input(edit, tok::type_::BODY).w_full().h(48.0);
|
||||
col().w_full().h_full().padding(16.0).gap(8.0)
|
||||
.child(field(&s.plain).key("plain").on_edit(|s: &mut State| &mut s.plain)
|
||||
.on_submit(|s: &mut State, _| s.submits += 1))
|
||||
.child(field(&s.single).key("single").single_line().on_edit(|s: &mut State| &mut s.single)
|
||||
.on_submit(|s: &mut State, _| s.submits += 1))
|
||||
.child(field(&s.secret).key("secret").single_line().on_edit(|s: &mut State| &mut s.secret)
|
||||
.on_submit(|s: &mut State, _| s.submits += 1))
|
||||
.child(el().key("button").focusable(true).w_full().h(48.0).child(text("Button"))
|
||||
.on_press(|s: &mut State| s.submits += 1))
|
||||
}
|
||||
|
||||
struct Audit {
|
||||
zoom: f32,
|
||||
clicks: Vec<String>,
|
||||
secondary: u32,
|
||||
middle: u32,
|
||||
wheels: Vec<String>,
|
||||
pinches: Vec<f32>,
|
||||
scroll: Rc<Cell<(f32, f32)>>,
|
||||
keys: Vec<String>,
|
||||
key_ups: Vec<String>,
|
||||
physical_mods: Vec<String>,
|
||||
focus_lost: u32,
|
||||
drags: Vec<String>,
|
||||
hovered: bool,
|
||||
edit: TextEdit,
|
||||
handle: Option<AppHandle<Audit>>,
|
||||
}
|
||||
|
||||
impl Default for Audit {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
zoom: query_zoom(),
|
||||
clicks: Vec::new(),
|
||||
secondary: 0,
|
||||
middle: 0,
|
||||
wheels: Vec::new(),
|
||||
pinches: Vec::new(),
|
||||
scroll: Rc::new(Cell::new((0.0, 0.0))),
|
||||
keys: Vec::new(),
|
||||
key_ups: Vec::new(),
|
||||
physical_mods: Vec::new(),
|
||||
focus_lost: 0,
|
||||
drags: Vec::new(),
|
||||
hovered: false,
|
||||
edit: TextEdit::default(),
|
||||
handle: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn mods_json(m: rune::Mods) -> String {
|
||||
format!(r#"{{"shift":{},"ctrl":{},"alt":{},"meta":{}}}"#, m.shift, m.ctrl, m.alt, m.logo)
|
||||
}
|
||||
|
||||
fn json_str(s: &str) -> String {
|
||||
let mut out = String::with_capacity(s.len() + 2);
|
||||
out.push('"');
|
||||
for ch in s.chars() {
|
||||
match ch {
|
||||
'"' => out.push_str("\\\""),
|
||||
'\\' => out.push_str("\\\\"),
|
||||
'\n' => out.push_str("\\n"),
|
||||
'\r' => out.push_str("\\r"),
|
||||
'\t' => out.push_str("\\t"),
|
||||
c if c.is_control() => out.push_str(&format!("\\u{:04x}", c as u32)),
|
||||
c => out.push(c),
|
||||
}
|
||||
}
|
||||
out.push('"');
|
||||
out
|
||||
}
|
||||
|
||||
fn publish_audit(s: &Audit) {
|
||||
let (sx, sy) = s.scroll.get();
|
||||
let pinches: Vec<String> = s.pinches.iter().map(|d| format!("{d:.4}")).collect();
|
||||
let key_ups: Vec<String> = s.key_ups.iter().map(|k| json_str(k)).collect();
|
||||
let preedit = s.edit.preedit().map(|(p, _)| p).unwrap_or("");
|
||||
let json = format!(
|
||||
r#"{{"zoom":{:.2},"clicks":[{}],"secondary":{},"middle":{},"wheels":[{}],"pinches":[{}],"scrollX":{:.2},"scrollY":{:.2},"keys":[{}],"keyUps":[{}],"physicalMods":[{}],"focusLost":{},"drags":[{}],"hovered":{},"plain":{},"preedit":{},"visible":{}}}"#,
|
||||
s.zoom,
|
||||
s.clicks.join(","),
|
||||
s.secondary,
|
||||
s.middle,
|
||||
s.wheels.join(","),
|
||||
pinches.join(","),
|
||||
sx,
|
||||
sy,
|
||||
s.keys.join(","),
|
||||
key_ups.join(","),
|
||||
s.physical_mods.join(","),
|
||||
s.focus_lost,
|
||||
s.drags.join(","),
|
||||
s.hovered,
|
||||
json_str(&s.edit.text),
|
||||
json_str(preedit),
|
||||
s.handle.as_ref().is_some_and(AppHandle::is_visible),
|
||||
);
|
||||
report_audit(&json);
|
||||
}
|
||||
|
||||
fn audit_view(s: &Audit, cx: &mut Cx<Audit>) -> El {
|
||||
cx.zoom(s.zoom);
|
||||
publish_audit(s);
|
||||
let scroll = s.scroll.clone();
|
||||
col().w_full().h_full()
|
||||
.on_key_up(|s: &mut Audit, ev, _| { s.key_ups.push(format!("{:?}", ev.key)); true })
|
||||
.child(
|
||||
row().h(60.0)
|
||||
.child(el().key("left").size(120.0, 60.0).on_press_tx(|s: &mut Audit, tx| {
|
||||
s.clicks.push(format!(r#"{{"target":"left","mods":{}}}"#, mods_json(tx.mods())));
|
||||
}))
|
||||
.child(el().key("right").size(120.0, 60.0).on_press_tx(|s: &mut Audit, tx| {
|
||||
s.clicks.push(format!(r#"{{"target":"right","mods":{}}}"#, mods_json(tx.mods())));
|
||||
})),
|
||||
)
|
||||
.child(
|
||||
row().h(60.0)
|
||||
.child(
|
||||
el().key("drag").size(120.0, 60.0).focusable(true)
|
||||
.on_hover_change(|s: &mut Audit, h, _| s.hovered = h)
|
||||
.on_drag(|s: &mut Audit, d: &mut Drag, _| {
|
||||
let phase = match d.phase { Phase::Down => "down", Phase::Move => "move", Phase::Up => "up" };
|
||||
s.drags.push(format!(r#"{{"phase":"{phase}","cancelled":{}}}"#, d.cancelled()));
|
||||
})
|
||||
.on_secondary_press(|s: &mut Audit, _, _| s.secondary += 1)
|
||||
.on_middle_press(|s: &mut Audit, _| s.middle += 1)
|
||||
.on_physical_input(|s: &mut Audit, ev, _| match ev {
|
||||
PhysicalInput::Modifiers(m) => { s.physical_mods.push(mods_json(*m)); true }
|
||||
PhysicalInput::FocusLost => { s.focus_lost += 1; true }
|
||||
PhysicalInput::Key { .. } => false,
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
el().key("wheel").size(120.0, 60.0).hit()
|
||||
.on_wheel(|s: &mut Audit, ev, _| {
|
||||
s.wheels.push(format!(
|
||||
r#"{{"dx":{:.2},"dy":{:.2},"precise":{},"mods":{}}}"#,
|
||||
ev.dx, ev.dy, ev.precise, mods_json(ev.mods)
|
||||
));
|
||||
true
|
||||
})
|
||||
.on_magnify(|s: &mut Audit, ev, _| { s.pinches.push(ev.delta); true }),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
el().key("scroller").size(240.0, 100.0).scroll_xy()
|
||||
.on_scroll_offset(move |pos: ScrollPos| {
|
||||
scroll.set((pos.offset[0], pos.offset[1]));
|
||||
report_scroll(pos.offset[0], pos.offset[1]);
|
||||
})
|
||||
.child(el().size(1200.0, 1200.0)),
|
||||
)
|
||||
.child(
|
||||
text_input(&s.edit, tok::type_::BODY).key("field").size(240.0, 48.0)
|
||||
.on_edit(|s: &mut Audit| &mut s.edit),
|
||||
)
|
||||
}
|
||||
|
||||
fn run_audit() {
|
||||
let mut spec = AppSpec::new("Input audit", (450.0, 600.0), Audit::default, audit_view);
|
||||
spec.poll = Some(|s, _, _| {
|
||||
publish_audit(s);
|
||||
false
|
||||
});
|
||||
spec.on_key = Some(|s, ev, tx| {
|
||||
let phys = tx.physical_key().map(|p| json_str(&format!("{p:?}"))).unwrap_or_else(|| "null".into());
|
||||
let base = tx.key_base().map(|c| json_str(&c.to_string())).unwrap_or_else(|| "null".into());
|
||||
s.keys.push(format!(
|
||||
r#"{{"key":{},"physical":{},"base":{},"repeat":{},"mods":{}}}"#,
|
||||
json_str(&format!("{:?}", ev.key)),
|
||||
phys,
|
||||
base,
|
||||
tx.key_repeat(),
|
||||
mods_json(ev.mods),
|
||||
));
|
||||
true
|
||||
});
|
||||
let app = App::new(spec);
|
||||
let handle = app.handle();
|
||||
let state_handle = handle.clone();
|
||||
handle.update(move |s, _| s.handle = Some(state_handle));
|
||||
app.run();
|
||||
}
|
||||
|
||||
pub fn run() {
|
||||
if audit_enabled() {
|
||||
run_audit();
|
||||
return;
|
||||
}
|
||||
let mut spec = AppSpec::new("Input proof", (390.0, 760.0), State::default, view);
|
||||
spec.poll = Some(|s, _, _| {
|
||||
report(&s.plain.text, &s.plain.display().0, &s.single.text, s.secret.text.chars().count(),
|
||||
s.submits, s.shortcuts, s.handle.as_ref().is_some_and(AppHandle::is_visible));
|
||||
false
|
||||
});
|
||||
spec.on_key = Some(|s, event, _| {
|
||||
if event.key == Key::Command('k') { s.shortcuts += 1; true } else { false }
|
||||
});
|
||||
let app = App::new(spec);
|
||||
let handle = app.handle();
|
||||
let state_handle = handle.clone();
|
||||
handle.update(move |s, _| s.handle = Some(state_handle));
|
||||
handle.show();
|
||||
handle.set_position((0, 0)); // Must warn, never cover the canvas with an error page.
|
||||
app.run();
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
use rune::{AppSpec, Cx, El, ScrollSpec, TextEdit, Tx, col, el, row, text, text_input};
|
||||
use rune::tok::{self, type_};
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod image_proof;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod input_proof;
|
||||
|
||||
struct State {
|
||||
messages: Vec<String>,
|
||||
draft: TextEdit,
|
||||
}
|
||||
|
||||
impl Default for State {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
messages: (1..=24).map(|n| format!("Message {n}: Hello from Rune." )).collect(),
|
||||
draft: TextEdit::new(""),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn send(state: &mut State, tx: &mut Tx) {
|
||||
if state.draft.text.trim().is_empty() { return; }
|
||||
state.messages.push(state.draft.text.clone());
|
||||
state.draft.clear();
|
||||
tx.scroll_to_bottom("messages");
|
||||
}
|
||||
|
||||
fn view(state: &State, cx: &mut Cx<State>) -> El {
|
||||
let dark = cx.system_dark();
|
||||
let t = tok::theme(dark);
|
||||
let [top, right, bottom, left] = cx.safe_area();
|
||||
let mut messages = col().w_full().gap(12.0).py(16.0);
|
||||
for (i, message) in state.messages.iter().enumerate() {
|
||||
messages = messages.child(text(message.clone()).key(format!("message-{i}"))
|
||||
.font(type_::BODY).color(t.text).w_full().padding(16.0).radius(12.0).fill(t.card));
|
||||
}
|
||||
let composer = text_input(&state.draft, type_::BODY).key("composer")
|
||||
.placeholder("Message", t.text_secondary).color(t.text)
|
||||
.grow(1.0).h(48.0).padding(12.0).radius(12.0).fill(t.card)
|
||||
.on_edit(|s: &mut State| &mut s.draft).on_submit(send);
|
||||
let send_button = el().key("send").h(48.0).px(16.0).center().radius(12.0).fill(t.control_off)
|
||||
.child(text("Send").font(type_::LABEL).color(t.text)).on_press_tx(send);
|
||||
let copy = el().key("copy").h(44.0).px(8.0).center()
|
||||
.child(text("Copy last").font(type_::LABEL).color(t.text_secondary)).on_press_tx(|s: &mut State, tx| {
|
||||
if let Some(message) = s.messages.last() { tx.copy(message.clone()); }
|
||||
});
|
||||
let title = text("Messages").font(type_::TITLE).color(t.text).grow(1.0);
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let title = title.on_press(|_: &mut State| { rune::web::open_url("https://www.rust-lang.org/").ok(); });
|
||||
col().w_full().h_full().pt(16.0 + top).pr(16.0 + right).pb(16.0 + bottom).pl(16.0 + left).gap(8.0).fill(t.bg)
|
||||
.child(row().w_full().center_y().child(title).child(copy))
|
||||
.child(col().key("messages").w_full().grow(1.0).shrink()
|
||||
.scroll(ScrollSpec { stick_bottom: true }).scroll_edge_fade(16.0).child(messages))
|
||||
.child(row().w_full().gap(8.0).child(composer).child(send_button))
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen::prelude::wasm_bindgen(start))]
|
||||
pub fn start() {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
if input_proof::enabled() { input_proof::run(); return; }
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
if image_proof::enabled() { image_proof::run(); return; }
|
||||
rune::run(AppSpec::new("Messages", (390.0, 760.0), State::default, view));
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
fn main() { web_hello::start(); }
|
||||
Reference in new issue
Block a user