ailloli_ui_widgets/primitives/rect.rs
1//! Direct axis-aligned rectangle command construction.
2
3use ailloli_ui_core::{Color, Rect};
4use ailloli_ui_runtime::{DrawCmd, DrawRect};
5
6/// Wraps `rect` and `color` in an unmodified solid rectangle draw command.
7///
8/// Coordinates are logical pixels; negative or non-finite dimensions are not
9/// normalized here and remain the renderer's responsibility.
10///
11/// # Examples
12///
13/// ```
14/// use ailloli_ui_core::{Color, Rect};
15/// use ailloli_ui_runtime::DrawCmd;
16/// use ailloli_ui_widgets::primitives::draw_rect;
17/// let DrawCmd::Rect(rect) = draw_rect(Rect::new(1.0, 2.0, 3.0, 4.0), Color::BLACK) else { panic!() };
18/// assert_eq!(rect.rect.w, 3.0);
19/// ```
20pub fn draw_rect(rect: Rect, color: Color) -> DrawCmd {
21 DrawCmd::Rect(DrawRect { rect, color })
22}