Components / CompareView

CompareView

Two pictures side by side or across a divider you drag.

Example

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

Code

use ravenrs::prelude::*;

fn compare_view() -> AnyView {
    let tone = |warm: f32| {
        ImageData::from_fn(240, 160, move |x, y| {
            let light = 0.25 + 0.5 * x as f32 / 240.0;
            Color::rgb(light + warm, light, light - warm + 0.2 * y as f32 / 160.0)
        })
    };
    match (tone(0.0), tone(0.2)) {
        (Some(before), Some(after)) => {
            Box::new(CompareView::new(before, after).mode(CompareMode::Divider).size(420.0, 200.0))
        }
        _ => Box::new(Text::new("No pictures")),
    }
}

Open in the playground, with every example →

Full API of CompareView →