From d8ce20bd7edf5d0595e45890764c0bf9ac175a31 Mon Sep 17 00:00:00 2001 From: Surferlul Date: Fri, 29 Jul 2022 06:13:44 +0200 Subject: [PATCH] initial commit --- .gitignore | 2 + Cargo.toml | 6 +++ native-ui-rs.iml | 12 ++++++ src/abstracts/application.rs | 55 +++++++++++++++++++++++++ src/abstracts/mod.rs | 18 ++++++++ src/abstracts/window.rs | 80 ++++++++++++++++++++++++++++++++++++ src/lib.rs | 17 ++++++++ 7 files changed, 190 insertions(+) create mode 100644 Cargo.toml create mode 100644 native-ui-rs.iml create mode 100644 src/abstracts/application.rs create mode 100644 src/abstracts/mod.rs create mode 100644 src/abstracts/window.rs create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore index 088ba6b..cbed4d7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk + +.idea/ diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..a746b80 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "native-ui-rs" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html \ No newline at end of file diff --git a/native-ui-rs.iml b/native-ui-rs.iml new file mode 100644 index 0000000..2fecef3 --- /dev/null +++ b/native-ui-rs.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/abstracts/application.rs b/src/abstracts/application.rs new file mode 100644 index 0000000..b3119e6 --- /dev/null +++ b/src/abstracts/application.rs @@ -0,0 +1,55 @@ +use crate::abstracts::Window; + +#[derive(Clone)] +pub struct Application { + pub title: String, + pub main_windows: Vec, +} + +impl Application { + pub fn builder() -> ApplicationBuilder { + ApplicationBuilder::default() + } +} + +pub struct ApplicationBuilder { + title: String, + main_windows: Vec, +} + +impl ApplicationBuilder { + pub fn new() -> ApplicationBuilder { + ApplicationBuilder { + title: String::from("My App"), + main_windows: Vec::new(), + } + } + + pub fn title(mut self, title: &str) -> ApplicationBuilder { + self.title = String::from(title); + self + } + + pub fn add_window(mut self, window: Window) -> ApplicationBuilder { + self.main_windows.push(window); + self + } + + pub fn build(mut self) -> Application { + for window in &mut self.main_windows { + if window.title_default { + window.title = self.title.clone(); + } + } + Application { + title: self.title, + main_windows: self.main_windows + } + } +} + +impl Default for ApplicationBuilder { + fn default() -> Self { + Self::new() + } +} diff --git a/src/abstracts/mod.rs b/src/abstracts/mod.rs new file mode 100644 index 0000000..5fb4307 --- /dev/null +++ b/src/abstracts/mod.rs @@ -0,0 +1,18 @@ +mod application; +mod window; + +pub use crate::abstracts::{ + application::{ + Application, + ApplicationBuilder + }, + window::{ + Window, + WindowBuilder + }, +}; + +#[derive(Clone,Debug)] +pub enum Widget { + Window(Box) +} \ No newline at end of file diff --git a/src/abstracts/window.rs b/src/abstracts/window.rs new file mode 100644 index 0000000..123566d --- /dev/null +++ b/src/abstracts/window.rs @@ -0,0 +1,80 @@ +use crate::abstracts::Widget; + +#[derive(Clone, Debug)] +pub struct Window { + pub title: String, + pub width: usize, + pub height: usize, + pub content: Option, + pub title_default: bool +} + +impl Window { + pub fn builder() -> WindowBuilder { + WindowBuilder::default() + } +} + +pub struct WindowBuilder { + title: String, + width: usize, + height: usize, + content: Option, + title_default: bool, +} + +impl WindowBuilder { + pub fn new() -> WindowBuilder { + WindowBuilder { + title: String::from("My Window"), + width: 250, + height: 250, + content: None, + title_default: true, + } + } + + pub fn title(mut self, title: &str) -> WindowBuilder { + self.title = String::from(title); + self.title_default = false; + self + } + + + pub fn width(mut self, width: usize) -> WindowBuilder { + self.width = width; + self + } + + pub fn height(mut self, height: usize) -> WindowBuilder { + self.height = height; + self + } + + pub fn dimensions(mut self, width: usize, height: usize) -> WindowBuilder { + self.width = width; + self.height = height; + self + } + + pub fn content(mut self, widget: Widget) -> WindowBuilder { + self.content = Some(widget); + self + } + + pub fn build(self) -> Window { + Window { + title: self.title, + width: self.width, + height: self.height, + content: self.content, + title_default: self.title_default, + } + } +} + +impl Default for WindowBuilder { + fn default() -> Self { + Self::new() + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..9ce03c7 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,17 @@ +pub mod abstracts; + +pub fn add(left: usize, right: usize) -> usize { + left + right +} + + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +}