about summary refs log tree commit diff
path: root/src/types
diff options
context:
space:
mode:
Diffstat (limited to 'src/types')
-rw-r--r--src/types/menu.rs31
-rw-r--r--src/types/mod.rs11
2 files changed, 42 insertions, 0 deletions
diff --git a/src/types/menu.rs b/src/types/menu.rs
new file mode 100644
index 000000000000..63abc837788e
--- /dev/null
+++ b/src/types/menu.rs
@@ -0,0 +1,31 @@
+use crate::types::Dimensions;
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct MenuInfo {
+    pub prompt: String,
+    pub options: Vec<String>,
+}
+
+impl MenuInfo {
+    pub fn new(prompt: String, options: Vec<String>) -> Self {
+        MenuInfo { prompt, options }
+    }
+
+    /// Returns the inner dimensions of a box necessary to draw this menu. Will
+    /// not trim either dimension to the size of the terminal
+    pub fn dimensions(&self) -> Dimensions {
+        Dimensions {
+            w: self
+                .options
+                .iter()
+                .map(|s| s.len())
+                .max()
+                .unwrap_or(0)
+                .max(self.prompt.len()) as u16
+                + 4,
+            h: self.options.len() as u16
+                + if self.prompt.is_empty() { 0 } else { 2 }
+                + 4,
+        }
+    }
+}
diff --git a/src/types/mod.rs b/src/types/mod.rs
index 31d2ecd29770..d417e873d8ca 100644
--- a/src/types/mod.rs
+++ b/src/types/mod.rs
@@ -5,10 +5,13 @@ use std::cmp::max;
 use std::cmp::Ordering;
 use std::ops;
 use std::rc::Rc;
+
 pub mod collision;
 pub mod command;
 pub mod direction;
 pub mod entity_map;
+pub mod menu;
+
 pub use collision::Collision;
 pub use direction::Direction;
 pub use direction::Direction::*;
@@ -78,6 +81,14 @@ impl BoundingBox {
             })
     }
 
+    pub fn ll_corner(self) -> Position {
+        self.position
+            + (Position {
+                x: 0,
+                y: self.dimensions.h as i16,
+            })
+    }
+
     /// Returns a bounding box representing the *inside* of this box if it was
     /// drawn on the screen.
     pub fn inner(self) -> BoundingBox {