From 53eccd741193317867efc36463a318e79a9e31d9 Mon Sep 17 00:00:00 2001 From: mars Date: Wed, 16 Nov 2022 19:27:54 -0700 Subject: [PATCH] Update scripts to use new protocol names --- scripts/music-player/src/lib.rs | 40 +++++++++++++++++---------------- scripts/sao-ui/src/lib.rs | 34 +++++++++++++++------------- scripts/sao-ui/src/main_menu.rs | 18 +++++++-------- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/scripts/music-player/src/lib.rs b/scripts/music-player/src/lib.rs index a4bee91..956df2b 100644 --- a/scripts/music-player/src/lib.rs +++ b/scripts/music-player/src/lib.rs @@ -4,10 +4,14 @@ #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; -use canary_script::*; use api::*; +use canary_script::*; -canary_script::export_abi!(MusicPlayerPanel); +canary_script::export_abi!(bind_panel_impl); + +pub fn bind_panel_impl(panel: Panel, _protocol: Message, message: Message) -> Box { + MusicPlayerPanel::bind(panel, message) +} const DISPLAY_FONT: &str = "Liberation Sans"; @@ -17,19 +21,6 @@ pub struct MusicPlayerPanel { label: Label, } -impl BindPanel for MusicPlayerPanel { - fn bind(panel: Panel, message: Message) -> Box { - let display_font = Font::new(DISPLAY_FONT); - let label = Label::new(display_font, "Hello, world!".into(), 1.2); - let panel = Self { - panel, - display_font, - label, - }; - Box::new(panel) - } -} - impl PanelImpl for MusicPlayerPanel { fn update(&mut self, dt: f32) {} @@ -42,20 +33,31 @@ impl PanelImpl for MusicPlayerPanel { self.label.draw(&ctx, offset, size, color); } - fn on_resize(&mut self, new_size: Vec2) { - - } + fn on_resize(&mut self, new_size: Vec2) {} fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) {} fn on_message(&mut self, msg: Message) { - use canary_music_player::{InMsg, serde_json}; + use canary_music_player::{serde_json, InMsg}; let msg = msg.to_vec(); let msg = serde_json::from_slice::(&msg); self.label.set_text(format!("{:#?}", msg)); } } +impl MusicPlayerPanel { + pub fn bind(panel: Panel, _message: Message) -> Box { + let display_font = Font::new(DISPLAY_FONT); + let label = Label::new(display_font, "Hello, world!".into(), 1.2); + let panel = Self { + panel, + display_font, + label, + }; + Box::new(panel) + } +} + pub struct Label { font: Font, text: String, diff --git a/scripts/sao-ui/src/lib.rs b/scripts/sao-ui/src/lib.rs index 0d12dc2..23d535b 100644 --- a/scripts/sao-ui/src/lib.rs +++ b/scripts/sao-ui/src/lib.rs @@ -8,12 +8,16 @@ pub mod anim; pub mod main_menu; pub mod widgets; -use canary_script::*; use api::*; -use widgets::Widget; +use canary_script::*; use main_menu::MainMenuPanel; +use widgets::Widget; -export_abi!(MainMenuPanel); +export_abi!(bind_panel_impl); + +fn bind_panel_impl(panel: Panel, _protocol: Message, msg: Message) -> Box { + MainMenuPanel::bind(panel, msg) +} pub const ICON_FONT: &str = "Iosevka Nerd Font"; pub const DISPLAY_FONT: &str = "Homenaje"; @@ -24,18 +28,6 @@ pub struct ConfirmationDialogPanel { dialog: widgets::dialog::Dialog, } -impl BindPanel for ConfirmationDialogPanel { - fn bind(panel: Panel, msg: Message) -> Box { - 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 }) - } -} - impl PanelImpl for ConfirmationDialogPanel { fn update(&mut self, dt: f32) { self.dialog.update(dt); @@ -54,3 +46,15 @@ impl PanelImpl for ConfirmationDialogPanel { fn on_message(&mut self, _msg: Message) {} } + +impl ConfirmationDialogPanel { + pub fn bind(panel: Panel, msg: Message) -> Box { + 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 }) + } +} diff --git a/scripts/sao-ui/src/main_menu.rs b/scripts/sao-ui/src/main_menu.rs index f8e3ffc..87bbbb0 100644 --- a/scripts/sao-ui/src/main_menu.rs +++ b/scripts/sao-ui/src/main_menu.rs @@ -15,15 +15,6 @@ pub struct MainMenuPanel { menu: MainMenu, } -impl BindPanel for MainMenuPanel { - fn bind(panel: Panel, msg: Message) -> Box { - Box::new(Self { - panel, - menu: MainMenu::default(), - }) - } -} - impl PanelImpl for MainMenuPanel { fn update(&mut self, dt: f32) { Widget::update(&mut self.menu, dt); @@ -43,6 +34,15 @@ impl PanelImpl for MainMenuPanel { fn on_message(&mut self, msg: Message) {} } +impl MainMenuPanel { + pub fn bind(panel: Panel, msg: Message) -> Box { + Box::new(Self { + panel, + menu: MainMenu::default(), + }) + } +} + pub struct MainMenu { pub menu: Offset>, pub player_info: Reveal>,