summaryrefslogtreecommitdiffstats
path: root/src/oop
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/oop/Cargo.toml6
-rw-r--r--src/oop/src/lib.rs27
-rw-r--r--src/oop/src/main.rs40
3 files changed, 73 insertions, 0 deletions
diff --git a/src/oop/Cargo.toml b/src/oop/Cargo.toml
new file mode 100644
index 0000000..40f6a81
--- /dev/null
+++ b/src/oop/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "oop"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/src/oop/src/lib.rs b/src/oop/src/lib.rs
new file mode 100644
index 0000000..1f260c0
--- /dev/null
+++ b/src/oop/src/lib.rs
@@ -0,0 +1,27 @@
+pub trait Draw {
+ fn draw(&self);
+}
+
+pub struct Screen {
+ pub components: Vec<Box<dyn Draw>>,
+}
+
+impl Screen {
+ pub fn run(&self) {
+ for component in self.components.iter() {
+ component.draw();
+ }
+ }
+}
+
+pub struct Button {
+ pub width: u32,
+ pub height: u32,
+ pub label: String,
+}
+
+impl Draw for Button {
+ fn draw(&self) {
+ // some code
+ }
+}
diff --git a/src/oop/src/main.rs b/src/oop/src/main.rs
new file mode 100644
index 0000000..5bd600e
--- /dev/null
+++ b/src/oop/src/main.rs
@@ -0,0 +1,40 @@
+use oop::{
+ Button,
+ Screen,
+ Draw,
+};
+
+struct SelectBox {
+ width: u32,
+ height: u32,
+ options: Vec<String>,
+}
+
+impl Draw for SelectBox {
+ fn draw(&self) {
+ // some code
+ }
+}
+
+fn main() {
+ let screen = Screen {
+ components: vec![
+ Box::new(SelectBox {
+ width: 75,
+ height: 10,
+ options: vec![
+ String::from("Yes"),
+ String::from("Maybe"),
+ String::from("No"),
+ ],
+ }),
+ Box::new(Button {
+ width: 50,
+ height: 10,
+ label: String::from("Ok"),
+ }),
+ ],
+ };
+
+ screen.run();
+}