Skip to main content

scaled_box

Function scaled_box 

Source
pub fn scaled_box(scale: f32) -> ScaledBoxBuilder
Expand description

§scaled_box

Scale a single native child uniformly for responsive illustrations and previews.

§Usage

Fit an interactive control or fixed-size scene into a smaller display region.

§Parameters

  • scale — finite, positive, invertible scale relative to the child’s layout units.
  • child — optional content producing one direct layout child; empty when omitted.

§Examples

use tessera_ui::{LocalToWindow, Px, PxPosition, PxSize, layout::layout, scaled_box};

#[tessera_ui::tessera]
fn preview() {
    scaled_box(0.625).child(|| {
        layout().child(|| {});
    });
}

let transform = LocalToWindow::new(0.625, PxPosition::ZERO).unwrap();
assert_eq!(
    transform.map_size(PxSize::new(Px(240), Px(56))),
    [150.0, 35.0]
);