Skip to content

Commit

Permalink
feat: LaunchConfig::with_visible (#935)
Browse files Browse the repository at this point in the history
* feat: `LaunchConfig::with_visible`

* fix: Typo
  • Loading branch information
marc2332 authored Sep 28, 2024
1 parent f9b5e7a commit 5a055cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/renderer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Icon>,
/// Setup callback.
Expand All @@ -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,
Expand Down Expand Up @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions crates/renderer/src/window_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);

Expand Down

0 comments on commit 5a055cc

Please sign in to comment.