canary-rs/scripts/sao-ui/src/lib.rs

61 lines
1.5 KiB
Rust

// Copyright (c) 2022 Marceline Cramer
// SPDX-License-Identifier: AGPL-3.0-or-later
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
pub mod anim;
pub mod main_menu;
pub mod widgets;
use api::*;
use canary_script::*;
use main_menu::MainMenuPanel;
use widgets::Widget;
export_abi!(bind_panel_impl);
fn bind_panel_impl(panel: Panel, _protocol: Message, msg: Message) -> Box<dyn PanelImpl> {
MainMenuPanel::bind(panel, msg)
}
pub const ICON_FONT: &str = "Iosevka Nerd Font";
pub const DISPLAY_FONT: &str = "Homenaje";
pub const CONTENT_FONT: &str = "Ubuntu";
pub struct ConfirmationDialogPanel {
panel: Panel,
dialog: widgets::dialog::Dialog,
}
impl PanelImpl for ConfirmationDialogPanel {
fn update(&mut self, dt: f32) {
self.dialog.update(dt);
}
fn draw(&mut self) {
let ctx = DrawContext::new(self.panel);
self.dialog.draw(&ctx);
}
fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) {
self.dialog.on_cursor_event(kind, at.into());
}
fn on_resize(&mut self, _size: Vec2) {}
fn on_message(&mut self, _msg: Message) {}
}
impl ConfirmationDialogPanel {
pub fn bind(panel: Panel, msg: Message) -> Box<dyn PanelImpl> {
let msg = msg.to_vec();
let info: DialogInfo = serde_json::from_slice(&msg).unwrap();
use widgets::dialog::*;
let style = DialogStyle::default();
let dialog = Dialog::new(style, &info);
Box::new(Self { panel, dialog })
}
}