tree_table/types/
selection.rs1use crate::Span;
2use crate::statics::CELLS;
3use crate::statics::COLS;
4use crate::statics::ROWS;
5use crate::str_err;
6use alloc::string::String;
7use alloc::vec::Vec;
8
9#[cfg_attr(feature = "tsify", derive(tsify::Tsify))]
10#[cfg_attr(feature = "tsify", tsify(from_wasm_abi))]
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12#[derive(Debug, Clone, Copy, PartialEq)]
13pub enum SelectionKind {
15 Rows,
16 Cols,
17 Cells,
18}
19
20impl SelectionKind {
21 pub fn as_str(&self) -> &'static str {
23 match self {
24 SelectionKind::Rows => ROWS,
25 SelectionKind::Cols => COLS,
26 SelectionKind::Cells => CELLS,
27 }
28 }
29
30 pub fn from_str(s: &str) -> Option<Self> {
32 match s {
33 "rows" => Some(SelectionKind::Rows),
34 "cols" => Some(SelectionKind::Cols),
35 "cells" => Some(SelectionKind::Cells),
36 _ => None,
37 }
38 }
39
40 pub fn from_str_res(s: &str) -> Result<Self, String> {
42 Self::from_str(s).ok_or_else(|| str_err!("Cannot convert: {} to SelectionKind", s))
43 }
44}
45
46#[cfg_attr(feature = "tsify", derive(tsify::Tsify))]
47#[cfg_attr(feature = "tsify", tsify(from_wasm_abi))]
48#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
49#[derive(Debug, PartialEq, Clone)]
50pub enum SelectionState {
52 Normal,
53 Hidden,
54}
55
56impl SelectionState {
57 pub fn as_str(&self) -> &'static str {
59 match self {
60 SelectionState::Normal => "normal",
61 SelectionState::Hidden => "hidden",
62 }
63 }
64
65 pub fn from_str(s: &str) -> Option<Self> {
67 match s {
68 "normal" => Some(SelectionState::Normal),
69 "hidden" => Some(SelectionState::Hidden),
70 _ => None,
71 }
72 }
73
74 pub fn from_str_res(s: &str) -> Result<Self, String> {
76 Self::from_str(s).ok_or_else(|| str_err!("Cannot convert: {} to SelectionState", s))
77 }
78}
79
80#[cfg_attr(feature = "tsify", derive(tsify::Tsify))]
81#[cfg_attr(feature = "tsify", tsify(from_wasm_abi))]
82#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
83#[derive(Debug, Clone, Copy, PartialEq)]
84pub struct Selected {
85 pub row: usize,
86 pub col: usize,
87 pub coords: Span,
88}
89
90#[cfg_attr(feature = "tsify", derive(tsify::Tsify))]
91#[cfg_attr(feature = "tsify", tsify(from_wasm_abi))]
92#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
93#[derive(Debug, Clone, PartialEq)]
94pub struct Selection {
95 pub selection_boxes: Vec<Span>,
96 pub selected: Option<Selected>,
97}
98
99impl Selection {
100 pub fn new() -> Self {
101 Selection {
102 selection_boxes: Vec::new(),
103 selected: None,
104 }
105 }
106}