use crate::event::{Event, EventCtx};
use crate::geometry::Rect;
use crate::painter::Painter;
use crate::theme::Theme;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PopupKind {
Popup,
Dialog,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PopupRequest {
pub rect: Rect,
pub kind: PopupKind,
pub title: Option<String>,
}
pub trait Widget {
fn bounds(&self) -> Rect;
fn paint(&mut self, painter: &mut Painter, theme: &Theme);
fn paint_overlay(&mut self, _painter: &mut Painter, _theme: &Theme) {}
fn event(&mut self, _event: &Event, _ctx: &mut EventCtx) {}
fn on_cancel(&mut self, _ctx: &mut EventCtx) {}
fn captures_pointer(&self) -> bool {
false
}
fn focusable(&self) -> bool {
false
}
fn set_focused(&mut self, _focused: bool) {}
fn accepts_accelerators(&self) -> bool {
false
}
fn layout(&mut self, _bounds: Rect) {}
fn popup_request(&self) -> Option<PopupRequest> {
None
}
fn collect_popups(&self, out: &mut Vec<PopupRequest>) {
if let Some(req) = self.popup_request() {
out.push(req);
}
}
fn focus_first(&mut self) -> bool {
if self.focusable() {
self.set_focused(true);
true
} else {
false
}
}
fn wants_ticks(&self) -> bool {
false
}
}