Format and a comment

This commit is contained in:
Emilia Allison 2023-05-11 17:51:09 -04:00
parent 14df69db59
commit 0c2bbbdb27
Signed by: emilia
GPG Key ID: 7A3F8997BFE894E0
3 changed files with 27 additions and 22 deletions

View File

@ -1,6 +1,6 @@
table, tr, td { table, tr, td {
box-sizing: border-box; box-sizing: border-box;
user-select: none; user-select: none; /* Prevents dragging issue */
} }
td.plate_cell { td.plate_cell {
width: 30px; width: 30px;

View File

@ -9,19 +9,19 @@ pub struct SourcePlateProps {
height: u8, height: u8,
} }
struct SelectionState { struct SelectionState {
m_start: Option<(u8,u8)>, m_start: Option<(u8, u8)>,
m_end: Option<(u8,u8)>, m_end: Option<(u8, u8)>,
m_stat: bool m_stat: bool,
} }
pub fn SourcePlate(cx: Scope<SourcePlateProps>) -> Element { pub fn SourcePlate(cx: Scope<SourcePlateProps>) -> Element {
use_shared_state_provider(cx, || SelectionState { use_shared_state_provider(cx, || SelectionState {
m_start: None, m_start: None,
m_end: None, m_end: None,
m_stat: false m_stat: false,
}); });
cx.render(rsx!{ cx.render(rsx! {
style { style {
vec![STYLE].into_iter().map(|s| rsx!{s}) // This is stupid vec![STYLE].into_iter().map(|s| rsx!{s}) // This is stupid
} }
@ -41,16 +41,19 @@ pub fn SourcePlate(cx: Scope<SourcePlateProps>) -> Element {
} }
#[inline_props] #[inline_props]
fn SourcePlateCell(cx: Scope<PlateCellProps>, i: u8, j: u8,) -> Element { fn SourcePlateCell(cx: Scope<PlateCellProps>, i: u8, j: u8) -> Element {
let selection_state = use_shared_state::<SelectionState>(cx).unwrap(); let selection_state = use_shared_state::<SelectionState>(cx).unwrap();
let selected = in_square(selection_state.read().m_start, let selected = in_square(
selection_state.read().m_end, (*i,*j)); selection_state.read().m_start,
selection_state.read().m_end,
(*i, *j),
);
let selected_class = match selected { let selected_class = match selected {
true => "current_select", true => "current_select",
false => "" false => "",
}; };
cx.render(rsx!{ cx.render(rsx! {
td { td {
class: "plate_cell {selected_class}", class: "plate_cell {selected_class}",
draggable: "false", draggable: "false",
@ -71,27 +74,29 @@ fn SourcePlateCell(cx: Scope<PlateCellProps>, i: u8, j: u8,) -> Element {
}) })
} }
fn in_square(corner1: Option<(u8,u8)>, corner2: Option<(u8,u8)>, pt: (u8,u8)) -> bool { fn in_square(corner1: Option<(u8, u8)>, corner2: Option<(u8, u8)>, pt: (u8, u8)) -> bool {
if let (Some(c1), Some(c2)) = (corner1, corner2) { if let (Some(c1), Some(c2)) = (corner1, corner2) {
return pt.0 <= u8::max(c1.0,c2.0) && return pt.0 <= u8::max(c1.0, c2.0)
pt.0 >= u8::min(c1.0,c2.0) && && pt.0 >= u8::min(c1.0, c2.0)
pt.1 <= u8::max(c1.1,c2.1) && && pt.1 <= u8::max(c1.1, c2.1)
pt.1 >= u8::min(c1.1,c2.1) && pt.1 >= u8::min(c1.1, c2.1);
} else { return false } } else {
return false;
}
} }
fn PlateSelectionIndicator(cx: Scope) -> Element { fn PlateSelectionIndicator(cx: Scope) -> Element {
let selection_state = use_shared_state::<SelectionState>(cx).unwrap(); let selection_state = use_shared_state::<SelectionState>(cx).unwrap();
let start_str = match selection_state.read().m_start { let start_str = match selection_state.read().m_start {
Some(start) => format!("{},{}", start.0, start.1), Some(start) => format!("{},{}", start.0, start.1),
None => "None".to_string() None => "None".to_string(),
}; };
let end_str = match selection_state.read().m_end{ let end_str = match selection_state.read().m_end {
Some(end) => format!("{},{}", end.0, end.1), Some(end) => format!("{},{}", end.0, end.1),
None => "None".to_string() None => "None".to_string(),
}; };
cx.render(rsx!{ cx.render(rsx! {
p { start_str ", and " end_str } p { start_str ", and " end_str }
}) })
} }

View File

@ -1,8 +1,8 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
mod components; mod components;
use dioxus::prelude::*;
use components::source_plate::SourcePlate; use components::source_plate::SourcePlate;
use dioxus::prelude::*;
pub fn App(cx: Scope) -> Element { pub fn App(cx: Scope) -> Element {
cx.render(rsx! { cx.render(rsx! {