add action set icon while running (#1590)
* set windows icon live action * change get icon to insto raw * remove mobile docs * format * fix format * add file methods to Icon * Rename action to `ChangeIcon` and tidy up `Icon` modules * Fix documentation of `icon::Error` * Remove unnecessary `\` in `icon` documentation * Remove `etc.` from `Icon` documentation --------- Co-authored-by: Héctor Ramón Jiménez <hector0193@gmail.com>
This commit is contained in:
parent
e7549877ef
commit
5a056ce051
9 changed files with 177 additions and 163 deletions
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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!(
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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)))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue