ailloli_ui_widgets/primitives/
icon.rs

1//! Direct icon draw-command construction without a retained widget.
2
3use ailloli_ui_core::{Color, IconId, Rect};
4use ailloli_ui_runtime::{DrawCmd, DrawImage};
5
6/// Creates an unrotated image command for `icon` in `rect` with `tint`.
7///
8/// Coordinates are logical pixels and are passed through unchanged. The helper
9/// performs no SVG/font validation and always sets rotation to zero radians.
10///
11/// # Examples
12///
13/// ```
14/// use ailloli_ui_core::{Color, IconId, Rect};
15/// use ailloli_ui_runtime::DrawCmd;
16/// use ailloli_ui_widgets::primitives::draw_icon;
17/// let command = draw_icon(Rect::new(1.0, 2.0, 16.0, 16.0), IconId::Close, Color::WHITE);
18/// let DrawCmd::Image(image) = command else { panic!("expected image command") };
19/// assert_eq!(image.rotation_rad, 0.0);
20/// ```
21pub fn draw_icon(rect: Rect, icon: IconId, tint: Color) -> DrawCmd {
22    DrawCmd::Image(DrawImage {
23        rect,
24        icon,
25        tint,
26        rotation_rad: 0.0,
27    })
28}