sao-ui-rs/src/lib.rs

66 lines
1.3 KiB
Rust

#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
pub use glam::Vec2;
pub mod abi;
pub mod anim;
pub mod draw;
pub mod panel;
pub mod widgets;
use abi::UiPanel;
use widgets::Widget;
pub struct DummyPanel {
panel: UiPanel,
buttons: Vec<widgets::RoundButton>,
}
impl DummyPanel {
fn bind(panel: UiPanel) -> Self {
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);
}
Self { panel, buttons }
}
}
impl abi::PanelImpl for DummyPanel {
fn update(&mut self, dt: f32) {
let ctx = draw::DrawContext::new(self.panel);
for button in self.buttons.iter_mut() {
button.update(dt);
button.draw(&ctx);
}
}
fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) {
for button in self.buttons.iter_mut() {
button.on_cursor_event(kind, at);
}
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}
#[derive(Copy, Clone, Debug)]
pub enum CursorEventKind {
Hover,
Select,
Drag,
Deselect,
}