aboutsummaryrefslogtreecommitdiffstats
path: root/src/types.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/types.rs')
-rw-r--r--src/types.rs50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/types.rs b/src/types.rs
index b1ed2fb..5614ab7 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -14,6 +14,37 @@ pub enum ScalarType {
Bool,
}
+impl ScalarType {
+ const SCALARS: [Self; 5] = [
+ ScalarType::Float(FloatPrecision::Single),
+ ScalarType::Float(FloatPrecision::Double),
+ ScalarType::Int,
+ ScalarType::UInt,
+ ScalarType::Bool,
+ ];
+
+ pub fn pick(ui: &mut egui::Ui) -> Option<Self> {
+ for value in Self::SCALARS {
+ if ui.button(format!("{}", value)).clicked() {
+ return Some(value);
+ }
+ }
+
+ None
+ }
+}
+impl fmt::Display for ScalarType {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ ScalarType::Float(FloatPrecision::Single) => write!(f, "float"),
+ ScalarType::Float(FloatPrecision::Double) => write!(f, "double"),
+ ScalarType::Int => write!(f, "int"),
+ ScalarType::UInt => write!(f, "uint"),
+ ScalarType::Bool => write!(f, "bool"),
+ }
+ }
+}
+
#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
#[repr(u8)]
pub enum Dimension {
@@ -23,7 +54,7 @@ pub enum Dimension {
}
impl fmt::Display for Dimension {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "{}", *self as u8)
+ write!(f, "{:?}", *self as u8)
}
}
impl Dimension {
@@ -59,6 +90,23 @@ impl Type {
Type::Matrix(p, _, _) => ScalarType::Float(*p),
}
}
+
+ pub fn pick(ui: &mut egui::Ui) -> Option<Self> {
+ let mut result: Option<Self> = ScalarType::pick(ui).map(Self::Scalar);
+
+ ui.separator();
+
+ for dim in [Dimension::D2, Dimension::D3, Dimension::D4] {
+ result = result.or(ui
+ .menu_button(format!("Vector {dim}"), |ui| {
+ ScalarType::pick(ui).map(|s| Self::Vector(s, dim))
+ })
+ .inner
+ .flatten());
+ }
+
+ result
+ }
}
impl fmt::Display for Type {