use crate::event::Event;
use crate::renderer::Renderer;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Rect {
pub x: i32,
pub y: i32,
pub width: i32,
pub height: i32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Color(
pub u8,
pub u8,
pub u8,
pub u8,
);
impl Color {
pub fn to_argb8888(self) -> u32 {
((self.3 as u32) << 24) | ((self.0 as u32) << 16) | ((self.1 as u32) << 8) | (self.2 as u32)
}
pub fn with_alpha(self, opacity: u8) -> Color {
Color(
self.0,
self.1,
self.2,
((self.3 as u16 * opacity as u16) / 255) as u8,
)
}
}
pub trait Widget {
fn bounds(&self) -> Rect;
fn draw(&self, renderer: &mut dyn Renderer);
fn handle_event(&mut self, event: &Event) -> bool;
fn clear_region(&mut self) -> Option<Rect> {
None
}
}