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
22.19k stars 1.6k forks source link

ViewportBuilder::with_visible(false) does not work #3654

Open BaZzz01010101 opened 11 months ago

BaZzz01010101 commented 11 months ago

Describe the bug If to run the app with viewport visibility set to false, the window is displayed anyway.

To Reproduce

fn main() {
    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default()
            .with_visible(false), // NOT WORKING
        ..Default::default()
    };

    eframe::run_simple_native("Auto-Brightness", options, |_ctx, _frame| {
    }).unwrap();
}

Expected behavior The application should start with the main window hidden.

Desktop (please complete the following information):

kryptan commented 2 months ago

Window is unconditionally made visible in EpiIntegration::post_rendering:

pub fn post_rendering(&mut self, window: &winit::window::Window) {
    crate::profile_function!();
    if std::mem::take(&mut self.is_first_frame) {
        // We keep hidden until we've painted something. See https://github.com/emilk/egui/pull/2279
        window.set_visible(true);
    }
}

https://github.com/emilk/egui/blob/9a1e358a144b5d2af9d03a80257c34883f57cf0b/crates/eframe/src/native/epi_integration.rs#L309