pub struct Icon {
pub handle: HANDLE,
/* private fields */
}
Expand description
A wrapper over a icon file (*.ico)
Windows icons are a legacy thing and should only be used when winapi forces you to use them (ex: when setting a window icon).
The Bitmap
object of NWG not only supports transparency if “image-decoder” is enabled but it can also be create from multiple
different sources (including “.ico” files).
To display a icon in an application, see the ImageFrame
control.
Note: Loading an icon from binary source (source_bin) REQUIRES the “image-decoder” feature.
Builder parameters:
source_file
: The source of the icon if it is a file.source_bin
: The source of the icon if it is a binary blob. For example usinginclude_bytes!("my_icon.ico")
.source_system
: The source of the icon if it is a system resource (see OemIcon)source_embed
: The source of the icon if it is stored in an embedded filesource_embed_id
: The number identifier of the icon in the embedded filesource_embed_str
: The string identifier of the icon in the embedded filesize
: Optional. Resize the image to this size.strict
: Use a system placeholder instead of panicking if the image source do no exists.
Example:
use native_windows_gui as nwg;
fn load_icon() -> nwg::Icon {
nwg::Icon::from_file("hello.ico", true).unwrap()
}
fn load_icon_builder() -> nwg::Icon {
let mut icon = nwg::Icon::default();
nwg::Icon::builder()
.source_file(Some("hello.ico"))
.strict(true)
.build(&mut icon);
icon
}
Fields§
§handle: HANDLE
Implementations§
Source§impl Icon
impl Icon
Sourcepub fn builder<'a>() -> IconBuilder<'a>
pub fn builder<'a>() -> IconBuilder<'a>
Examples found in repository?
60 fn build_ui(mut data: SystemTray) -> Result<SystemTrayUi, nwg::NwgError> {
61 use nwg::Event as E;
62
63 // Resources
64 nwg::Icon::builder()
65 .source_file(Some("./test_rc/cog.ico"))
66 .build(&mut data.icon)?;
67
68 // Controls
69 nwg::MessageWindow::builder()
70 .build(&mut data.window)?;
71
72 nwg::TrayNotification::builder()
73 .parent(&data.window)
74 .icon(Some(&data.icon))
75 .tip(Some("Hello"))
76 .build(&mut data.tray)?;
77
78 nwg::Menu::builder()
79 .popup(true)
80 .parent(&data.window)
81 .build(&mut data.tray_menu)?;
82
83 nwg::MenuItem::builder()
84 .text("Hello")
85 .parent(&data.tray_menu)
86 .build(&mut data.tray_item1)?;
87
88 nwg::MenuItem::builder()
89 .text("Popup")
90 .parent(&data.tray_menu)
91 .build(&mut data.tray_item2)?;
92
93 nwg::MenuItem::builder()
94 .text("Exit")
95 .parent(&data.tray_menu)
96 .build(&mut data.tray_item3)?;
97
98 // Wrap-up
99 let ui = SystemTrayUi {
100 inner: Rc::new(data),
101 default_handler: Default::default(),
102 };
103
104 // Events
105 let evt_ui = Rc::downgrade(&ui.inner);
106 let handle_events = move |evt, _evt_data, handle| {
107 if let Some(evt_ui) = evt_ui.upgrade() {
108 match evt {
109 E::OnContextMenu =>
110 if &handle == &evt_ui.tray {
111 SystemTray::show_menu(&evt_ui);
112 }
113 E::OnMenuItemSelected =>
114 if &handle == &evt_ui.tray_item1 {
115 SystemTray::hello1(&evt_ui);
116 } else if &handle == &evt_ui.tray_item2 {
117 SystemTray::hello2(&evt_ui);
118 } else if &handle == &evt_ui.tray_item3 {
119 SystemTray::exit(&evt_ui);
120 },
121 _ => {}
122 }
123 }
124 };
125
126 ui.default_handler.borrow_mut().push(
127 nwg::full_bind_event_handler(&ui.window.handle, handle_events)
128 );
129
130 return Ok(ui);
131 }
Sourcepub fn from_system(sys_icon: OemIcon) -> Icon
pub fn from_system(sys_icon: OemIcon) -> Icon
Single line helper function over the icon builder api.
Use system resources.
Sourcepub fn from_file(path: &str, strict: bool) -> Result<Icon, NwgError>
pub fn from_file(path: &str, strict: bool) -> Result<Icon, NwgError>
Single line helper function over the icon builder api.
Use a file resource.
Sourcepub fn from_bin(bin: &[u8]) -> Result<Icon, NwgError>
pub fn from_bin(bin: &[u8]) -> Result<Icon, NwgError>
Single line helper function over the icon builder api.
Use a binary resource.
Sourcepub fn from_embed(
embed: &EmbedResource,
embed_id: Option<usize>,
embed_str: Option<&str>,
) -> Result<Icon, NwgError>
pub fn from_embed( embed: &EmbedResource, embed_id: Option<usize>, embed_str: Option<&str>, ) -> Result<Icon, NwgError>
Single line helper function over the icon builder api.
Use an embedded resource. Either embed_id
or embed_str
must be defined, not both.
Requires the embed-resource
feature.