emilk / egui

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
https://www.egui.rs/
Apache License 2.0
21.53k stars 1.55k forks source link

Transparency not working depending on the Screen it is created on #4453

Open GeneralBombe opened 4 months ago

GeneralBombe commented 4 months ago

This is if the window starts on the second monitor: grafik

This is on main screen: grafik

However if i dray the window from second screen to main screen, it works. This is the code i use:


use eframe::egui::*;

fn main() {
    let native_options = eframe::NativeOptions {
        viewport: ViewportBuilder::default()
            .with_inner_size(vec2(480.0, 270.0))
            .with_min_inner_size(vec2(480.0, 270.0))
            .with_transparent(true),
        ..Default::default()
    };

    let _ = eframe::run_native(
        &format!("My App{}", env!("CARGO_PKG_VERSION")),
        native_options,
        Box::new(|cc| {
            let mut visuals = Visuals::dark();
            // make panels transparent
            visuals.panel_fill = Color32::from_rgba_premultiplied(
                visuals.panel_fill.r(),
                visuals.panel_fill.g(),
                visuals.panel_fill.b(),
                100,
            );
            cc.egui_ctx.set_visuals(visuals);
            cc.egui_ctx
                .set_pixels_per_point(cc.egui_ctx.native_pixels_per_point().unwrap_or(1.0) * 1.2);
            Box::new(App::default())
        }),
    );
}

#[derive(Default)]
struct App {}

impl eframe::App for App {
    fn update(&mut self, ctx: &eframe::egui::Context, _frame: &mut eframe::Frame) {
        CentralPanel::default().show(ctx, |ui| {
            ui.label("main viewport");
        });

    }

    fn clear_color(&self, _visuals: &eframe::egui::Visuals) -> [f32; 4] {
        // fully transparent clear
        [0.0, 1.0, 0.0, 0.0]
    }
}

I really dont understand what is happening ...

I am using a AMD RX 7000 Gpu.

rustbasic commented 4 months ago

When you have clear_color(), try using frame in the following form:

        let mut panel_frame = egui::Frame {
            fill: ctx.style().visuals.window_fill(),
            ..Default::default()
        };

OR

        let mut panel_frame = egui::Frame {
            fill: egui::Color32::TRANSPARENT,
            ..Default::default()
        };

Try various tests.

SSFRPA commented 1 month ago

Me too, AMD,It wasn't transparent when I was full screen,It became transparent when I moved the window

GeneralBombe commented 1 month ago

Me too, AMD,It wasn't transparent when I was full screen,It became transparent when I moved the window

I'll try it again later with new egui version. Haven't touched this issue in quite some time, as I had a similar issue with other window/OpenGl crates. Did you move it with the mouse or from the code?

SSFRPA commented 1 month ago

When I use with_fullscreen, the background is black, and then when I drag the window with the mouse, it becomes transparent. If I set it manually .with_position([1., 0.]) with_inner_size([3840.0, 2160.0]) then transparency is also available My operating system is win11