ailloli_ui_widgets/primitives/
image.rs

1//! Provider-neutral image references and their current draw-command mapping.
2
3use ailloli_ui_core::{Color, IconId, ImageId, Rect};
4use ailloli_ui_runtime::{DrawCmd, DrawImage};
5
6#[derive(Debug, Clone, PartialEq, Eq, Hash)]
7/// Image source accepted by [`draw_image`].
8///
9/// The `Image` variant is a reserved sentinel until runtime image resources are
10/// implemented; only `Icon` currently produces a command.
11///
12/// # Examples
13///
14/// ```
15/// use ailloli_ui_core::{IconId, ImageId};
16/// use ailloli_ui_widgets::primitives::ImageRef;
17/// assert_ne!(ImageRef::Icon(IconId::Close), ImageRef::Image(ImageId(1)));
18/// ```
19pub enum ImageRef {
20    /// Font glyph or SVG source renderable by the current runtime.
21    Icon(IconId),
22    /// Future runtime image resource; currently produces no draw command.
23    Image(ImageId),
24}
25
26/// The runtime IR currently supports Lucide icons via `IconId` only.
27///
28/// `Image(ImageId)` is reserved for future use and does not emit `DrawCmd` yet.
29/// Coordinates, tint, and icon source are otherwise passed through unchanged,
30/// with rotation fixed at zero radians.
31///
32/// # Examples
33///
34/// ```
35/// use ailloli_ui_core::{Color, IconId, ImageId, Rect};
36/// use ailloli_ui_widgets::primitives::{draw_image, ImageRef};
37/// let rect = Rect::new(0.0, 0.0, 16.0, 16.0);
38/// assert!(draw_image(rect, ImageRef::Icon(IconId::Close), Color::WHITE).is_some());
39/// assert!(draw_image(rect, ImageRef::Image(ImageId(7)), Color::WHITE).is_none());
40/// ```
41pub fn draw_image(rect: Rect, image: ImageRef, tint: Color) -> Option<DrawCmd> {
42    match image {
43        ImageRef::Icon(icon) => Some(DrawCmd::Image(DrawImage {
44            rect,
45            icon,
46            tint,
47            rotation_rad: 0.0,
48        })),
49        ImageRef::Image(_image_id) => None,
50    }
51}