Commit 03aef195 authored by Florian Blasius's avatar Florian Blasius 🤘

[#157] move structs module to sub crate.

Impl Position for WebWindow.
parent 1ce2e8e3
Pipeline #3815 passed with stages
in 7 minutes and 36 seconds
......@@ -463,13 +463,22 @@ dependencies = [
"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-structs 0.1.0",
"orbtk-web-window 0.1.0",
]
[[package]]
name = "orbtk-structs"
version = "0.1.0"
dependencies = [
"orbgl_api 0.1.0 (git+https://gitlab.redox-os.org/redox-os/orbgl.git)",
]
[[package]]
name = "orbtk-web-window"
version = "0.1.0"
dependencies = [
"orbtk-structs 0.1.0",
"stdweb 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
......
......@@ -31,6 +31,7 @@ orbimage = "0.1.17"
orbclient = "0.3.21"
[dependencies]
orbtk-structs = { version = "0.1.0", path = "crates/structs" }
cssparser = "0.17.0"
lazy_static = "1.3.0"
# dces = { path = "../dces-rust"}
......
[package]
name = "orbtk-structs"
version = "0.1.0"
authors = ["Florian Blasius <flovanpt@posteo.de>"]
description = "Helper structs and traits for OrbTk."
repository = "https://gitlab.redox-os.org/redox-os/orbtk"
license = "MIT"
keywords = ["helpers", "structs", "traits", "ui"]
edition = "2018"
[dependencies]
orbgl_api = { git = "https://gitlab.redox-os.org/redox-os/orbgl.git" }
\ No newline at end of file
pub use self::border::*;
pub use self::brush::*;
pub use self::dirty_size::*;
pub use self::point::*;
pub use self::rect::*;
pub use self::thickness::*;
pub use orbgl_api::Color as Color;
mod border;
mod brush;
mod dirty_size;
mod point;
pub mod prelude;
mod rect;
mod spacer;
mod thickness;
#[cfg(test)]
mod tests;
\ No newline at end of file
pub use crate::*;
\ No newline at end of file
pub use orbclient::Color;
pub use self::border::*;
pub use self::brush::*;
pub use self::dirty_size::DirtySize;
pub use self::point::Point;
pub use self::rect::*;
pub use self::thickness::Thickness;
mod border;
mod brush;
mod dirty_size;
mod point;
mod rect;
mod thickness;
use crate::Thickness;
// todo: documentation
pub trait Spacer {
......@@ -47,5 +33,4 @@ pub trait Spacer {
fn set_thickness<T: Into<Thickness>>(&mut self, thickness: T);
}
#[cfg(test)]
mod tests;
use super::Spacer;
/// Used to describes a thickness e.g a border thickness.
#[derive(Copy, Clone, Default, Debug, PartialEq)]
pub struct Thickness {
......@@ -94,3 +92,36 @@ impl From<f64> for Thickness {
Thickness::new(t, t, t, t)
}
}
// todo: documentation
pub trait Spacer {
/// Gets left.
fn left(&self) -> f64;
/// Sets left.
fn set_left(&mut self, left: f64);
/// Gets top.
fn top(&self) -> f64;
/// Sets top.
fn set_top(&mut self, top: f64);
/// Gets right.
fn right(&self) -> f64;
/// Sets right.
fn set_right(&mut self, right: f64);
/// Gets bottom.
fn bottom(&self) -> f64;
/// Sets bottom.
fn set_bottom(&mut self, bottom: f64);
/// Gets thickness.
fn thickness(&self) -> Thickness;
/// Sets thickness.
fn set_thickness<T: Into<Thickness>>(&mut self, thickness: T);
}
\ No newline at end of file
......@@ -10,4 +10,5 @@ edition = "2018"
[dependencies]
stdweb = "0.4.15"
orbtk-structs = { version = "0.1.0", path = "../structs" }
......@@ -10,6 +10,8 @@ use stdweb::{
},
};
use orbtk_structs::{Position, Size};
/// Used to initializes the web engine.
///
/// This method must be called first!
......@@ -71,4 +73,44 @@ pub struct WebWindow {
title: String,
canvas: CanvasElement,
size: (f64, f64),
}
\ No newline at end of file
}
impl WebWindow {
/// Creates a new `WebWindowBuilder` with default values.
pub fn create() -> WebWindowBuilder {
WebWindowBuilder::new()
}
/// Gets the inner canvas.
pub fn canvas(&self) -> CanvasElement {
self.canvas.clone()
}
}
impl Size for WebWindow {
fn width(&self) -> f64 {
self.canvas.width() as f64
}
fn set_width(&mut self, width: f64) {
self.canvas.set_width(width as u32);
}
fn height(&self) -> f64 {
self.canvas.height() as f64
}
fn set_height(&mut self, height: f64) {
self.canvas.set_height(height as u32)
}
fn size(&self) -> (f64, f64) {
(self.canvas.width() as f64, self.canvas.height() as f64)
}
fn set_size(&mut self, width: f64, height: f64) {
self.set_width(width);
self.set_height(height);
}
}
......@@ -24,6 +24,7 @@ pub use crate::theme::*;
pub use crate::widgets::*;
pub use dces::prelude::*;
pub use orbtk_structs::prelude as structs;
pub mod application;
pub mod backend;
......@@ -32,7 +33,6 @@ pub mod event;
pub mod layout;
pub mod properties;
pub mod render_object;
pub mod structs;
pub mod styling;
pub mod systems;
pub mod theme;
......
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