Commit 66cc7907 authored by Florian Blasius's avatar Florian Blasius 🤘

Move tree to subcrate.

Move structs tests to files.
parent 197c4999
......@@ -406,7 +406,7 @@ dependencies = [
[[package]]
name = "orbclient"
version = "0.3.21"
version = "0.3.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -418,7 +418,7 @@ name = "orbfont"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"orbclient 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)",
"orbclient 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
"rusttype 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -428,7 +428,7 @@ version = "0.1.9"
source = "git+https://gitlab.redox-os.org/redox-os/orbfont.git#9e624358518925e75bc5af94a2369e981379002a"
dependencies = [
"font-loader 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"orbclient 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)",
"orbclient 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
"rusttype 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -437,7 +437,7 @@ name = "orbgl"
version = "0.1.0"
source = "git+https://gitlab.redox-os.org/redox-os/orbgl.git#715fc579acf3cc2b449bf54f5cf3e4667bd82a93"
dependencies = [
"orbclient 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)",
"orbclient 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
"orbgl_api 0.1.0 (git+https://gitlab.redox-os.org/redox-os/orbgl.git)",
"rust-cairo 0.1.0 (git+https://gitlab.redox-os.org/redox-os/rust-cairo.git)",
"stdweb 0.4.16 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -448,7 +448,7 @@ name = "orbgl_api"
version = "0.1.0"
source = "git+https://gitlab.redox-os.org/redox-os/orbgl.git#715fc579acf3cc2b449bf54f5cf3e4667bd82a93"
dependencies = [
"orbclient 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)",
"orbclient 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
"orbfont 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"orbimage 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"stdweb 0.4.16 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -460,7 +460,7 @@ version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"orbclient 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)",
"orbclient 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
"resize 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -470,14 +470,14 @@ version = "0.3.0"
dependencies = [
"dces 0.1.6 (git+https://gitlab.redox-os.org/redox-os/dces-rust.git)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"orbclient 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)",
"orbclient 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
"orbfont 0.1.9 (git+https://gitlab.redox-os.org/redox-os/orbfont.git)",
"orbgl 0.1.0 (git+https://gitlab.redox-os.org/redox-os/orbgl.git)",
"orbgl_api 0.1.0 (git+https://gitlab.redox-os.org/redox-os/orbgl.git)",
"orbimage 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"orbtk-css-engine 0.1.0",
"orbtk-structs 0.1.0",
"orbtk-web-window 0.1.0",
"orbtk-tree 0.1.0",
]
[[package]]
......@@ -496,11 +496,10 @@ dependencies = [
]
[[package]]
name = "orbtk-web-window"
name = "orbtk-tree"
version = "0.1.0"
dependencies = [
"orbtk-structs 0.1.0",
"stdweb 0.4.16 (registry+https://github.com/rust-lang/crates.io-index)",
"dces 0.1.6 (git+https://gitlab.redox-os.org/redox-os/dces-rust.git)",
]
[[package]]
......@@ -1139,7 +1138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e96f040177bb3da242b5b1ecf3f54b5d5af3efbbfb18608977a5d2767b22f10"
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
"checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba"
"checksum orbclient 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)" = "3fc3cb6a2e27e7635ffb7333ce0d32f1bb4f1735979ce6dacc647b1122c86e53"
"checksum orbclient 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "1d0e398a001ca5f52b252d1cf5679d52ddd347d3130ac9ded98549f16537c546"
"checksum orbfont 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "da4dfbc851e5c24c3cf1e16ec5222f868f3362d2b7493d0b53051fe2669267a2"
"checksum orbfont 0.1.9 (git+https://gitlab.redox-os.org/redox-os/orbfont.git)" = "<none>"
"checksum orbgl 0.1.0 (git+https://gitlab.redox-os.org/redox-os/orbgl.git)" = "<none>"
......
......@@ -21,18 +21,16 @@ edition = "2018"
name = "orbtk"
path = "src/lib.rs"
[target.wasm32-unknown-unknown.dependencies]
orbtk-web-window = { version = "0.1.0", path = "crates/web-window" }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
orbgl = { git = "https://gitlab.redox-os.org/redox-os/orbgl.git" }
orbfont = { git = "https://gitlab.redox-os.org/redox-os/orbfont.git" }
orbimage = "0.1.17"
orbclient = "0.3.21"
orbclient = "0.3.22"
[dependencies]
orbtk-structs = { version = "0.1.0", path = "crates/structs" }
orbtk-css-engine = { version = "0.1.0", path = "crates/css-engine" }
orbtk-tree = { version = "0.1.0", path="crates/tree" }
lazy_static = "1.3.0"
# dces = { path = "../dces-rust"}
dces = { git = "https://gitlab.redox-os.org/redox-os/dces-rust.git" }
......@@ -44,5 +42,5 @@ orbgl_api = { git = "https://gitlab.redox-os.org/redox-os/orbgl.git" }
members = [
"crates/css-engine",
"crates/structs",
"crates/web-window"
"crates/tree"
]
\ No newline at end of file
......@@ -113,3 +113,66 @@ pub trait Bordered {
/// Sets the complete border.
fn set_border(&mut self, border: Border);
}
#[cfg(test)]
mod tests {
use crate::prelude::*;
#[test]
fn test_brush() {
let brush = Brush::from("#000000");
let builder = BorderBuilder::new();
let border = builder.brush(brush).build();
let test_brush = Brush::from("#000000");
assert_eq!(border.brush(), &test_brush);
}
#[test]
fn test_thickness() {
let thickness = Thickness::new(0.0, 0.0, 0.0, 0.0);
let builder = BorderBuilder::new();
let border = builder.thickness(thickness).build();
assert_eq!(border.thickness(), thickness);
}
#[test]
fn test_radius() {
let radius = 0.0;
let builder = BorderBuilder::new();
let border = builder.radius(radius).build();
assert_eq!(border.radius(), radius);
}
#[test]
fn test_set_brush() {
let brush = Brush::from("#000000");
let mut border = Border::default();
border.set_brush(brush);
let test_brush = Brush::from("#000000");
assert_eq!(border.brush(), &test_brush);
}
#[test]
fn test_set_thickness() {
let thickness = Thickness::new(0.0, 0.0, 0.0, 0.0);
let mut border = Border::default();
border.set_thickness(thickness);
assert_eq!(border.thickness(), thickness);
}
#[test]
fn test_set_radius() {
let radius = 0.0;
let mut border = Border::default();
border.set_radius(radius);
assert_eq!(border.radius(), radius);
}
}
\ No newline at end of file
......@@ -69,3 +69,9 @@ fn get_color(hex: &str) -> Color {
_ => Color { data: 0 },
}
}
#[cfg(test)]
mod tests {
// use crate::prelude::*;
// todo: tbd after brush struct is finished
}
\ No newline at end of file
......@@ -73,3 +73,52 @@ impl Size for DirtySize {
self.height = height;
}
}
#[cfg(test)]
mod tests {
use crate::prelude::*;
#[test]
fn test_set_width() {
let width = 10.0;
let mut dirty_size = DirtySize::default();
dirty_size.set_width(width);
assert_eq!(dirty_size.width(), width);
assert!(dirty_size.dirty());
}
#[test]
fn test_set_height() {
let height = 10.0;
let mut dirty_size = DirtySize::default();
dirty_size.set_height(height);
assert_eq!(dirty_size.height(), height);
assert!(dirty_size.dirty());
}
#[test]
fn test_set_size() {
let size = (10.0, 20.0);
let mut dirty_size = DirtySize::default();
dirty_size.set_size(size.0, size.1);
assert_eq!(dirty_size.size(), size);
assert!(dirty_size.dirty());
}
#[test]
fn test_set_dirty() {
let mut dirty_size = DirtySize::default();
dirty_size.set_dirty(false);
assert!(!dirty_size.dirty());
}
}
\ No newline at end of file
......@@ -14,7 +14,4 @@ mod point;
pub mod prelude;
mod rect;
mod spacer;
mod thickness;
#[cfg(test)]
mod tests;
\ No newline at end of file
mod thickness;
\ No newline at end of file
......@@ -9,6 +9,4 @@ impl Point {
pub fn new(x: f64, y: f64) -> Self {
Point { x, y }
}
}
// property!(Point, PointProperty, point, shared_point);
\ No newline at end of file
}
\ No newline at end of file
......@@ -67,3 +67,18 @@ pub trait Size {
/// Sets the size with width and height.
fn set_size(&mut self, width: f64, height: f64);
}
#[cfg(test)]
mod tests {
use crate::prelude::*;
#[test]
fn test_new() {
let rect = Rect::new(5.0, 10.0, 20.0, 30.0);
assert_eq!(rect.x, 5.0);
assert_eq!(rect.y, 10.0);
assert_eq!(rect.width, 20.0);
assert_eq!(rect.height, 30.0);
}
}
\ No newline at end of file
......@@ -31,6 +31,4 @@ pub trait Spacer {
/// Sets thickness.
fn set_thickness<T: Into<Thickness>>(&mut self, thickness: T);
}
}
\ No newline at end of file
use super::*;
#[test]
fn test_brush() {
let brush = Brush::from("#000000");
let builder = BorderBuilder::new();
let border = builder.brush(brush).build();
let test_brush = Brush::from("#000000");
assert_eq!(border.brush(), &test_brush);
}
#[test]
fn test_thickness() {
let thickness = Thickness::new(0.0, 0.0, 0.0, 0.0);
let builder = BorderBuilder::new();
let border = builder.thickness(thickness).build();
assert_eq!(border.thickness(), thickness);
}
#[test]
fn test_radius() {
let radius = 0.0;
let builder = BorderBuilder::new();
let border = builder.radius(radius).build();
assert_eq!(border.radius(), radius);
}
#[test]
fn test_set_brush() {
let brush = Brush::from("#000000");
let mut border = Border::default();
border.set_brush(brush);
let test_brush = Brush::from("#000000");
assert_eq!(border.brush(), &test_brush);
}
#[test]
fn test_set_thickness() {
let thickness = Thickness::new(0.0, 0.0, 0.0, 0.0);
let mut border = Border::default();
border.set_thickness(thickness);
assert_eq!(border.thickness(), thickness);
}
#[test]
fn test_set_radius() {
let radius = 0.0;
let mut border = Border::default();
border.set_radius(radius);
assert_eq!(border.radius(), radius);
}
// !!! Brush is still WIP. Brush will use color struct from OrbGL. !!!
use super::*;
#[test]
fn test_set_width() {
let width = 10.0;
let mut dirty_size = DirtySize::default();
dirty_size.set_width(width);
assert_eq!(dirty_size.width(), width);
assert!(dirty_size.dirty());
}
#[test]
fn test_set_height() {
let height = 10.0;
let mut dirty_size = DirtySize::default();
dirty_size.set_height(height);
assert_eq!(dirty_size.height(), height);
assert!(dirty_size.dirty());
}
#[test]
fn test_set_size() {
let size = (10.0, 20.0);
let mut dirty_size = DirtySize::default();
dirty_size.set_size(size.0, size.1);
assert_eq!(dirty_size.size(), size);
assert!(dirty_size.dirty());
}
#[test]
fn test_set_dirty() {
let mut dirty_size = DirtySize::default();
dirty_size.set_dirty(false);
assert!(!dirty_size.dirty());
}
use super::*;
mod border;
mod brush;
mod dirty_size;
mod rect;
mod thickness;
use super::*;
#[test]
fn test_new() {
let rect = Rect::new(5.0, 10.0, 20.0, 30.0);
assert_eq!(rect.x, 5.0);
assert_eq!(rect.y, 10.0);
assert_eq!(rect.width, 20.0);
assert_eq!(rect.height, 30.0);
}
use super::*;
#[test]
fn test_new() {
let rect = Thickness::new(5.0, 10.0, 20.0, 30.0);
assert_eq!(rect.left, 5.0);
assert_eq!(rect.top, 10.0);
assert_eq!(rect.right, 20.0);
assert_eq!(rect.bottom, 30.0);
}
#[test]
fn test_into() {
let thickness: Thickness = (10.0, 12.0, 13.0, 14.0).into();
assert_eq!(thickness.left, 10.0);
assert_eq!(thickness.top, 12.0);
assert_eq!(thickness.right, 13.0);
assert_eq!(thickness.bottom, 14.0);
let thickness: Thickness = 10.0.into();
assert_eq!(thickness.left, 10.0);
assert_eq!(thickness.top, 10.0);
assert_eq!(thickness.right, 10.0);
assert_eq!(thickness.bottom, 10.0);
}
......@@ -124,4 +124,36 @@ pub trait Spacer {
/// Sets thickness.
fn set_thickness<T: Into<Thickness>>(&mut self, thickness: T);
}
#[cfg(test)]
mod tests {
use crate::prelude::*;
#[test]
fn test_new() {
let rect = Thickness::new(5.0, 10.0, 20.0, 30.0);
assert_eq!(rect.left, 5.0);
assert_eq!(rect.top, 10.0);
assert_eq!(rect.right, 20.0);
assert_eq!(rect.bottom, 30.0);
}
#[test]
fn test_into() {
let thickness: Thickness = (10.0, 12.0, 13.0, 14.0).into();
assert_eq!(thickness.left, 10.0);
assert_eq!(thickness.top, 12.0);
assert_eq!(thickness.right, 13.0);
assert_eq!(thickness.bottom, 14.0);
let thickness: Thickness = 10.0.into();
assert_eq!(thickness.left, 10.0);
assert_eq!(thickness.top, 10.0);
assert_eq!(thickness.right, 10.0);
assert_eq!(thickness.bottom, 10.0);
}
}
\ No newline at end of file
[package]
name = "orbtk-tree"
version = "0.1.0"
authors = ["Florian Blasius <flovanpt@posteo.de>"]
description = "Tree structure based on DCES."
repository = "https://gitlab.redox-os.org/redox-os/orbtk"
license = "MIT"
keywords = ["ecs", "tree"]
edition = "2018"
[dependencies]
dces = { git = "https://gitlab.redox-os.org/redox-os/dces-rust.git" }
\ No newline at end of file
pub mod prelude;
use std::{
cell::{Cell, RefCell},
collections::BTreeMap,
......@@ -5,9 +7,17 @@ use std::{
use dces::prelude::{Entity, EntityContainer};
use crate::enums;
/// Used as return type if a requested entity is not found on the tree.
#[derive(Debug, PartialEq, Eq)]
pub enum NotFound {
/// Parent could not be found.
Parent(Entity),
/// Child could not be found
Child(Entity),
}
/// Base data structure to manage the widget entities of a window in a tree based structure.
/// Base data structure to manage the entity entities of a window in a tree based structure.
#[derive(Default)]
pub struct Tree {
pub root: Entity,
......@@ -23,7 +33,7 @@ impl Tree {
self
}
/// Registers a new widget `entity` as node.
/// Registers a new entity `entity` as node.
pub fn register_node(&mut self, entity: Entity) {
self.children.insert(entity, vec![]);
self.parent.insert(entity, None);
......@@ -35,11 +45,11 @@ impl Tree {
&mut self,
parent: Entity,
child: Entity,
) -> Result<Entity, enums::NotFound> {
) -> Result<Entity, NotFound> {
if let Some(p) = self.children.get_mut(&parent) {
p.push(child);
} else {
return Err(enums::NotFound::Parent(parent));
return Err(NotFound::Parent(parent));
}
self.parent.insert(child, Some(parent));
......
pub use crate::*;
\ No newline at end of file
......@@ -134,7 +134,7 @@ fn main() {
.create_window()
.bounds((100.0, 100.0, 420.0, 730.0))
.title("OrbTk - widgets example")
.debug_flag(true)
.debug_flag(false)
.build(MainView::create());
application.run();
}
......@@ -3,11 +3,9 @@
use crate::prelude::*;
pub use self::global::*;
pub use self::tree::*;
pub use self::window::*;
mod global;
mod tree;
mod window;
#[derive(Default)]
......
......@@ -25,6 +25,7 @@ pub use crate::widgets::*;
pub use dces::prelude::*;
pub use orbtk_css_engine::prelude as css_engine;
pub use orbtk_structs::prelude as structs;
pub use orbtk_tree::prelude as tree;
pub mod application;
......
......@@ -20,5 +20,6 @@ pub use crate::{
widgets::*,
widget,
property,
css_engine::{Selector as SelectorValue, Theme, ThemeBuilder, SelectorRelation}
css_engine::{Selector as SelectorValue, Theme, ThemeBuilder, SelectorRelation},
tree::*,
};
\ No newline at end of file
......@@ -7,18 +7,7 @@ use std::{
use dces::prelude::{Entity, EntityComponentManager, System};
use crate::{
application::Tree,
backend::Backend,
event::{
check_mouse_condition, ClickEvent, EventBox, EventHandler, EventStrategy, MouseDownEvent,
MouseUpEvent, SystemEvent, WindowEvent,
},
properties::{Bounds, Constraint, ConstraintExt, Enabled, Focused, Pressed, Selected},
structs::Size,
widgets::WidgetContainer,
Global,
};
use crate::{backend::Backend, prelude::*};
pub struct EventSystem {
pub backend: Rc<RefCell<dyn Backend>>,
......
......@@ -2,12 +2,7 @@ use std::{cell::{Cell, RefCell}, rc::Rc, collections::BTreeMap};
use dces::prelude::{Entity, EntityComponentManager, System};
use crate::{
application::{Global, Tree},
backend::Backend,
properties::*,
widgets::{Context, State},
};
use crate::{backend::Backend, prelude::*};
/// This system is used to initializes the widgets.
pub struct InitSystem {
......
......@@ -6,9 +6,7 @@ use std::{
use dces::prelude::{Entity, EntityComponentManager, System};
use crate::{
application::Tree, backend::Backend, layout::Layout, properties::Bounds, structs::Size,
};
use crate::{backend::Backend, prelude::*};
/// The `LayoutSystem` builds per iteration the layout of the current ui. The layout parts are calulated by the layout objects of layout widgets.
pub struct LayoutSystem {
......
......@@ -6,14 +6,7 @@ use std::{
use dces::prelude::{Entity, EntityComponentManager, System};
use crate::{
application::Tree,
backend::Backend,
properties::*,
widgets::{
add_selector_to_widget, remove_selector_from_widget, Context, State, WidgetContainer,
},
};
use crate::{backend::Backend, prelude::*};
/// The `StateSystem` calls the update methods of widget states.
pub struct StateSystem {
......
......@@ -2,12 +2,7 @@ use std::{cell::RefCell, collections::BTreeMap, rc::Rc};
use dces::prelude::{Component, ComponentBox, Entity, SharedComponentBox, World};
use crate::application::Tree;
use crate::event::EventHandler;
use crate::{Layout, RenderObject};
use crate::prelude::*;
use super::State;
/// Used to create an entity for a widget with its properties as components.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment