diff --git a/src/components/waveform/canvas.rs b/src/components/waveform/canvas.rs index 8164564..96f0166 100644 --- a/src/components/waveform/canvas.rs +++ b/src/components/waveform/canvas.rs @@ -9,6 +9,7 @@ use yew::services::ConsoleService; use yew::Bridge; pub struct Canvas { + props: Props, _audio_agent: Box>, canvas_node: NodeRef, audio_data: Option>, @@ -21,12 +22,19 @@ pub enum Msg { AudioAgentMessage(Result, String>), } +#[derive(Properties, Clone, PartialEq, Debug)] +pub struct Props { + #[prop_or(1)] + pub zoom_factor: i32, +} + impl Component for Canvas { type Message = Msg; - type Properties = (); + type Properties = Props; - fn create(_: Self::Properties, link: ComponentLink) -> Self { + fn create(props: Self::Properties, link: ComponentLink) -> Self { Self { + props, _audio_agent: AudioAgent::bridge(link.callback(Msg::AudioAgentMessage)), canvas_node: NodeRef::default(), audio_data: None, @@ -37,7 +45,7 @@ impl Component for Canvas { fn rendered(&mut self, first_render: bool) { if first_render { let cb = Closure::wrap(Box::new(|| { - ConsoleService::log(&format!("In the callback")); + ConsoleService::log(&format!("In setInterval callback")); }) as Box); // TODO: request_animation_frame() ? @@ -62,7 +70,16 @@ impl Component for Canvas { false } - fn change(&mut self, _: Self::Properties) -> ShouldRender { + fn change(&mut self, props: Self::Properties) -> ShouldRender { + if self.props.zoom_factor != props.zoom_factor { + ConsoleService::log(&format!("Switch to Zoom factor: {:?}", props)); + self.props.zoom_factor = props.zoom_factor; + self.redraw_canvas(); + } + + if self.props != props { + self.props = props; + } false } diff --git a/src/components/waveform/container.rs b/src/components/waveform/container.rs index bb9991a..361166a 100644 --- a/src/components/waveform/container.rs +++ b/src/components/waveform/container.rs @@ -10,10 +10,12 @@ pub struct Container { link: ComponentLink, file_input: NodeRef, audio_agent: Dispatcher, + zoom_factor: i32, } pub enum Msg { SubmitForm, + ZoomButtonClicked(i32), } impl Component for Container { @@ -25,6 +27,7 @@ impl Component for Container { link, file_input: NodeRef::default(), audio_agent: AudioAgent::dispatcher(), + zoom_factor: 1, } } @@ -35,18 +38,21 @@ impl Component for Container { ConsoleService::error(&e); }; } + Msg::ZoomButtonClicked(factor) => { + self.zoom_factor = factor; + } }; true } fn change(&mut self, _: Self::Properties) -> ShouldRender { - false + true } fn view(&self) -> Html { html! {
- +
+ +
- +
+

{ "Zoom" }

+ + + + + + +
} } diff --git a/src/lib.rs b/src/lib.rs index e3cc1b7..3fb7d68 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![recursion_limit = "256"] +#![recursion_limit = "1024"] extern crate console_error_panic_hook; extern crate js_sys;