Skip to content

Commit

Permalink
Fix plugin redraw on split-panel resize
Browse files Browse the repository at this point in the history
  • Loading branch information
texodus committed Mar 2, 2022
1 parent bbe51b0 commit 5e2e696
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ pub struct SplitPanelProps {
#[prop_or_default]
pub on_resize: Option<Callback<(i32, i32)>>,

#[prop_or_default]
pub on_resize_finished: Option<Callback<()>>,

#[cfg(test)]
#[prop_or_default]
pub weak_link: WeakScope<SplitPanel>,
Expand Down Expand Up @@ -273,6 +276,9 @@ impl Component for SplitPanel {
}
SplitPanelMsg::StopResizing => {
self.resize_state = None;
if let Some(cb) = &ctx.props().on_resize_finished {
cb.emit(());
}
}
SplitPanelMsg::MoveResizing(client_offset) => {
if let Some(state) = self.resize_state.as_ref() {
Expand Down
10 changes: 7 additions & 3 deletions rust/perspective-viewer/src/rust/components/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ use super::status_bar::StatusBar;

use crate::config::*;
use crate::dragdrop::*;
use crate::model::*;
use crate::renderer::*;
use crate::session::Session;
use crate::session::*;
use crate::utils::*;
use crate::*;

use futures::channel::oneshot::*;
use std::rc::Rc;
Expand All @@ -38,6 +40,8 @@ pub struct PerspectiveViewerProps {
pub weak_link: WeakScope<PerspectiveViewer>,
}

derive_session_renderer_model!(PerspectiveViewerProps);

impl PartialEq for PerspectiveViewerProps {
fn eq(&self, _rhs: &Self) -> bool {
false
Expand Down Expand Up @@ -179,14 +183,14 @@ impl Component for PerspectiveViewer {
// `JsPerspectiveConfig` - they may need caching as in the JavaScript version.
fn view(&self, ctx: &Context<Self>) -> Html {
let settings = ctx.link().callback(|_| Msg::ToggleSettingsInit(None, None));
let callback = self.on_dimensions_reset.callback();
if self.settings_open {
html! {
<>
<style>{ &CSS }</style>
<SplitPanel
id="app_panel"
on_reset={ callback }>
on_reset={ self.on_dimensions_reset.callback() }
on_resize_finished={ ctx.props().render_callback() }>
<div id="side_panel" class="column noselect">
<PluginSelector
session={ ctx.props().session.clone() }
Expand Down
14 changes: 14 additions & 0 deletions rust/perspective-viewer/src/rust/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::utils::*;
use std::future::Future;
use std::pin::Pin;
use wasm_bindgen::prelude::*;
use yew::prelude::*;

/// A `SessionRendererModel` is any struct with `session` and `renderer` fields, as
/// this method is boilerplate but has no other trait to live on currently. As
Expand All @@ -39,6 +40,19 @@ pub trait SessionRendererModel {
});
}

fn render_callback(&self) -> Callback<()> {
let session = self.session().clone();
let renderer = self.renderer().clone();
Callback::from(move |_| {
let session = session.clone();
let renderer = renderer.clone();
drop(promisify_ignore_view_delete(async move {
drop(renderer.draw(async { Ok(&session) }).await?);
Ok(JsValue::UNDEFINED)
}))
})
}

fn render(&self) {
let session = self.session().clone();
let renderer = self.renderer().clone();
Expand Down

0 comments on commit 5e2e696

Please sign in to comment.