sao-ui-rs/src/lib.rs

66 lines
1.3 KiB
Rust
Raw Normal View History

2022-07-07 18:39:21 +00:00
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
2022-07-08 18:48:31 +00:00
pub use glam::Vec2;
2022-07-07 18:39:21 +00:00
2022-07-08 18:48:31 +00:00
pub mod abi;
2022-07-08 19:48:32 +00:00
pub mod anim;
2022-07-08 18:48:31 +00:00
pub mod draw;
pub mod panel;
pub mod widgets;
2022-07-07 18:39:21 +00:00
2022-07-08 18:48:31 +00:00
use abi::UiPanel;
use widgets::Widget;
2022-07-07 18:39:21 +00:00
pub struct DummyPanel {
panel: UiPanel,
2022-07-09 02:07:19 +00:00
buttons: Vec<widgets::RoundButton>,
2022-07-07 18:39:21 +00:00
}
impl DummyPanel {
fn bind(panel: UiPanel) -> Self {
2022-07-09 02:07:19 +00:00
let mut buttons = Vec::new();
for i in 0..6 {
let mut button = widgets::RoundButton::default();
button.pos.y = i as f32 * 0.2;
buttons.push(button);
2022-07-08 18:48:31 +00:00
}
2022-07-09 02:07:19 +00:00
Self { panel, buttons }
2022-07-07 18:39:21 +00:00
}
}
2022-07-08 18:48:31 +00:00
impl abi::PanelImpl for DummyPanel {
fn update(&mut self, dt: f32) {
let ctx = draw::DrawContext::new(self.panel);
2022-07-09 02:07:19 +00:00
for button in self.buttons.iter_mut() {
button.update(dt);
button.draw(&ctx);
}
2022-07-08 18:48:31 +00:00
}
2022-07-08 19:48:32 +00:00
fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) {
2022-07-09 02:07:19 +00:00
for button in self.buttons.iter_mut() {
button.on_cursor_event(kind, at);
}
2022-07-08 19:48:32 +00:00
}
2022-07-07 18:39:21 +00:00
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}
2022-07-08 19:48:32 +00:00
#[derive(Copy, Clone, Debug)]
pub enum CursorEventKind {
Hover,
Select,
Drag,
Deselect,
}