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

79 lines
2.1 KiB
Rust
Raw Normal View History

// Copyright (c) 2022 Marceline Cramer
// SPDX-License-Identifier: AGPL-3.0-or-later
2022-07-15 21:11:35 +00:00
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
pub mod anim;
2022-07-31 05:33:55 +00:00
pub mod main_menu;
2022-11-07 01:27:43 +00:00
pub mod music_player;
2022-11-18 19:43:23 +00:00
pub mod style;
2022-07-15 21:11:35 +00:00
pub mod widgets;
use api::*;
use canary_script::*;
2022-07-31 05:33:55 +00:00
use main_menu::MainMenuPanel;
use music_player::MusicPlayerPanel;
use widgets::Widget;
2022-07-15 21:11:35 +00:00
export_abi!(bind_panel_impl);
2022-07-15 21:11:35 +00:00
fn bind_panel_impl(panel: Panel, protocol: Message, msg: Message) -> Box<dyn PanelImpl> {
let protocol = protocol.to_vec();
let protocol = String::from_utf8(protocol).unwrap();
match protocol.as_str() {
"tebibyte-media.desktop.music-player-controller" => MusicPlayerPanel::bind(panel, msg),
"wip-dialog" => ConfirmationDialogPanel::bind(panel, msg),
_ => MainMenuPanel::bind(panel, msg),
}
}
2022-07-15 21:11:35 +00:00
2022-07-28 04:24:55 +00:00
pub const ICON_FONT: &str = "Iosevka Nerd Font";
pub const DISPLAY_FONT: &str = "Homenaje";
2022-07-31 06:29:36 +00:00
pub const CONTENT_FONT: &str = "Ubuntu";
2022-07-28 04:24:55 +00:00
2022-07-27 07:43:54 +00:00
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);
2022-07-27 07:43:54 +00:00
self.dialog.draw(&ctx);
}
2022-11-05 20:28:07 +00:00
fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) {
2022-07-27 07:43:54 +00:00
self.dialog.on_cursor_event(kind, at.into());
}
2022-08-17 00:11:56 +00:00
fn on_resize(&mut self, size: Vec2) {
self.dialog.resize(size);
}
2022-11-05 20:28:07 +00:00
2022-08-17 00:11:56 +00:00
fn on_message(&mut self, _msg: Message) {}
2022-07-27 07:43:54 +00:00
}
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();
let info = DialogInfo {
title: "Hello world!".to_string(),
content: "Testing, testing...".to_string(),
responses: vec![DialogResponse::Yes, DialogResponse::No],
};
use widgets::dialog::*;
let style = DialogStyle::default();
let dialog = Dialog::new(style, &info);
Box::new(Self { panel, dialog })
}
}