From 5a055ccf06f20d45fa08472dd47a04b7ffd144a3 Mon Sep 17 00:00:00 2001 From: Marc Espin Date: Sat, 28 Sep 2024 15:42:34 +0200 Subject: [PATCH] feat: `LaunchConfig::with_visible` (#935) * feat: `LaunchConfig::with_visible` * fix: Typo --- crates/renderer/src/config.rs | 9 +++++++++ crates/renderer/src/window_state.rs | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/crates/renderer/src/config.rs b/crates/renderer/src/config.rs index 5d647e08a..4466ac4a4 100644 --- a/crates/renderer/src/config.rs +++ b/crates/renderer/src/config.rs @@ -38,6 +38,8 @@ pub struct WindowConfig { pub transparent: bool, /// Background color of the Window. pub background: Color, + /// Window visibility. Default to `true`. + pub visible: bool, /// The Icon of the Window. pub icon: Option, /// Setup callback. @@ -58,6 +60,7 @@ impl Default for WindowConfig { title: "Freya app", transparent: false, background: Color::WHITE, + visible: true, icon: None, on_setup: None, on_exit: None, @@ -159,6 +162,12 @@ impl<'a, T: Clone> LaunchConfig<'a, T> { self } + /// Specify the Window visibility at launch. + pub fn with_visible(mut self, visible: bool) -> Self { + self.window_config.visible = visible; + self + } + /// Embed a font. pub fn with_font(mut self, font_name: &'a str, font: &'a [u8]) -> Self { self.embedded_fonts.push((font_name, font)); diff --git a/crates/renderer/src/window_state.rs b/crates/renderer/src/window_state.rs index 8e7a0c081..57a136264 100644 --- a/crates/renderer/src/window_state.rs +++ b/crates/renderer/src/window_state.rs @@ -75,6 +75,7 @@ impl<'a, State: Clone + 'a> WindowState<'a, State> { }; let mut window_attributes = Window::default_attributes() + .with_visible(false) .with_title(config.window_config.title) .with_decorations(config.window_config.decorations) .with_transparent(config.window_config.transparent) @@ -100,6 +101,10 @@ impl<'a, State: Clone + 'a> WindowState<'a, State> { let (graphics_driver, window, mut surface) = GraphicsDriver::new(event_loop, window_attributes, &config); + if config.window_config.visible { + window.set_visible(true); + } + // Allow IME window.set_ime_allowed(true);