initial commit
This commit is contained in:
parent
24babbe695
commit
d8ce20bd7e
2
.gitignore
vendored
2
.gitignore
vendored
@ -8,3 +8,5 @@ Cargo.lock
|
|||||||
|
|
||||||
# These are backup files generated by rustfmt
|
# These are backup files generated by rustfmt
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|
||||||
|
.idea/
|
||||||
|
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
@ -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
|
12
native-ui-rs.iml
Normal file
12
native-ui-rs.iml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="RUST_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
55
src/abstracts/application.rs
Normal file
55
src/abstracts/application.rs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
use crate::abstracts::Window;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Application {
|
||||||
|
pub title: String,
|
||||||
|
pub main_windows: Vec<Window>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Application {
|
||||||
|
pub fn builder() -> ApplicationBuilder {
|
||||||
|
ApplicationBuilder::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ApplicationBuilder {
|
||||||
|
title: String,
|
||||||
|
main_windows: Vec<Window>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
18
src/abstracts/mod.rs
Normal file
18
src/abstracts/mod.rs
Normal file
@ -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<Window>)
|
||||||
|
}
|
80
src/abstracts/window.rs
Normal file
80
src/abstracts/window.rs
Normal file
@ -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<Widget>,
|
||||||
|
pub title_default: bool
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Window {
|
||||||
|
pub fn builder() -> WindowBuilder {
|
||||||
|
WindowBuilder::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct WindowBuilder {
|
||||||
|
title: String,
|
||||||
|
width: usize,
|
||||||
|
height: usize,
|
||||||
|
content: Option<Widget>,
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
17
src/lib.rs
Normal file
17
src/lib.rs
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user