Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Fade

Fade — a wrapper widget that animates its child between hidden (opacity 0) and visible (opacity 1) when an external Signal<bool> toggles.

Public functions

Fade

Detailed description

Drives an opacity: Signal<f32> ∈ [0, 1] and applies it to its own subtree via BuildContext::set_opacity. The framework's render walker emits SetOpacity(value) before this widget's paint and RestoreOpacity afterwards, so the multiplier composes correctly with ancestor opacity scopes via the canvas's stacked opacity model.

let visible = ctx.signal(false);
ctx.add(Fade::new(visible.clone()).child(tooltip_content));
// ...elsewhere:
visible.set(true);  // fades in over `motion.duration_fast`

Layout semantics

Fade does not change layout. The wrapped child reports its full natural size at all opacity values, so reserving space for a to-be-faded-in widget works the same whether the widget is fully visible or fully hidden.

For overlays where the dismiss should be deferred until the fade-out completes (tooltip / popover / snackbar / dialog), prefer OverlayRequest::with_fade instead — that path coordinates the dismiss with the tween so the overlay survives until the opacity reaches zero.

Reduced motion

Honours prefers-reduced-motion: under reduced motion the opacity snaps to its end value instead of tweening.

API reference

📖 Full rustdoc API for this module

pub struct Fade

Import: use teksilo::widgets::Fade;

Wraps a child and animates the entire subtree's opacity between 0 and 1, driven by an external Signal<bool>.

#![allow(unused)]
fn main() {
pub struct Fade { /* fields */ }
}

Methods

pub fn new(visible: impl Into<Prop<bool>>) -> Self

Build a fade wrapper bound to visible. Initially hidden iff visible.get() is false at the first build().

Accepts any Prop<bool> source — Signal<bool>, Prop<bool>, or a plain bool (for static "always visible" / "always hidden" cases without a tween).

pub fn child(mut self, widget: impl teksilo_core::IntoTeksiChild) -> Self

Inline child widget (deferred insertion).

pub fn child_opt(self, widget: Option<impl teksilo_core::IntoTeksiChild>) -> Self

Attach widget when it is Some, and do nothing when it is None.

The conditional-child form. teksu!'s if without an else lowers to this, and it is what cond.then(|| w) is for in a builder chain. None adds no arena node, so nothing is laid out, painted, or published to the accessibility tree, and a stack applies no spacing around it.