@@ -91,13 +91,18 @@ impl WindowResizeConstraints {
9191 }
9292}
9393
94+ /// Generic icon buffer for a window.
95+ /// Replicates the struct from winit.
96+ ///
97+ /// Only allows rgba images.
9498#[ derive( Debug , Clone ) ]
9599pub struct WindowIconBytes {
96100 bytes : Vec < u8 > ,
97101 width : u32 ,
98102 height : u32 ,
99103}
100104
105+ /// Errors that occur while constructing window icons.
101106#[ derive( Error , Debug ) ]
102107pub enum WindowIconBytesError {
103108 #[ error( "32bpp RGBA image buffer expected, but {bytes_length} is not divisible by 4" ) ]
@@ -109,6 +114,10 @@ pub enum WindowIconBytesError {
109114 } ,
110115}
111116
117+ /// The icon on a window.
118+ /// The path buffer in the `Path` variant will be passed to the asset server and will automatically trigger the call to the window backend.
119+ ///
120+ /// Make sure that the source image is reasonably sized. Refer to winit's `set_window_icon` function.
112121#[ derive( Debug , Clone ) ]
113122pub enum WindowIcon {
114123 Path ( PathBuf ) ,
@@ -131,7 +140,14 @@ impl From<WindowIconBytes> for WindowIcon {
131140}
132141
133142impl WindowIconBytes {
134- pub fn new ( bytes : Vec < u8 > , width : u32 , height : u32 ) -> Result < Self , WindowIconBytesError > {
143+ /// Create a window icon from a rgba image.
144+ ///
145+ /// Returns a `WindowIconBytesError` if `bytes` do not add up to a rgba image or the size does not match the specified width and height.
146+ pub fn from_rgba (
147+ bytes : Vec < u8 > ,
148+ width : u32 ,
149+ height : u32 ,
150+ ) -> Result < Self , WindowIconBytesError > {
135151 let pixel_count = ( width * height) as usize ;
136152 let pixel_bytes_length = pixel_count * 4 ;
137153 let bytes_length = bytes. len ( ) ;
@@ -152,14 +168,17 @@ impl WindowIconBytes {
152168 }
153169 }
154170
171+ /// Bytes of the rgba icon.
155172 pub fn bytes ( & self ) -> & [ u8 ] {
156173 & self . bytes
157174 }
158175
176+ /// Width of the icon.
159177 pub fn width ( & self ) -> u32 {
160178 self . width
161179 }
162180
181+ /// Height if the icon.
163182 pub fn height ( & self ) -> u32 {
164183 self . height
165184 }
@@ -200,9 +219,9 @@ pub struct Window {
200219 cursor_position : Option < Vec2 > ,
201220 focused : bool ,
202221 mode : WindowMode ,
222+ icon : Option < WindowIcon > ,
203223 #[ cfg( target_arch = "wasm32" ) ]
204224 pub canvas : Option < String > ,
205- icon : Option < WindowIcon > ,
206225 command_queue : Vec < WindowCommand > ,
207226}
208227
0 commit comments