use crate::event::{Event, EventResponse};
use crate::rect::{Rect, Size};
#[derive(Debug, Clone, Copy)]
pub struct Constraints {
pub min: Size,
pub max: Size,
}
impl Constraints {
pub fn loose(max: Size) -> Self {
Self {
min: Size::ZERO,
max,
}
}
pub fn tight(size: Size) -> Self {
Self {
min: size,
max: size,
}
}
pub fn constrain(&self, size: Size) -> Size {
size.clamp(self.min, self.max)
}
}
pub trait Widget: std::fmt::Debug {
fn layout(&mut self, constraints: Constraints) -> Size;
fn paint(&self, rect: Rect);
fn on_event(&mut self, event: &Event, rect: Rect) -> EventResponse {
let _ = (event, rect);
EventResponse::Ignored
}
fn name(&self) -> &str {
"Widget"
}
}