cleaning + fmt

This commit is contained in:
Martin Kavík 2024-10-08 18:54:21 +02:00
parent 1d20d3ac56
commit d7874e728b
6 changed files with 37 additions and 168 deletions

View file

@ -6,17 +6,14 @@ pub use excalidraw_canvas::ExcalidrawController;
#[derive(Clone)]
pub struct DiagramPanel {
canvas_controller: Mutable<Mutable<Option<SendWrapper<ExcalidrawController>>>>
canvas_controller: Mutable<Mutable<Option<SendWrapper<ExcalidrawController>>>>,
}
impl DiagramPanel {
pub fn new(
canvas_controller: Mutable<Mutable<Option<SendWrapper<ExcalidrawController>>>>,
) -> impl Element {
Self {
canvas_controller
}
.root()
Self { canvas_controller }.root()
}
fn root(&self) -> impl Element {
@ -26,7 +23,6 @@ impl DiagramPanel {
.s(Width::fill())
.s(Height::fill())
.s(Gap::new().y(20))
.item("Diagram panel")
.item(self.canvas())
}
@ -38,7 +34,6 @@ impl DiagramPanel {
.s(Height::fill())
.task_with_controller(move |controller| {
canvas_controller.set(controller.clone());
zoon::println!("hello from task_with_controller");
async {}
})
}

View file

@ -4,10 +4,6 @@ use zoon::*;
pub struct ExcalidrawCanvas {
raw_el: RawHtmlEl<web_sys::HtmlElement>,
controller: Mutable<Option<SendWrapper<js_bridge::ExcalidrawController>>>,
#[allow(dead_code)]
width: ReadOnlyMutable<u32>,
#[allow(dead_code)]
height: ReadOnlyMutable<u32>,
task_with_controller: Mutable<Option<TaskHandle>>,
}
@ -32,35 +28,13 @@ impl ExcalidrawCanvas {
pub fn new() -> Self {
let controller: Mutable<Option<SendWrapper<js_bridge::ExcalidrawController>>> =
Mutable::new(None);
let width = Mutable::new(0);
let height = Mutable::new(0);
let resize_task = Task::start_droppable(
map_ref! {
let width = width.signal(),
let height = height.signal() => (*width, *height)
}
.dedupe()
.throttle(|| Timer::sleep(50))
.for_each(
clone!((controller) move |(width, height)| clone!((controller) async move {
if let Some(controller) = controller.lock_ref().as_ref() {
controller.resize(width, height).await
}
})),
),
);
let task_with_controller = Mutable::new(None);
Self {
controller: controller.clone(),
width: width.read_only(),
height: height.read_only(),
task_with_controller: task_with_controller.clone(),
raw_el: El::new()
.s(RoundedCorners::all(10))
.s(Clip::both())
.on_viewport_size_change(clone!((width, height) move |new_width, new_height| {
width.set_neq(new_width);
height.set_neq(new_height);
}))
.after_insert(clone!((controller) move |element| {
Task::start(async move {
let excalidraw_controller = SendWrapper::new(js_bridge::ExcalidrawController::new());
@ -69,11 +43,7 @@ impl ExcalidrawCanvas {
});
}))
.after_remove(move |_| {
drop(resize_task);
drop(task_with_controller);
if let Some(controller) = controller.take() {
controller.destroy();
}
})
.into_raw_el(),
}
@ -103,16 +73,5 @@ mod js_bridge {
#[wasm_bindgen(method)]
pub async fn init(this: &ExcalidrawController, parent_element: &JsValue);
#[wasm_bindgen(method)]
pub async fn resize(this: &ExcalidrawController, width: u32, height: u32);
#[wasm_bindgen(method)]
pub fn destroy(this: &ExcalidrawController);
// -- FastWave-specific --
#[wasm_bindgen(method)]
pub fn hello(this: &ExcalidrawController);
}
}

View file

@ -2,8 +2,6 @@ use crate::{platform, theme::*, Filename, Layout, Mode};
use std::sync::Arc;
use zoon::*;
pub struct HeaderPanel {
hierarchy: Mutable<Option<Arc<wellen::Hierarchy>>>,
layout: Mutable<Layout>,
@ -38,7 +36,7 @@ impl HeaderPanel {
.s(Gap::both(15))
.item(self.load_button())
.item(self.layout_switcher())
.item(self.mode_switcher())
.item(self.mode_switcher()),
)
}

View file

@ -8,7 +8,7 @@ mod controls_panel;
use controls_panel::ControlsPanel;
mod diagram_panel;
use diagram_panel::{ExcalidrawController, DiagramPanel};
use diagram_panel::{DiagramPanel, ExcalidrawController};
mod waveform_panel;
use waveform_panel::{PixiController, WaveformPanel};