Components / Minimap

Minimap

Small copy of the content with a draggable rectangle around what is in view.

Example

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

Code

use ravenrs::prelude::*;

fn minimap() -> impl View {
    let view = State::new(ZoomView::at(1.0));
    let picture = |frame: ZoomPanPaint, scene: &mut Scene| {
        // ravenrs-lint: allow(raw_color) the stand-in photograph the minimap shows: its colors are the content
        scene.push_quad(Quad::new(frame.placed, Color::rgb(0.2, 0.45, 0.7)));
        let sun = Rect::new(
            frame.placed.x() + frame.placed.width() * 0.6,
            frame.placed.y() + frame.placed.height() * 0.2,
            80.0 * frame.scale,
            80.0 * frame.scale,
        );
        // ravenrs-lint: allow(raw_color) the stand-in photograph the minimap shows: its colors are the content
        scene.push_quad(Quad::new(sun, Color::rgb(0.95, 0.8, 0.3)).radius(40.0 * frame.scale));
    };
    let content = Size::new(800.0, 500.0);
    HStack::new((
        Minimap::custom(view.binding(), content, picture),
        ZoomPanView::custom(view.binding(), content, picture).size(240.0, 150.0),
    ))
    .spacing(12.0)
}

Open in the playground, with every example →

Full API of Minimap →