iced-rs / iced

A cross-platform GUI library for Rust, inspired by Elm
https://iced.rs
MIT License
24.6k stars 1.15k forks source link

Window transparency does not work under Windows #2525

Open doums opened 3 months ago

doums commented 3 months ago

Is your issue REALLY a bug?

Is there an existing issue for this?

Is this issue related to iced?

What happened?

Window transparent background does not work, it renders as solid black color, under Windows11. Setting wgpu in features changes nothing. Note: My gpu is an Nvidia card 4070, driver uptodate

Test program: Cargo.toml

[package]
name = "transparency"
version = "0.1.0"
edition = "2021"

[dependencies]
iced = { version = "0.12", features = ["wgpu", "debug"] }

main.rs

use iced::theme::Palette;
use iced::widget::container;
use iced::window::Level;
use iced::{
    executor, mouse, Application, Color, Command, Element, Length, Rectangle, Renderer, Sandbox,
    Settings, Size, Theme,
};

pub fn main() -> iced::Result {
    let settings = Settings {
        id: Some("test".into()),
        window: iced::window::Settings {
            size: Size::new(200f32, 200f32),
            transparent: true,
            level: Level::AlwaysOnTop,
            ..iced::window::Settings::default()
        },
        antialiasing: true,
        ..Settings::default()
    };
    TestApp::run(settings)
}

struct TestApp {
    theme: Theme,
}

#[derive(Debug, Clone, Copy)]
enum Message {}

impl Application for TestApp {
    type Executor = executor::Default;
    type Flags = ();
    type Message = Message;
    type Theme = Theme;

    fn new(_flags: ()) -> (TestApp, Command<Self::Message>) {
        (
            TestApp {
                theme: Theme::custom(
                    "main".to_string(),
                    Palette {
                        background: Color::TRANSPARENT,
                        ..Theme::default().palette()
                    },
                ),
            },
            Command::none(),
        )
    }

    fn title(&self) -> String {
        String::from("test")
    }

    fn update(&mut self, _message: Self::Message) -> Command<Self::Message> {
        Command::none()
    }

    fn view(&self) -> Element<Self::Message> {
        container("1234")
            .height(Length::Fill)
            .center_x()
            .center_y()
            .into()
    }

    fn theme(&self) -> Theme {
        self.theme.clone()
    }
}

What is the expected behavior?

Window transparency should work

Version

crates.io release

Operating System

Windows

Do you have any log output?

No response

FaisalAhmedAlghamdi commented 1 day ago

Same issue on windows 10 with an rx 6700 xt on the latest drivers (24.10.1)