1use crate::event::{Event, EventResponse};
4use crate::rect::{Rect, Size};
5
6#[derive(Debug, Clone, Copy)]
8pub struct Constraints {
9 pub min: Size,
10 pub max: Size,
11}
12
13impl Constraints {
14 pub fn loose(max: Size) -> Self {
15 Self {
16 min: Size::ZERO,
17 max,
18 }
19 }
20 pub fn tight(size: Size) -> Self {
21 Self {
22 min: size,
23 max: size,
24 }
25 }
26
27 pub fn constrain(&self, size: Size) -> Size {
28 size.clamp(self.min, self.max)
29 }
30}
31
32pub trait Widget: std::fmt::Debug {
34 fn layout(&mut self, constraints: Constraints) -> Size;
36
37 fn paint(&self, rect: Rect);
39
40 fn on_event(&mut self, event: &Event, rect: Rect) -> EventResponse {
42 let _ = (event, rect);
43 EventResponse::Ignored
44 }
45
46 fn name(&self) -> &str {
48 "Widget"
49 }
50}