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

The background is completely transparent #5072

Open
lngex opened this issue Sep 5, 2024 · 10 comments
Open

The background is completely transparent #5072

lngex opened this issue Sep 5, 2024 · 10 comments
Labels
bug Something is broken eframe Relates to epi and eframe

Comments

@lngex
Copy link

lngex commented Sep 5, 2024

Using "Viewport Builder::with transparent(true)" to set transparency will result in shadow or translucency. I hope a function can be provided to achieve complete transparency.
图片

@jayy-ahn
Copy link

jayy-ahn commented Sep 9, 2024

Have you tried implementing fn clear_color to MyEguiApp?

impl MyEquiApp {
    fn new(...) {...}
    fn clear_color(&self, _visuals: &egui::Visuals) -> [f32; 4] {
        [0.0, 0.0, 0.0, 0.0]
    }
}

This made the window completely transparent in another project I'm working on.

@lngex
Copy link
Author

lngex commented Sep 10, 2024

Have you tried implementing fn clear_color to MyEguiApp?

impl MyEquiApp {
    fn new(...) {...}
    fn clear_color(&self, _visuals: &egui::Visuals) -> [f32; 4] {
        [0.0, 0.0, 0.0, 0.0]
    }
}

This made the window completely transparent in another project I'm working on.

Using this method will cause the window to be completely black

@lngex
Copy link
Author

lngex commented Sep 18, 2024

图片
Implement clear color and return [0,0,0,0],But the window is not transparent

@lucasmerlin lucasmerlin added eframe Relates to epi and eframe bug Something is broken labels Sep 18, 2024
@jayy-ahn
Copy link

jayy-ahn commented Sep 24, 2024

Try adding a CentralPanel with the frame filled with Color32::TRANSPARENT.

impl eframe::App for MyEguiApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::Window::new("test").show(ctx, |ui| {
            ui.heading("hi");
        };
        egui::CentralPanel::default()
            .frame(egui::Frame::default().fill(Color32::TRANSPARENT))
            .show(ctx, |ui| {});
    }
    fn clear_color(...) {...}

{07AAAF92-D5E3-4545-B23A-CE1AF607BC23}

@lngex
Copy link
Author

lngex commented Sep 24, 2024

图片
I tried to do what you said, but it still didn't work as expected.

@lucasmerlin
Copy link
Collaborator

@jayy-ahn @lngex I'm curious if you're using the gl or the wgpu backend? Maybe that makes a difference?

@lngex
Copy link
Author

lngex commented Sep 24, 2024

@jayy-ahn@lngex我很好奇你是使用gl还是wgpu后端?也许这会有所不同?
I turned on the log, and the log shows the glow used.

[2024-09-24T13:38:30Z DEBUG eframe] Using the glow renderer
[2024-09-24T13:38:30Z TRACE eframe::native::run] Entering the winit event loop (run_on_demand)…
[2024-09-24T13:38:30Z TRACE eframe::native::run] winit event: NewEvents(Init)
[2024-09-24T13:38:30Z TRACE eframe::native::run] event_result: Wait
[2024-09-24T13:38:30Z TRACE eframe::native::run] winit event: Resumed
[2024-09-24T13:38:30Z DEBUG eframe::native::glow_integration] Event::Resumed

This works fine on my other computer, but on this one the background is always black

@rustbasic
Copy link
Contributor

Please check if there are any problems as follows.

See Below:

use eframe::egui::*;

fn main() -> eframe::Result {
    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default()
            .with_inner_size([320.0, 240.0])
            .with_transparent(true),
        ..Default::default()
    };
    eframe::run_native(
        "My egui App",
        options,
        Box::new(|_cc| Ok(Box::<App>::default())),
    )
}

#[derive(Default)]
struct App {
    _temp_value: usize,
    _text: String,
}

impl eframe::App for App {
    fn clear_color(&self, _visuals: &egui::Visuals) -> [f32; 4] {
        [0.0, 0.0, 0.0, 0.0]
    }

    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {

        let panel_frame = Frame::default().fill(egui::Color32::TRANSPARENT);

        egui::CentralPanel::default().frame(panel_frame).show(ctx, |ui| {
            ui.label(RichText::new("Demo").background_color(egui::Color32::LIGHT_GREEN).color(Color32::RED));
        });
    }
}

@lngex
Copy link
Author

lngex commented Oct 30, 2024

Please check if there are any problems as follows.

See Below:

use eframe::egui::*;

fn main() -> eframe::Result {
    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default()
            .with_inner_size([320.0, 240.0])
            .with_transparent(true),
        ..Default::default()
    };
    eframe::run_native(
        "My egui App",
        options,
        Box::new(|_cc| Ok(Box::<App>::default())),
    )
}

#[derive(Default)]
struct App {
    _temp_value: usize,
    _text: String,
}

impl eframe::App for App {
    fn clear_color(&self, _visuals: &egui::Visuals) -> [f32; 4] {
        [0.0, 0.0, 0.0, 0.0]
    }

    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {

        let panel_frame = Frame::default().fill(egui::Color32::TRANSPARENT);

        egui::CentralPanel::default().frame(panel_frame).show(ctx, |ui| {
            ui.label(RichText::new("Demo").background_color(egui::Color32::LIGHT_GREEN).color(Color32::RED));
        });
    }
}

There is no problem with the panel and font setting colors, but the window setting the background to transparent does not take effect

@rustbasic
Copy link
Contributor

There is no problem with the panel and font setting colors, but the window setting the background to transparent does not take effect

The above source code works fine on Windows10 + glow.

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

No branches or pull requests

4 participants