Skip to content

Is it possible to apply a mask on a view? #857

Answered by jrmoulton
arthur-fontaine asked this question in Q&A
Discussion options

You must be logged in to vote
use floem::{
    Application, IntoView, View, ViewId,
    context::PaintCx,
    kurbo::RoundedRect,
    prelude::palette::css,
    views::{Decorators, empty},
    window::{WindowConfig, WindowId},
};

pub fn launch() {
    Application::new()
        .window(app_view, Some(WindowConfig::default()))
        .run();
}

fn app_view(_: WindowId) -> impl IntoView {
    let v = empty().style(|s| s.size(100, 100).background(css::BLACK));

    masked_view(
        v,
        RoundedRect::from_origin_size((0.0, 0.0), (150.0, 150.0), 9999.0),
    )
    .into_view()
    .style(|s| s.size_full().absolute().inset_left(400).inset_top(400))
}

struct MaskedView {
    id: ViewId,
    inner_id: ViewId,
    c…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@arthur-fontaine
Comment options

@jrmoulton
Comment options

@arthur-fontaine
Comment options

@jrmoulton
Comment options

Answer selected by arthur-fontaine
@arthur-fontaine
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants