-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
188 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use yew::{html, prelude::Html, Component, Context}; | ||
|
||
#[derive(Default)] | ||
pub struct Dummy {} | ||
|
||
impl Component for Dummy { | ||
type Message = (); | ||
type Properties = (); | ||
|
||
fn create(_ctx: &Context<Self>) -> Self { | ||
Default::default() | ||
} | ||
|
||
fn update(&mut self, _ctx: &Context<Self>, _msg: Self::Message) -> bool { | ||
false | ||
} | ||
|
||
fn view(&self, _ctx: &Context<Self>) -> Html { | ||
html!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use log::error; | ||
use yew::{html, prelude::Html, Callback, Component, Context}; | ||
|
||
use crate::api; | ||
|
||
#[derive(Default)] | ||
pub struct Visualizer {} | ||
|
||
pub enum Msg { | ||
PointsLoaded(Vec<(f32, f32, f32)>), | ||
} | ||
|
||
fn get_api(ctx: &Context<Visualizer>) -> api::Gateway { | ||
ctx.link() | ||
.context::<api::Gateway>(Callback::noop()) | ||
.expect("gateway to be created") | ||
.0 | ||
} | ||
|
||
impl Component for Visualizer { | ||
type Message = Msg; | ||
type Properties = (); | ||
|
||
fn create(_ctx: &Context<Self>) -> Self { | ||
Default::default() | ||
} | ||
|
||
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool { | ||
match msg { | ||
Msg::PointsLoaded(points) => { | ||
let api = get_api(ctx); | ||
wasm_bindgen_futures::spawn_local(async move { | ||
rustmas_visualizer::run(api.frames(), points); | ||
}); | ||
false | ||
} | ||
} | ||
} | ||
|
||
fn rendered(&mut self, ctx: &Context<Self>, first_render: bool) { | ||
if first_render { | ||
let api = get_api(ctx); | ||
let points_loaded = ctx.link().callback(Msg::PointsLoaded); | ||
wasm_bindgen_futures::spawn_local(async move { | ||
match api.get_points().await { | ||
Ok(points) => points_loaded.emit(points), | ||
Err(e) => error!("Failed to load points for visualizer, reason: {}", e), | ||
} | ||
}) | ||
} | ||
} | ||
|
||
fn view(&self, _ctx: &Context<Self>) -> Html { | ||
html! { | ||
<section class="visualizer-container"> | ||
<canvas id="visualizer"></canvas> | ||
</section> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters