tawasuyu/llimphi
Sovereign retained-mode GPU UI framework in Rust (wgpu+vello+taffy+parley), Elm loop, 40+ widgets.
refresh: stack al día (vello 0.7 / wgpu 27 / parley 0.6) + motor 3D voxel
1//! `llimphi-widget-hero` — shared-element transitions estilo Flutter Hero.
2//!
3//! El runtime de Llimphi tiene un [`HeroRegistry`](llimphi_ui::llimphi_compositor::HeroRegistry)
4//! retenido entre frames: si la misma `key` aparece en un rect distinto entre
5//! dos frames consecutivos, el runtime interpola `transform` para que el nodo
6//! "vuele" del rect anterior al actual. Este widget es el envoltorio canónico
7//! que marca al `child` como hero con la `key` indicada — la app no necesita
8//! tocar `View::hero` a mano si compone con esto.
9//!
10//! Mantenemos las firmas previas (`hero_view`, `hero_quick`) para no romper
11//! callers. Antes envolvían sólo con `animated_inout` (fade); ahora componen
12//! `hero` + `animated_inout` para que un caller que reusa la misma `key` entre
13//! rutas obtenga el fly real **y** el fade de aterrizaje juntos.
14
15#![forbid(unsafe_code)]
16
17use llimphi_ui::llimphi_layout::taffy::prelude::{percent, Size, Style};
18use llimphi_ui::View;
19use llimphi_theme::motion;
20
21/// Envuelve `child` como hero: si la misma `key` aparece en otro rect en un
22/// frame siguiente, el runtime interpola `transform` para volar entre las dos
23/// posiciones; el fade-in/out de `animated_inout` cubre el aterrizaje
24/// (`motion::DRAMATIC`, 480 ms). `key` debe ser estable entre rebuilds.
25pub fn hero_view<Msg: Clone + 'static>(key: u64, child: View<Msg>) -> View<Msg> {
26 View::new(Style {
27 size: Size {
28 width: percent(1.0_f32),
29 height: percent(1.0_f32),
30 },
31 ..Default::default()
32 })
33 .children(vec![child])
34 .hero(key, motion::DRAMATIC)
35 .animated_inout(key, motion::DRAMATIC)
36}
37
38/// Hero "rápido" — variante con `motion::SLOW` (320 ms). Para elementos
39/// destacados pero menos protagónicos (un toast importante, un panel
40/// que se monta).
41pub fn hero_quick<Msg: Clone + 'static>(key: u64, child: View<Msg>) -> View<Msg> {
42 View::new(Style {
43 size: Size {
44 width: percent(1.0_f32),
45 height: percent(1.0_f32),
46 },
47 ..Default::default()
48 })
49 .children(vec![child])
50 .hero(key, motion::SLOW)
51 .animated_inout(key, motion::SLOW)
52}