winctx/
icons.rs

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