surface

Function surface 

Source
pub fn surface(
    args: SurfaceArgs,
    ripple_state: Option<Arc<RippleState>>,
    child: impl FnOnce(),
)
Expand description

Renders a styled rectangular (or elliptic / capsule) container and optionally provides interactive click + ripple feedback.

§Behavior

  • Child closure is executed first so that nested components are registered.
  • Layout (measure) phase:
    • Measures (optional) single child (if present) with padding removed from constraints
    • Computes final size using width / height (Wrap / Fill / Fixed) merging parent constraints
    • Pushes a shape draw command sized to computed width/height
  • Interaction (input_handler) phase (only when on_click is Some):
    • Tracks cursor containment
    • Sets hover state on provided RippleState
    • Starts ripple animation on mouse press
    • Invokes on_click on mouse release inside bounds
    • Optionally blocks further event propagation if block_input is true
  • Non‑interactive variant only blocks events if block_input and cursor inside.

§Ripple

Ripple requires a RippleState (pass in Some(Arc<RippleState>)). Without it, the surface still detects clicks but no animation is shown.

§Sizing

Effective minimum size = child size + padding * 2 in each axis (if child exists).

§Example

use std::sync::Arc;
use tessera_ui::{Dp, tessera, Color};
use tessera_ui_basic_components::{
    surface::{surface, SurfaceArgsBuilder},
    ripple_state::RippleState,
};

#[tessera]
fn example_box() {
    let ripple = Arc::new(RippleState::new());
    surface(
        SurfaceArgsBuilder::default()
            .padding(Dp(8.0))
            .on_click(Arc::new(|| println!("Surface clicked")))
            .build()
            .unwrap(),
        Some(ripple),
        || {
            // child content here
        },
    );
}