Components / RubberBand

RubberBand

A rectangle drawn with a drag, in the units of the content, selected on release.

Example

The component itself, running in WebAssembly, beside its code in a playground. Try it.

Code

use ravenrs::prelude::*;

fn rubber_band() -> impl View {
    let selection = State::new(None::<Rect>);
    let chosen = State::new(String::from("Drag over the box"));
    let told = chosen.clone();
    VStack::new((
        Text::bound(&chosen, Clone::clone),
        RubberBand::new(selection.binding())
            .on_select(move |r| told.set(format!("{:.0} × {:.0}", r.width(), r.height())))
            .size(320.0, 130.0),
    ))
    .spacing(8.0)
}

Open in the playground, with every example →

Full API of RubberBand →