1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! Type used to interact with an icons collection.
use crate::{IconBuffer, IconId};
/// A collection of notification icons.
///
/// This defines the various icons that an application using winctx can use.
///
/// This is returned by [`CreateWindow::icons`].
///
/// [`CreateWindow::icons`]: crate::CreateWindow::icons
#[derive(Default)]
pub struct Icons {
pub(super) icons: Vec<IconBuffer>,
}
impl Icons {
/// Construct a new empty collection of notification icons.
#[inline]
pub fn new() -> Self {
Self::default()
}
/// Push an icon from a buffer and return a handle to it.
///
/// # Examples
///
/// ```
/// use winctx::CreateWindow;
///
/// # macro_rules! include_bytes { ($path:literal) => { &[] } }
/// const ICON: &[u8] = include_bytes!("tokio.ico");
///
/// let mut window = CreateWindow::new("se.tedro.Example");
/// let icon = window.icons().insert_buffer(ICON, 22, 22);
/// ```
pub fn insert_buffer<T>(&mut self, buffer: T, width: u32, height: u32) -> IconId
where
T: AsRef<[u8]>,
{
let icon = IconId::new(self.icons.len() as u32);
self.icons
.push(IconBuffer::from_buffer(buffer, width, height));
icon
}
}