// Copyright (c) 2022 Marceline Cramer // SPDX-License-Identifier: AGPL-3.0-or-later use crate::{CursorEventKind, Vec2}; use canary_script::{api::DrawContext, Rect}; pub mod button; pub mod dialog; pub mod flex; pub mod menu; pub mod palette; pub mod scroll; pub mod slider; pub mod shell; pub mod text; #[allow(unused)] pub trait Widget { fn update(&mut self, dt: f32) {} fn draw(&mut self, ctx: &DrawContext) {} fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) {} } impl Widget for Option { fn update(&mut self, dt: f32) { if let Some(inner) = self.as_mut() { inner.update(dt); } } fn draw(&mut self, ctx: &DrawContext) { if let Some(inner) = self.as_mut() { inner.draw(ctx); } } fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) { if let Some(inner) = self.as_mut() { inner.on_cursor_event(kind, at); } } } pub trait RectBounds { fn get_bounds(&self) -> Rect; } pub trait Button { fn was_clicked(&self) -> bool; } #[allow(unused)] pub trait Container { fn with_children(&mut self, f: impl FnMut(&mut dyn Widget)); fn update(&mut self, dt: f32) {} fn draw(&mut self, ctx: &DrawContext) {} fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) {} } impl Widget for T { fn update(&mut self, dt: f32) { ::update(self, dt); self.with_children(|w| w.update(dt)); } fn draw(&mut self, ctx: &DrawContext) { ::draw(self, ctx); self.with_children(|w| w.draw(ctx)); } fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) { ::on_cursor_event(self, kind, at); self.with_children(|w| w.on_cursor_event(kind, at)); } } pub mod prelude { pub use super::*; pub use crate::anim::Animation; pub use crate::style::{self, THEME}; pub use canary_script::{*, api::*}; pub use keyframe::functions::*; }