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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! This module contains image type definitions.

use crate::{
    platform::{IconApi, Wrapper},
    platform_impl::IconImpl,
    ContextOwner,
    Error,
};

/// Icon types.
#[derive(Debug)]
pub enum IconType {
    /// GIF.
    Gif,
    /// JPEG.
    Jpeg,
    /// PNG.
    Png,
    /// TIFF.
    Tiff,
}

/// System icon.
#[derive(Debug)]
pub struct Icon(IconImpl);

impl Icon {
    /// Creates a new icon from bytes.
    ///
    /// # Parameters:
    /// * `ctx` - Context owner.
    /// * `icon_data` - Icon data in bytes.
    /// * `icon_type` - Icon type.
    pub fn from_data(
        ctx: &impl ContextOwner,
        icon_data: &Vec<u8>,
        icon_type: IconType,
    ) -> Result<Self, Error> {
        Ok(Self(IconImpl::from_data(ctx, icon_data, icon_type)?))
    }

    /// Creates a new image from built-in system icons.
    ///
    /// # Parameters:
    /// * `ctx` - Context owner.
    /// * `title` - Built-in system icon title.
    pub fn from_str<S>(ctx: &impl ContextOwner, title: S) -> Result<Self, Error>
    where
        S: Into<String>,
    {
        Ok(Self(IconImpl::from_str(ctx, &title.into())?))
    }
}

impl Wrapper<IconImpl> for Icon {
    #[inline]
    fn get_impl(&self) -> &IconImpl { &self.0 }

    #[inline]
    fn get_impl_mut(&mut self) -> &mut IconImpl { &mut self.0 }
}