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

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

Open
GeneralBombe opened this issue May 3, 2024 · 1 comment
Open
Labels
bug Something is broken

Comments

@GeneralBombe
Copy link

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.

@GeneralBombe GeneralBombe added the bug Something is broken label May 3, 2024
@rustbasic
Copy link
Contributor

rustbasic commented May 3, 2024

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.

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

No branches or pull requests

2 participants