Reviewed-on: iris/iris#16 Reviewed-by: iris <2+iris@noreply.localhost> Co-authored-by: iris-ai <4+iris-ai@noreply.localhost>
54 lines
1.1 KiB
Rust
54 lines
1.1 KiB
Rust
use crate::prelude::*;
|
|
|
|
#[derive(Clone, Copy)]
|
|
pub struct Rect {
|
|
pub color: UiColor,
|
|
pub radius: f32,
|
|
pub thickness: f32,
|
|
pub inner_radius: f32,
|
|
}
|
|
|
|
impl Rect {
|
|
pub fn new(color: UiColor) -> Self {
|
|
Self {
|
|
color,
|
|
radius: 0.0,
|
|
inner_radius: 0.0,
|
|
thickness: 0.0,
|
|
}
|
|
}
|
|
pub fn color(mut self, color: UiColor) -> Self {
|
|
self.color = color;
|
|
self
|
|
}
|
|
pub fn radius(mut self, radius: impl UiNum) -> Self {
|
|
self.radius = radius.to_f32();
|
|
self
|
|
}
|
|
}
|
|
|
|
impl Widget for Rect {
|
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
|
painter.primitive(RectPrimitive {
|
|
color: self.color,
|
|
radius: self.radius,
|
|
thickness: self.thickness,
|
|
inner_radius: self.inner_radius,
|
|
});
|
|
Size::REST
|
|
}
|
|
|
|
fn size_hint(&self, _: Axis) -> Option<Len> {
|
|
Some(Len::REST)
|
|
}
|
|
|
|
/// Its box is its primitive's own region, so a new one is written there.
|
|
fn on_resize(&self, _: Axis) -> OnResize {
|
|
OnResize::Scale
|
|
}
|
|
}
|
|
|
|
pub fn rect(color: UiColor) -> Rect {
|
|
Rect::new(color)
|
|
}
|