2023-05-21 16:45:12 +00:00
|
|
|
#![allow(non_snake_case)]
|
2023-06-13 16:02:32 +00:00
|
|
|
use wasm_bindgen::prelude::Closure;
|
2023-06-16 02:23:12 +00:00
|
|
|
use wasm_bindgen::JsCast;
|
2023-05-22 15:26:08 +00:00
|
|
|
use yew::prelude::*;
|
2023-05-24 15:20:12 +00:00
|
|
|
|
2024-02-12 00:46:43 +00:00
|
|
|
use plate_tool_lib::plate::PlateType;
|
|
|
|
use plate_tool_lib::plate_instances::PlateInstance;
|
2023-05-24 20:10:33 +00:00
|
|
|
|
2024-02-11 02:57:30 +00:00
|
|
|
// use super::destination_plate::DestinationPlate;
|
|
|
|
// use super::source_plate::SourcePlate;
|
|
|
|
use super::plate::Plate;
|
2023-05-21 16:45:12 +00:00
|
|
|
|
2023-05-22 15:26:08 +00:00
|
|
|
#[derive(Properties, PartialEq)]
|
|
|
|
pub struct PlateContainerProps {
|
2023-05-24 20:10:33 +00:00
|
|
|
pub source_dims: Option<PlateInstance>,
|
|
|
|
pub destination_dims: Option<PlateInstance>,
|
2023-05-22 15:26:08 +00:00
|
|
|
}
|
2023-05-21 16:45:12 +00:00
|
|
|
|
2023-05-22 15:26:08 +00:00
|
|
|
#[function_component]
|
|
|
|
pub fn PlateContainer(props: &PlateContainerProps) -> Html {
|
2023-06-16 02:23:12 +00:00
|
|
|
let cell_height = {
|
|
|
|
let height = web_sys::window()
|
|
|
|
.unwrap()
|
|
|
|
.inner_height()
|
|
|
|
.unwrap()
|
|
|
|
.as_f64()
|
|
|
|
.unwrap();
|
|
|
|
let width = web_sys::window()
|
|
|
|
.unwrap()
|
|
|
|
.inner_width()
|
|
|
|
.unwrap()
|
|
|
|
.as_f64()
|
|
|
|
.unwrap();
|
|
|
|
if let (Some(src_d), Some(dest_d)) = (&props.source_dims, &props.destination_dims) {
|
|
|
|
let h = (0.78 * height) / (src_d.plate.size().0 + dest_d.plate.size().0) as f64;
|
|
|
|
let w = (0.90 * width) / (src_d.plate.size().1 + dest_d.plate.size().1) as f64;
|
|
|
|
f64::min(w, h)
|
|
|
|
} else {
|
|
|
|
1f64
|
|
|
|
}
|
|
|
|
};
|
2023-06-13 16:02:32 +00:00
|
|
|
|
2023-06-16 02:23:12 +00:00
|
|
|
let resize_trigger = use_force_update();
|
|
|
|
let onresize = Closure::<dyn FnMut(_)>::new(move |_: Event| {
|
|
|
|
resize_trigger.force_update();
|
|
|
|
});
|
|
|
|
web_sys::window()
|
|
|
|
.unwrap()
|
|
|
|
.set_onresize(Some(onresize.as_ref().unchecked_ref()));
|
|
|
|
onresize.forget(); // Magic!
|
2023-06-13 16:02:32 +00:00
|
|
|
|
2023-05-22 15:26:08 +00:00
|
|
|
html! {
|
|
|
|
<div class="plate_container">
|
2023-05-24 20:10:33 +00:00
|
|
|
if let Some(spi) = props.source_dims.clone() {
|
2023-05-24 22:39:38 +00:00
|
|
|
if let Some(dpi) = props.destination_dims.clone() {
|
2023-06-13 16:02:32 +00:00
|
|
|
<div class="plate_container--source">
|
2023-05-24 20:10:33 +00:00
|
|
|
<h2>{spi.name.clone()}</h2>
|
2024-02-12 00:32:30 +00:00
|
|
|
<h2>{"Source"}</h2>
|
2024-02-11 02:57:30 +00:00
|
|
|
<Plate source_plate={spi.clone()} destination_plate={dpi.clone()}
|
|
|
|
cell_height={cell_height} ptype={PlateType::Source}/>
|
2023-05-24 20:10:33 +00:00
|
|
|
</div>
|
2023-06-13 16:02:32 +00:00
|
|
|
<div class="plate_container--destination">
|
2023-05-24 20:10:33 +00:00
|
|
|
<h2>{dpi.name.clone()}</h2>
|
2024-02-12 00:32:30 +00:00
|
|
|
<h2>{"Destination"}</h2>
|
2024-02-11 02:57:30 +00:00
|
|
|
<Plate source_plate={spi.clone()} destination_plate={dpi.clone()}
|
|
|
|
cell_height={cell_height} ptype={PlateType::Destination}/>
|
2023-05-24 20:10:33 +00:00
|
|
|
</div>
|
2023-05-24 15:42:54 +00:00
|
|
|
} else {
|
|
|
|
<h2>{"No Destination Plate Selected"}</h2>
|
|
|
|
}
|
2023-05-24 22:39:38 +00:00
|
|
|
} else {
|
|
|
|
<h2>{"No Source Plate Selected"}</h2>
|
|
|
|
}
|
2023-05-22 15:26:08 +00:00
|
|
|
</div>
|
|
|
|
}
|
2023-05-21 16:45:12 +00:00
|
|
|
}
|