Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to make the transparent window blurry #2728

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rhysd
Copy link
Contributor

@rhysd rhysd commented Jan 13, 2025

This PR adds blur option to the iced::window::Settings struct. When enabling it, the window has a blurry effect. The option value will be passed to winit.

Here is a screenshot of example:

image
use iced::theme::Style;
use iced::widget::{container, text};
use iced::window::Settings;
use iced::{Color, Element, Length::Fill, Theme};

pub fn main() -> iced::Result {
    iced::application("Test", Test::update, Test::view)
        .window(Settings {
            transparent: true,
            blur: true,
            ..Default::default()
        })
        .style(Test::style)
        .run()
}

#[derive(Default)]
struct Test;

impl Test {
    fn update(&mut self, _: ()) {}

    fn view(&self) -> impl Into<Element<()>> {
        container(text("This is test")).center(Fill).style(|_| {
            container::Style::default()
                .background(Color::from_rgba(0.0, 0.0, 0.0, 0.3))
        })
    }

    fn style(&self, theme: &Theme) -> Style {
        Style {
            background_color: Color::TRANSPARENT,
            text_color: theme.palette().text,
        }
    }
}

(To make this example work on macOS, the change for #2727 is also needed.)

@rhysd
Copy link
Contributor Author

rhysd commented Jan 26, 2025

I haven't explained the use case of this feature.

My use case for this feature is creating a visual effect for macOS apps. It is common for the side menu of macOS apps to have a blurry appearance. For example, Finder (the default file manager in macOS) has a similar effect, as shown below. I would like to achieve the same effect for my macOS app to provide a natural look and feel.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant