From 9275a866d0c2343d82de1f589369223067cdce3a Mon Sep 17 00:00:00 2001 From: Emilia Date: Tue, 13 Jun 2023 12:02:32 -0400 Subject: [PATCH] Dynamic sizing of plate cells Calculates available size and allocates --- src/components/plates/destination_plate.rs | 4 ++++ src/components/plates/plate_container.rs | 28 ++++++++++++++++++---- src/components/plates/source_plate.rs | 4 ++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/components/plates/destination_plate.rs b/src/components/plates/destination_plate.rs index 3328a83..888a36e 100644 --- a/src/components/plates/destination_plate.rs +++ b/src/components/plates/destination_plate.rs @@ -18,6 +18,7 @@ use super::super::transfer_menu::{num_to_letters, RegionDisplay}; pub struct DestinationPlateProps { pub source_plate: PlateInstance, pub destination_plate: PlateInstance, + pub cell_height: f64, } #[function_component] @@ -112,6 +113,7 @@ pub fn DestinationPlate(props: &DestinationPlateProps) -> Html { mouse={mouse_callback.clone()} in_transfer={destination_wells.contains(&(i,j))} color={color_map.get(&(i,j)).copied()} + cell_height={props.cell_height} /> } }).collect::(); @@ -152,6 +154,7 @@ pub struct DestPlateCellProps { pub mouse: Callback<(u8, u8, MouseEventType)>, pub in_transfer: Option, color: Option, + cell_height: f64, } #[function_component] @@ -174,6 +177,7 @@ fn DestPlateCell(props: &DestPlateCellProps) -> Html { html! { Html { + let height = web_sys::window().unwrap().inner_height().unwrap().as_f64().unwrap(); + let cell_height = { + if let (Some(src_d), Some(dest_d)) = (&props.source_dims, &props.destination_dims) { + (0.78*height)/(src_d.plate.size().0 + dest_d.plate.size().0) as f64 + } else { + 1f64 + } + }; + + let resize_trigger = use_force_update(); + let onresize = Closure::::new(move |_: Event| { + resize_trigger.force_update(); + }); + web_sys::window().unwrap().set_onresize(Some(onresize.as_ref().unchecked_ref())); + onresize.forget(); // Magic! + html! {
if let Some(spi) = props.source_dims.clone() { if let Some(dpi) = props.destination_dims.clone() { -
+

{spi.name.clone()}

- +
-
+

{dpi.name.clone()}

- +
} else {

{"No Destination Plate Selected"}

diff --git a/src/components/plates/source_plate.rs b/src/components/plates/source_plate.rs index 12cddaf..6a5cbb9 100644 --- a/src/components/plates/source_plate.rs +++ b/src/components/plates/source_plate.rs @@ -18,6 +18,7 @@ use super::super::transfer_menu::{num_to_letters, RegionDisplay}; pub struct SourcePlateProps { pub source_plate: PlateInstance, pub destination_plate: PlateInstance, + pub cell_height: f64, } #[function_component] @@ -114,6 +115,7 @@ pub fn SourcePlate(props: &SourcePlateProps) -> Html { mouse={mouse_callback.clone()} in_transfer={source_wells.contains(&(i,j))} color={color_map.get(&(i,j)).copied()} + cell_height={props.cell_height} /> } }) @@ -150,6 +152,7 @@ pub struct SourcePlateCellProps { mouse: Callback<(u8, u8, MouseEventType)>, in_transfer: Option, color: Option, + cell_height: f64, } #[derive(Debug)] pub enum MouseEventType { @@ -177,6 +180,7 @@ fn SourcePlateCell(props: &SourcePlateCellProps) -> Html { html! {