Skip to main content

bhoo/systems/material/
icons.rs

1use crate::*;
2
3/// Bundled 24 dp Material Icons for top app bar actions.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum AppBarIcon {
6    Back,
7    Forward,
8    Folder,
9    Tab,
10    Search,
11    More,
12    Menu,
13    Add,
14}
15impl AppBarIcon {
16    pub(crate) fn shape_index(self, rtl: bool) -> u8 {
17        let base = match self {
18            Self::Back if rtl => 17,
19            Self::Back => 16,
20            Self::Forward if rtl => 16,
21            Self::Forward => 17,
22            Self::Folder => 3,
23            Self::Tab => 21,
24            Self::Search => 18,
25            Self::More => 19,
26            Self::Menu => 14,
27            Self::Add => 20,
28        };
29        (crate::beercss_shapes::SHAPES.len() + base) as u8
30    }
31}
32
33/// Official Material Symbols Outlined, regular weight at optical size 24.
34/// Geometry is bundled; no platform font or network access is required.
35#[derive(Clone, Copy, Debug, PartialEq, Eq)]
36#[repr(usize)]
37pub enum MaterialIcon {
38    Widgets,
39    Code,
40    Palette,
41    Pause,
42    DarkMode,
43    LightMode,
44    Download,
45    Menu,
46    MenuOpen,
47    VerticalAlignTop,
48    VerticalAlignBottom,
49    Close,
50    Check,
51    Add,
52    ArrowBack,
53    ArrowForward,
54    Search,
55    MoreVert,
56    Home,
57    Settings,
58    Inbox,
59    Star,
60    Archive,
61    ChevronRight,
62    Person,
63    Delete,
64    MarkEmailUnread,
65    Mail,
66    ChatBubble,
67    Videocam,
68    Edit,
69    Sell,
70    AttachFile,
71    Send,
72    Reply,
73    MoreHoriz,
74    ChevronLeft,
75    Image,
76    SentimentSatisfied,
77    Description,
78}
79impl MaterialIcon {
80    pub const ALL: &'static [Self] = &[
81        Self::Widgets,
82        Self::Code,
83        Self::Palette,
84        Self::Pause,
85        Self::DarkMode,
86        Self::LightMode,
87        Self::Download,
88        Self::Menu,
89        Self::MenuOpen,
90        Self::VerticalAlignTop,
91        Self::VerticalAlignBottom,
92        Self::Close,
93        Self::Check,
94        Self::Add,
95        Self::ArrowBack,
96        Self::ArrowForward,
97        Self::Search,
98        Self::MoreVert,
99        Self::Home,
100        Self::Settings,
101        Self::Inbox,
102        Self::Star,
103        Self::Archive,
104        Self::ChevronRight,
105        Self::Person,
106        Self::Delete,
107        Self::MarkEmailUnread,
108        Self::Mail,
109        Self::ChatBubble,
110        Self::Videocam,
111        Self::Edit,
112        Self::Sell,
113        Self::AttachFile,
114        Self::Send,
115        Self::Reply,
116        Self::MoreHoriz,
117        Self::ChevronLeft,
118        Self::Image,
119        Self::SentimentSatisfied,
120        Self::Description,
121    ];
122    pub fn name(self) -> &'static str {
123        crate::icons::material_symbols::ICONS[self as usize].name
124    }
125}
126
127impl Frame<'_> {
128    /// Paint a bundled Material navigation icon without adding a focus target.
129    pub fn paint_navigation_icon(
130        &mut self,
131        bounds: Rect,
132        icon: NavigationIcon,
133        selected: bool,
134        color: Color,
135    ) {
136        self.commands.push(DrawCommand::Shape {
137            bounds,
138            index: icon.shape_index(selected),
139            color,
140            rotation: 0.0,
141        });
142    }
143    /// Paint an official Material Symbol inside its original 24dp design box.
144    /// The symbol is centered with its aspect ratio preserved within `bounds`.
145    pub fn paint_material_icon(&mut self, bounds: Rect, icon: MaterialIcon, color: Color) {
146        let size = bounds.width.min(bounds.height);
147        if !size.is_finite() || size <= 0.0 { return; }
148        let bounds = Rect { x: bounds.x + (bounds.width-size)/2.0,
149            y: bounds.y + (bounds.height-size)/2.0, width: size, height: size };
150        self.commands.push(DrawCommand::Shape {
151            bounds,
152            index: (crate::beercss_shapes::SHAPES.len() + crate::icons::material_navigation::ICONS.len() + icon as usize) as u8,
153            color, rotation: 0.0,
154        });
155    }
156}
157
158#[cfg(test)]
159#[path = "icons.spec.rs"]
160mod tests;