use super::*;
pub struct RRectRenderObject {
pub size: Size,
pub color: Color,
pub radius: f32,
pub element_id: Option<ElementId>,
}
impl RRectRenderObject {
pub fn new(size: Size, color: Color, radius: f32) -> Self {
Self { size, color, radius, element_id: None }
}
pub fn with_element_id(mut self, id: ElementId) -> Self {
self.element_id = Some(id);
self
}
}
impl RenderObject for RRectRenderObject {
fn layout(&mut self, constraints: BoxConstraints, _ctx: &mut LayoutContext) -> Size {
self.size = constraints.constrain(self.size);
self.size
}
fn paint(&self, offset: Point, painter: &mut PaintList) {
let rect = Rect::new(offset.x, offset.y, self.size.width, self.size.height);
painter.rounded_rect(rect, self.color, self.radius);
}
fn hit_test(&self, position: Point, offset: Point) -> Option<ElementId> {
let rect = Rect::new(offset.x, offset.y, self.size.width, self.size.height);
if rect.contains(position) {
self.element_id
} else {
None
}
}
fn set_element_id(&mut self, id: ElementId) {
self.element_id = Some(id);
}
fn element_id(&self) -> Option<ElementId> {
self.element_id
}
fn content_size(&self) -> Size {
self.size
}
}