2022-10-07 21:52:35 +00:00
|
|
|
// Copyright (c) 2022 Marceline Cramer
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2022-07-31 05:33:55 +00:00
|
|
|
use crate::{CursorEventKind, Vec2};
|
2022-11-01 09:08:57 +00:00
|
|
|
use canary_script::{api::DrawContext, Rect};
|
2022-07-21 21:19:57 +00:00
|
|
|
|
|
|
|
pub mod button;
|
2022-07-27 07:43:54 +00:00
|
|
|
pub mod dialog;
|
2022-07-28 02:39:36 +00:00
|
|
|
pub mod flex;
|
2022-07-21 21:19:57 +00:00
|
|
|
pub mod menu;
|
2022-11-19 22:11:09 +00:00
|
|
|
pub mod palette;
|
2022-07-21 21:19:57 +00:00
|
|
|
pub mod scroll;
|
2022-11-22 03:25:29 +00:00
|
|
|
pub mod slider;
|
2022-07-21 21:19:57 +00:00
|
|
|
pub mod shell;
|
|
|
|
pub mod text;
|
|
|
|
|
2022-07-27 05:09:52 +00:00
|
|
|
#[allow(unused)]
|
2022-07-21 21:19:57 +00:00
|
|
|
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) {}
|
|
|
|
}
|
|
|
|
|
2022-07-27 05:09:52 +00:00
|
|
|
impl<T: Widget> Widget for Option<T> {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 03:21:24 +00:00
|
|
|
pub trait RectBounds {
|
|
|
|
fn get_bounds(&self) -> Rect;
|
|
|
|
}
|
|
|
|
|
2022-07-31 05:33:55 +00:00
|
|
|
pub trait Button {
|
|
|
|
fn was_clicked(&self) -> bool;
|
|
|
|
}
|
|
|
|
|
2022-07-28 02:52:56 +00:00
|
|
|
#[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<T: Container> Widget for T {
|
|
|
|
fn update(&mut self, dt: f32) {
|
|
|
|
<Self as Container>::update(self, dt);
|
|
|
|
self.with_children(|w| w.update(dt));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn draw(&mut self, ctx: &DrawContext) {
|
|
|
|
<Self as Container>::draw(self, ctx);
|
|
|
|
self.with_children(|w| w.draw(ctx));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) {
|
|
|
|
<Self as Container>::on_cursor_event(self, kind, at);
|
|
|
|
self.with_children(|w| w.on_cursor_event(kind, at));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-31 05:33:55 +00:00
|
|
|
pub mod prelude {
|
|
|
|
pub use super::*;
|
|
|
|
pub use crate::anim::Animation;
|
2022-11-18 20:08:17 +00:00
|
|
|
pub use crate::style::{self, THEME};
|
2022-11-01 09:08:57 +00:00
|
|
|
pub use canary_script::{*, api::*};
|
2022-07-31 05:33:55 +00:00
|
|
|
pub use keyframe::functions::*;
|
2022-07-27 04:44:53 +00:00
|
|
|
}
|