Add music player script

This commit is contained in:
mars 2022-10-19 22:01:17 -06:00
parent b7c5fa0417
commit dea255cf1d
3 changed files with 52 additions and 0 deletions

View File

@ -4,6 +4,7 @@ members = [
"apps/sandbox",
"crates/script",
"crates/types",
"scripts/music-player",
"scripts/sao-ui",
]

View File

@ -0,0 +1,11 @@
[package]
name = "canary-music-player-script"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
canary_script = { path = "../../crates/script" }
wee_alloc = "^0.4"

View File

@ -0,0 +1,40 @@
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
use canary_script::{BindPanel, CursorEventKind, Color, TextLayout, Font, Message, Panel, PanelImpl, Vec2};
canary_script::export_abi!(MusicPlayerPanel);
const DISPLAY_FONT: &str = "Liberation Sans";
pub struct MusicPlayerPanel {
panel: Panel,
display_font: Font,
}
impl BindPanel for MusicPlayerPanel {
fn bind(panel: Panel, message: Message) -> Box<dyn PanelImpl> {
let display_font = Font::new(DISPLAY_FONT);
let panel = Self {
panel,
display_font,
};
Box::new(panel)
}
}
impl PanelImpl for MusicPlayerPanel {
fn update(&mut self, dt: f32) {}
fn draw(&mut self) {
let layout = TextLayout::new(&self.display_font, "Hello world!");
let offset = Vec2 { x: 0.0, y: 0.0 };
let scale = 0.1;
let color = Color::WHITE;
self.panel.draw_text_layout(&layout, offset, scale, color);
}
fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) {}
fn on_message(&mut self, message: Message) {}
}