Refactor script crate to use bind_panel function w/ protocol name instead of trait
This commit is contained in:
parent
4e9b01810a
commit
f8f59cb265
|
@ -7,11 +7,17 @@ use super::*;
|
|||
|
||||
static mut PANEL_IMPLS: Vec<Box<dyn PanelImpl>> = Vec::new();
|
||||
|
||||
pub fn bind_panel<T: BindPanel>(panel: u32, msg: u32) -> u32 {
|
||||
pub fn bind_panel(
|
||||
cb: impl Fn(Panel, Message, Message) -> Box<dyn PanelImpl>,
|
||||
panel: u32,
|
||||
protocol: u32,
|
||||
msg: u32,
|
||||
) -> u32 {
|
||||
unsafe {
|
||||
let panel = Panel(panel);
|
||||
let protocol = Message(protocol);
|
||||
let msg = Message(msg);
|
||||
let panel_impl = T::bind(panel, msg);
|
||||
let panel_impl = cb(panel, protocol, msg);
|
||||
let id = PANEL_IMPLS.len() as u32;
|
||||
PANEL_IMPLS.push(panel_impl);
|
||||
id
|
||||
|
|
|
@ -9,10 +9,10 @@ pub mod abi;
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! export_abi {
|
||||
($panel_impl: ident) => {
|
||||
($bind_panel: ident) => {
|
||||
#[no_mangle]
|
||||
pub extern "C" fn bind_panel(panel: u32, msg: u32) -> u32 {
|
||||
::canary_script::api::abi::bind_panel::<$panel_impl>(panel, msg)
|
||||
pub extern "C" fn bind_panel(panel: u32, protocol: u32, msg: u32) -> u32 {
|
||||
::canary_script::api::abi::bind_panel($bind_panel, panel, protocol, msg)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -42,10 +42,6 @@ macro_rules! export_abi {
|
|||
};
|
||||
}
|
||||
|
||||
pub trait BindPanel {
|
||||
fn bind(panel: Panel, msg: Message) -> Box<dyn PanelImpl>;
|
||||
}
|
||||
|
||||
pub trait PanelImpl {
|
||||
fn update(&mut self, dt: f32);
|
||||
fn draw(&mut self);
|
||||
|
@ -375,7 +371,6 @@ impl DrawContext {
|
|||
self.draw_rect(bottom_edge, color);
|
||||
}
|
||||
|
||||
|
||||
self.draw_rect(inner_rect, color);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue