use super::*;
pub(crate) fn render_mode_name(idx: usize) -> &'static str {
match idx {
1 => MODE_SOFTWARE,
2 => MODE_HARDWARE,
3 => MODE_HYBRID,
_ => MODE_AUTO,
}
}
pub(crate) fn render_blur_radius(idx: usize) -> f32 {
match idx {
0 => 8.0,
2 => 24.0,
_ => 16.0,
}
}
pub(crate) fn render_gradient_angle(idx: usize) -> f32 {
match idx {
0 => 0.0,
2 => 90.0,
3 => 135.0,
_ => 45.0,
}
}
pub(crate) fn mount_render_vector_card(
mode_idx: Signal<usize>,
tokens: ThemeTokens,
) -> (NodeId, NodeId) {
let p: ThemePalette = tokens.get_palette();
let g: ThemeGeometry = tokens.get_geometry();
let mut canvas_id: NodeId = NodeId::default();
let pipeline_label = move || -> String {
let mode_name: &str = render_mode_name(mode_idx.get());
format!("Demo Preview Pipeline: {mode_name} (Widget-Scoped — Global App Unchanged)")
};
let paint_preview = move |bounds: Rect, dl: &mut DisplayList| {
let live: ThemeTokens = live_tokens_untracked(tokens);
let lp: ThemePalette = live.get_palette();
let mode: usize = mode_idx.get_untracked();
let bw: f32 = bounds.get_width().max(120.0);
let bh: f32 = bounds.get_height().max(100.0);
let grid_col: Color = lp.get_border().with_alpha(90);
let step_x: f32 = (bw / 6.0).max(32.0);
let mut gx: f32 = bounds.get_x() + step_x;
while gx < bounds.right() - 8.0 {
dl.push(DrawCommand::Line {
from: Point::new(gx, bounds.get_y() + 8.0),
to: Point::new(gx, bounds.bottom() - 8.0),
color: grid_col,
width: 1.0,
});
gx += step_x;
}
let rect_w: f32 = (bw * 0.28).clamp(64.0, 210.0);
let rect_h: f32 = (bh - 52.0).max(60.0);
let primary_fill: Color = match mode {
1 => lp.get_secondary(),
2 => lp.get_primary(),
3 => lp.get_success(),
_ => lp.get_primary(),
};
dl.push(DrawCommand::FillRoundedRect {
rect: Rect::new(bounds.get_x() + 18.0, bounds.get_y() + 34.0, rect_w, rect_h),
color: primary_fill,
radius: CornerRadius::all(14.0),
border: Border::new(1.5, lp.get_border()),
});
let circle_r: f32 = (bw * 0.085).clamp(22.0, 48.0);
let circle_x: f32 = (bounds.get_x() + 18.0 + rect_w + circle_r + 24.0)
.min(bounds.right() - circle_r - 14.0);
let circle_y: f32 = bounds.get_y() + 34.0 + rect_h * 0.5;
dl.push(DrawCommand::Circle {
center: Point::new(circle_x, circle_y),
radius: circle_r + 6.0,
color: lp.get_success().with_alpha(52),
});
dl.push(DrawCommand::Circle {
center: Point::new(circle_x, circle_y),
radius: circle_r,
color: lp.get_success(),
});
let line_x0: f32 = (circle_x + circle_r + 18.0).min(bounds.right() - 24.0);
let line_x1: f32 = (bounds.right() - 18.0).max(line_x0);
dl.push(DrawCommand::Line {
from: Point::new(line_x0, bounds.get_y() + 42.0),
to: Point::new(line_x1, bounds.bottom() - 22.0),
color: lp.get_warning(),
width: 3.5,
});
dl.push(DrawCommand::Line {
from: Point::new(line_x0, bounds.bottom() - 22.0),
to: Point::new(line_x1, bounds.get_y() + 42.0),
color: lp.get_primary().with_alpha(180),
width: 2.0,
});
let mut hud_style: TextStyle = TextStyle::default();
hud_style
.set_font_size(11.5)
.set_weight(FontWeight::SemiBold)
.set_color(lp.get_foreground());
dl.push(DrawCommand::TextRun {
rect: Rect::new(
bounds.get_x() + 16.0,
bounds.get_y() + 10.0,
(bw - 32.0).max(1.0),
18.0,
),
text: format!(
"SDF Vector Stage | Preview Mode: {} | Bounds: {:.0}x{:.0}",
render_mode_name(mode),
bw,
bh
),
style: hud_style,
});
};
let card: NodeId = view! {
EuvCard {
title: RENDER_CARD_TITLE.to_string()
tokens: tokens
subtitle: RENDER_CARD_SUB
column {
style: {
width: Length::Percent(100.0)
gap: SPACE_SM
}
text {
style: {
width: Length::Percent(100.0)
font_size: 13.0
font_weight: FontWeight::SemiBold
color: p.get_primary()
}
{ pipeline_label }
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
font_weight: FontWeight::Medium
color: p.get_muted_foreground()
}
{ CANVAS_LABEL }
}
canvas {
node_ref: canvas_id
style: {
width: Length::Percent(100.0)
height: Length::Px(RENDER_VECTOR_CANVAS_HEIGHT)
background: p.get_muted()
border: (g.get_border_width(), p.get_border())
radius: g.get_radius_md()
}
painter: paint_preview
}
}
}
};
(card, canvas_id)
}
pub(crate) fn mount_render_blur_card(
blur_idx: Signal<usize>,
tokens: ThemeTokens,
) -> (NodeId, NodeId) {
let p: ThemePalette = tokens.get_palette();
let g: ThemeGeometry = tokens.get_geometry();
let mut glass_id: NodeId = NodeId::default();
let paint_backdrop = move |bounds: Rect, dl: &mut DisplayList| {
let live: ThemeTokens = live_tokens_untracked(tokens);
let lp: ThemePalette = live.get_palette();
let bw: f32 = bounds.get_width().max(80.0);
let bh: f32 = bounds.get_height().max(80.0);
dl.push(DrawCommand::Circle {
center: Point::new(bounds.get_x() + bw * 0.24, bounds.get_y() + bh * 0.48),
radius: (bh * 0.34).max(20.0),
color: lp.get_primary(),
});
dl.push(DrawCommand::Circle {
center: Point::new(bounds.get_x() + bw * 0.56, bounds.get_y() + bh * 0.42),
radius: (bh * 0.30).max(18.0),
color: lp.get_success(),
});
dl.push(DrawCommand::Circle {
center: Point::new(bounds.get_x() + bw * 0.80, bounds.get_y() + bh * 0.58),
radius: (bh * 0.28).max(16.0),
color: lp.get_warning(),
});
};
let glass_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
let lp: ThemePalette = live.get_palette();
let lg: ThemeGeometry = live.get_geometry();
Style::default()
.position(Position::Absolute)
.inset(
Some(SPACE_LG),
Some(SPACE_LG),
Some(SPACE_LG),
Some(SPACE_LG),
)
.column()
.justify(JustifyContent::Center)
.gap(SPACE_XS)
.padding(Edges::all(SPACE_MD))
.background(lp.get_card().with_alpha(196))
.border(lg.get_border_width(), lp.get_border())
.radius(lg.get_radius_md())
.overflow(Overflow::Hidden)
};
let glass_title_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
Style::default()
.width(Length::Percent(100.0))
.font_size(14.0)
.font_weight(FontWeight::Bold)
.color(live.get_palette().get_card_foreground())
};
let glass_sub_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
Style::default()
.width(Length::Percent(100.0))
.font_size(12.0)
.font_family(FontFamily::Monospace)
.color(live.get_palette().get_card_foreground())
};
let blur_caption = move || -> String {
let radius: f32 = render_blur_radius(blur_idx.get());
format!("Dual-Kawase radius: {radius:.0}px | alpha=196/255")
};
let card: NodeId = view! {
EuvCard {
title: RENDER_BLUR_CARD_TITLE.to_string()
tokens: tokens
subtitle: RENDER_BLUR_CARD_SUB
view {
style: {
width: Length::Percent(100.0)
height: Length::Px(RENDER_EFFECT_STAGE_HEIGHT)
background: p.get_muted()
border: (g.get_border_width(), p.get_border())
radius: g.get_radius_md()
overflow: Overflow::Hidden
}
canvas {
style: {
width: Length::Percent(100.0)
height: Length::Percent(100.0)
}
painter: paint_backdrop
}
view {
node_ref: glass_id
bind_style: glass_style
text {
bind_style: glass_title_style
{ RENDER_BLUR_GLASS_TITLE }
}
text {
bind_style: glass_sub_style
{ blur_caption }
}
}
}
}
};
(card, glass_id)
}
pub(crate) fn mount_render_shadow_card(shadow_idx: Signal<usize>, tokens: ThemeTokens) -> NodeId {
let p: ThemePalette = tokens.get_palette();
let g: ThemeGeometry = tokens.get_geometry();
let tile_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
let lp: ThemePalette = live.get_palette();
let lg: ThemeGeometry = live.get_geometry();
let sh: Shadow = match shadow_idx.get() {
0 => lg.get_shadow_sm(),
2 => lg.get_shadow_lg(),
_ => lg.get_shadow_md(),
};
Style::default()
.column()
.width(Length::Percent(100.0))
.padding(Edges::all(SPACE_MD))
.gap(SPACE_XS)
.background(lp.get_card())
.border(lg.get_border_width(), lp.get_border())
.radius(lg.get_radius_lg())
.shadow(sh)
.overflow(Overflow::Hidden)
};
let tile_title_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
Style::default()
.width(Length::Percent(100.0))
.font_size(14.0)
.font_weight(FontWeight::Bold)
.color(live.get_palette().get_card_foreground())
};
let tile_meta_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
Style::default()
.width(Length::Percent(100.0))
.font_size(12.0)
.font_family(FontFamily::Monospace)
.color(live.get_palette().get_muted_foreground())
};
let shadow_meta = move || -> String {
let live: ThemeTokens = use_live_tokens(tokens);
let lg: ThemeGeometry = live.get_geometry();
let (tier, sh): (&str, Shadow) = match shadow_idx.get() {
0 => (RENDER_SHADOW_OPT_SM, lg.get_shadow_sm()),
2 => (RENDER_SHADOW_OPT_LG, lg.get_shadow_lg()),
_ => (RENDER_SHADOW_OPT_MD, lg.get_shadow_md()),
};
format!(
"{tier} | offset=({:.0},{:.0}) blur={:.0}px",
sh.get_offset_x(),
sh.get_offset_y(),
sh.get_blur_radius()
)
};
view! {
EuvCard {
title: RENDER_SHADOW_CARD_TITLE.to_string()
tokens: tokens
subtitle: RENDER_SHADOW_CARD_SUB
column {
style: {
width: Length::Percent(100.0)
height: Length::Px(RENDER_EFFECT_STAGE_HEIGHT)
padding: Edges::all(SPACE_LG)
justify: JustifyContent::Center
background: p.get_muted()
border: (g.get_border_width(), p.get_border())
radius: g.get_radius_md()
overflow: Overflow::Hidden
}
view {
bind_style: tile_style
text {
bind_style: tile_title_style
{ RENDER_SHADOW_SAMPLE_TITLE }
}
text {
bind_style: tile_meta_style
{ shadow_meta }
}
}
}
}
}
}
pub(crate) fn mount_render_gradient_card(angle_idx: Signal<usize>, tokens: ThemeTokens) -> NodeId {
let grad_box_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
let lp: ThemePalette = live.get_palette();
let lg: ThemeGeometry = live.get_geometry();
let angle: f32 = render_gradient_angle(angle_idx.get());
let grad: LinearGradient = LinearGradient::new(angle, lp.get_primary(), lp.get_success());
Style::default()
.column()
.width(Length::Percent(100.0))
.height(Length::Px(RENDER_EFFECT_STAGE_HEIGHT))
.padding(Edges::all(SPACE_MD))
.justify(JustifyContent::End)
.gap(SPACE_XS)
.background(lp.get_primary())
.gradient(grad)
.border(lg.get_border_width(), lp.get_border())
.radius(lg.get_radius_md())
.overflow(Overflow::Hidden)
};
let grad_title_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
Style::default()
.width(Length::Percent(100.0))
.font_size(14.0)
.font_weight(FontWeight::Bold)
.color(live.get_palette().get_primary_foreground())
};
let grad_meta_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
Style::default()
.width(Length::Percent(100.0))
.font_size(12.0)
.font_family(FontFamily::Monospace)
.color(live.get_palette().get_primary_foreground())
};
let grad_meta = move || -> String {
let angle: f32 = render_gradient_angle(angle_idx.get());
format!("LinearGradient({angle:.0} deg, primary -> success)")
};
view! {
EuvCard {
title: RENDER_GRADIENT_CARD_TITLE.to_string()
tokens: tokens
subtitle: RENDER_GRADIENT_CARD_SUB
view {
bind_style: grad_box_style
text {
bind_style: grad_title_style
{ RENDER_GRADIENT_SAMPLE_TITLE }
}
text {
bind_style: grad_meta_style
{ grad_meta }
}
}
}
}
}
pub(crate) fn mount_render_damage_card(
pulse_sig: Signal<u32>,
tokens: ThemeTokens,
) -> (NodeId, NodeId) {
let p: ThemePalette = tokens.get_palette();
let g: ThemeGeometry = tokens.get_geometry();
let mut damage_canvas_id: NodeId = NodeId::default();
let paint_damage = move |bounds: Rect, dl: &mut DisplayList| {
let live: ThemeTokens = live_tokens_untracked(tokens);
let lp: ThemePalette = live.get_palette();
let pulse: u32 = pulse_sig.get_untracked();
let cols: usize = 4;
let rows: usize = 2;
let pad: f32 = 10.0;
let gap: f32 = 6.0;
let usable_w: f32 = (bounds.get_width() - pad * 2.0 - gap * ((cols - 1) as f32)).max(40.0);
let usable_h: f32 =
(bounds.get_height() - 28.0 - pad * 2.0 - gap * ((rows - 1) as f32)).max(24.0);
let cell_w: f32 = usable_w / (cols as f32);
let cell_h: f32 = usable_h / (rows as f32);
let active_idx: usize = (pulse as usize) % (cols * rows);
for row in 0..rows {
for col in 0..cols {
let idx: usize = row * cols + col;
let rx: f32 = bounds.get_x() + pad + (col as f32) * (cell_w + gap);
let ry: f32 = bounds.get_y() + 26.0 + pad + (row as f32) * (cell_h + gap);
let is_dirty: bool = idx == active_idx;
let fill: Color = if is_dirty {
lp.get_warning().with_alpha(96)
} else {
lp.get_card()
};
let stroke: Color = if is_dirty {
lp.get_warning()
} else {
lp.get_border()
};
dl.push(DrawCommand::FillRoundedRect {
rect: Rect::new(rx, ry, cell_w, cell_h),
color: fill,
radius: CornerRadius::all(6.0),
border: Border::new(if is_dirty { 2.0 } else { 1.0 }, stroke),
});
}
}
let mut hud_style: TextStyle = TextStyle::default();
hud_style
.set_font_size(11.5)
.set_weight(FontWeight::SemiBold)
.set_color(lp.get_foreground());
dl.push(DrawCommand::TextRun {
rect: Rect::new(
bounds.get_x() + 10.0,
bounds.get_y() + 8.0,
(bounds.get_width() - 20.0).max(1.0),
18.0,
),
text: format!("DIRTY_PAINT Pulses: {pulse} | Active Tile: #{active_idx}"),
style: hud_style,
});
};
let card: NodeId = view! {
EuvCard {
title: RENDER_DAMAGE_CARD_TITLE.to_string()
tokens: tokens
subtitle: RENDER_DAMAGE_CARD_SUB
canvas {
node_ref: damage_canvas_id
style: {
width: Length::Percent(100.0)
height: Length::Px(RENDER_EFFECT_STAGE_HEIGHT)
background: p.get_muted()
border: (g.get_border_width(), p.get_border())
radius: g.get_radius_md()
}
painter: paint_damage
}
}
};
(card, damage_canvas_id)
}
pub fn mount_render_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
let p: ThemePalette = tokens.get_palette();
let ctx: Context = current_context();
let mode_idx: Signal<usize> = state.get_render_mode_index();
let blur_idx: Signal<usize> = Signal::new(1);
let shadow_idx: Signal<usize> = Signal::new(1);
let angle_idx: Signal<usize> = Signal::new(1);
let damage_pulse: Signal<u32> = Signal::new(0);
let (vector_card, vector_canvas_id): (NodeId, NodeId) =
mount_render_vector_card(mode_idx, tokens);
let (blur_card, glass_id): (NodeId, NodeId) = mount_render_blur_card(blur_idx, tokens);
let shadow_card: NodeId = mount_render_shadow_card(shadow_idx, tokens);
let gradient_card: NodeId = mount_render_gradient_card(angle_idx, tokens);
let (damage_card, damage_canvas_id): (NodeId, NodeId) =
mount_render_damage_card(damage_pulse, tokens);
let effects_grid: NodeId =
mount_responsive_grid(vec![blur_card, shadow_card, gradient_card, damage_card], 2);
let pulse_scene: SceneHandle = ctx.get_scene().clone();
let on_pulse_dirty = move |_: &UiEvent| {
let _: bool = damage_pulse.update(|n: &mut u32| *n = n.saturating_add(1));
pulse_scene.mark_dirty(damage_canvas_id, DIRTY_PAINT);
};
let pulse_readout = move || -> String {
format!(
"Surgical DIRTY_PAINT count: {} (zero global layout rebuild)",
damage_pulse.get()
)
};
let pipeline_card: NodeId = view! {
EuvCard {
title: RENDER_PIPELINE_CARD_TITLE.to_string()
tokens: tokens
subtitle: RENDER_PIPELINE_CARD_SUB
EuvSegmented {
options: vec![
MODE_AUTO.to_string(),
MODE_SOFTWARE.to_string(),
MODE_HARDWARE.to_string(),
MODE_HYBRID.to_string(),
]
selected: mode_idx
tokens: tokens
}
}
};
let controls_card: NodeId = view! {
EuvCard {
title: RENDER_CONTROLS_CARD_TITLE.to_string()
tokens: tokens
subtitle: RENDER_CONTROLS_CARD_SUB
column {
style: {
width: Length::Percent(100.0)
gap: SPACE_SM
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
font_weight: FontWeight::Medium
color: p.get_muted_foreground()
}
{ RENDER_LABEL_BLUR_RADIUS }
}
EuvSegmented {
options: vec![
RENDER_BLUR_OPT_8.to_string(),
RENDER_BLUR_OPT_16.to_string(),
RENDER_BLUR_OPT_24.to_string(),
]
selected: blur_idx
tokens: tokens
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
font_weight: FontWeight::Medium
color: p.get_muted_foreground()
}
{ RENDER_LABEL_SHADOW_TIER }
}
EuvSegmented {
options: vec![
RENDER_SHADOW_OPT_SM.to_string(),
RENDER_SHADOW_OPT_MD.to_string(),
RENDER_SHADOW_OPT_LG.to_string(),
]
selected: shadow_idx
tokens: tokens
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
font_weight: FontWeight::Medium
color: p.get_muted_foreground()
}
{ RENDER_LABEL_GRADIENT_ANGLE }
}
EuvSegmented {
options: vec![
RENDER_ANGLE_0.to_string(),
RENDER_ANGLE_45.to_string(),
RENDER_ANGLE_90.to_string(),
RENDER_ANGLE_135.to_string(),
]
selected: angle_idx
tokens: tokens
}
EuvActionRow {
EuvButton {
label: RENDER_BTN_PULSE_DIRTY.to_string()
tokens: tokens
sm()
on_click: on_pulse_dirty
}
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
font_family: FontFamily::Monospace
color: p.get_primary()
}
{ pulse_readout }
}
}
}
};
let rail: NodeId = view! {
column {
style: {
width: Length::Percent(100.0)
gap: SPACE_MD
}
{ pipeline_card }
{ controls_card }
}
};
let main: NodeId = view! {
column {
style: {
width: Length::Percent(100.0)
gap: SPACE_MD
}
{ vector_card }
{ effects_grid }
}
};
let studio: NodeId = mount_studio_layout(main, rail);
let page: NodeId = view! {
EuvPage {
title: RENDER_TITLE.to_string()
subtitle: RENDER_SUBTITLE.to_string()
tokens: tokens
{ studio }
}
};
let scene_for_mode: SceneHandle = ctx.get_scene().clone();
let scene_for_blur: SceneHandle = ctx.get_scene().clone();
let (render_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
let _: Effect = Effect::new(move || {
let _: usize = mode_idx.get();
scene_for_mode.mark_dirty(vector_canvas_id, DIRTY_PAINT);
});
Effect::new(move || {
let radius: f32 = render_blur_radius(blur_idx.get());
scene_for_blur.with_write(
|tree: &mut SceneTree| {
tree.set_backdrop_blur(glass_id, radius);
tree.mark_dirty(glass_id, DIRTY_PAINT);
},
(),
);
})
});
ctx.get_scene().with_write(
|tree: &mut SceneTree| {
tree.attach_scope(page, render_scope);
},
(),
);
page
}