@@ -91,13 +91,18 @@ impl WindowResizeConstraints {
91
91
}
92
92
}
93
93
94
+ /// Generic icon buffer for a window.
95
+ /// Replicates the struct from winit.
96
+ ///
97
+ /// Only allows rgba images.
94
98
#[ derive( Debug , Clone ) ]
95
99
pub struct WindowIconBytes {
96
100
bytes : Vec < u8 > ,
97
101
width : u32 ,
98
102
height : u32 ,
99
103
}
100
104
105
+ /// Errors that occur while constructing window icons.
101
106
#[ derive( Error , Debug ) ]
102
107
pub enum WindowIconBytesError {
103
108
#[ error( "32bpp RGBA image buffer expected, but {bytes_length} is not divisible by 4" ) ]
@@ -109,6 +114,10 @@ pub enum WindowIconBytesError {
109
114
} ,
110
115
}
111
116
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.
112
121
#[ derive( Debug , Clone ) ]
113
122
pub enum WindowIcon {
114
123
Path ( PathBuf ) ,
@@ -131,7 +140,14 @@ impl From<WindowIconBytes> for WindowIcon {
131
140
}
132
141
133
142
impl 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 > {
135
151
let pixel_count = ( width * height) as usize ;
136
152
let pixel_bytes_length = pixel_count * 4 ;
137
153
let bytes_length = bytes. len ( ) ;
@@ -152,14 +168,17 @@ impl WindowIconBytes {
152
168
}
153
169
}
154
170
171
+ /// Bytes of the rgba icon.
155
172
pub fn bytes ( & self ) -> & [ u8 ] {
156
173
& self . bytes
157
174
}
158
175
176
+ /// Width of the icon.
159
177
pub fn width ( & self ) -> u32 {
160
178
self . width
161
179
}
162
180
181
+ /// Height if the icon.
163
182
pub fn height ( & self ) -> u32 {
164
183
self . height
165
184
}
@@ -200,9 +219,9 @@ pub struct Window {
200
219
cursor_position : Option < Vec2 > ,
201
220
focused : bool ,
202
221
mode : WindowMode ,
222
+ icon : Option < WindowIcon > ,
203
223
#[ cfg( target_arch = "wasm32" ) ]
204
224
pub canvas : Option < String > ,
205
- icon : Option < WindowIcon > ,
206
225
command_queue : Vec < WindowCommand > ,
207
226
}
208
227
0 commit comments