diff options
Diffstat (limited to '')
| -rw-r--r-- | winit/src/application.rs | 3 | ||||
| -rw-r--r-- | winit/src/conversion.rs | 9 | ||||
| -rw-r--r-- | winit/src/settings.rs | 7 | ||||
| -rw-r--r-- | winit/src/window.rs | 9 | 
4 files changed, 24 insertions, 4 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs index 31654f26..dd345785 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -770,6 +770,9 @@ pub fn run_command<A, E>(                          mode,                      ));                  } +                window::Action::ChangeIcon(icon) => { +                    window.set_window_icon(conversion::icon(icon)) +                }                  window::Action::FetchMode(tag) => {                      let mode = if window.is_visible().unwrap_or(true) {                          conversion::mode(window.fullscreen()) diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index d2dc9c06..cf066ef6 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -510,6 +510,15 @@ pub fn user_attention(      }  } +/// Converts some [`Icon`] into it's `winit` counterpart. +/// +/// Returns `None` if there is an error during the conversion. +pub fn icon(icon: window::Icon) -> Option<winit::window::Icon> { +    let (pixels, size) = icon.into_raw(); + +    winit::window::Icon::from_rgba(pixels, size.width, size.height).ok() +} +  // As defined in: http://www.unicode.org/faq/private_use.html  pub(crate) fn is_private_use_character(c: char) -> bool {      matches!( diff --git a/winit/src/settings.rs b/winit/src/settings.rs index 78d58000..6658773d 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -92,7 +92,7 @@ pub struct Window {      pub always_on_top: bool,      /// The window icon, which is also usually used in the taskbar -    pub icon: Option<winit::window::Icon>, +    pub icon: Option<crate::window::Icon>,      /// Platform specific settings.      pub platform_specific: platform::PlatformSpecific, @@ -134,8 +134,9 @@ impl Window {              .with_resizable(self.resizable)              .with_decorations(self.decorations)              .with_transparent(self.transparent) -            .with_window_icon(self.icon) -            .with_always_on_top(self.always_on_top); +            .with_window_icon(self.icon.and_then(conversion::icon)) +            .with_always_on_top(self.always_on_top) +            .with_visible(self.visible);          if let Some(position) = conversion::position(              primary_monitor.as_ref(), diff --git a/winit/src/window.rs b/winit/src/window.rs index 961562bd..ba0180c8 100644 --- a/winit/src/window.rs +++ b/winit/src/window.rs @@ -2,7 +2,9 @@  use crate::command::{self, Command};  use iced_native::window; -pub use window::{frames, Event, Mode, RedrawRequest, UserAttention}; +pub use window::{ +    frames, icon, Event, Icon, Mode, RedrawRequest, UserAttention, +};  /// Closes the current window and exits the application.  pub fn close<Message>() -> Command<Message> { @@ -104,3 +106,8 @@ pub fn fetch_id<Message>(          f,      ))))  } + +/// Changes the [`Icon`] of the window. +pub fn change_icon<Message>(icon: Icon) -> Command<Message> { +    Command::single(command::Action::Window(window::Action::ChangeIcon(icon))) +}  | 
