Commit 420dc677 authored by Florian Blasius's avatar Florian Blasius 🤘

Move theme resources to sub crate.

parent 0a9af479
......@@ -475,6 +475,7 @@ dependencies = [
"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-theme 0.1.0",
"orbtk-tree 0.1.0",
"orbtk-utils 0.1.0",
]
......@@ -487,6 +488,15 @@ dependencies = [
"orbtk-utils 0.1.0",
]
[[package]]
name = "orbtk-theme"
version = "0.1.0"
dependencies = [
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"orbfont 0.1.9 (git+https://gitlab.redox-os.org/redox-os/orbfont.git)",
"orbtk-css-engine 0.1.0",
]
[[package]]
name = "orbtk-tree"
version = "0.1.0"
......
......@@ -28,8 +28,9 @@ orbimage = "0.1.17"
orbclient = "0.3.22"
[dependencies]
orbtk-utils = { version = "0.1.0", path = "crates/utils" }
orbtk-css-engine = { version = "0.1.0", path = "crates/css-engine" }
orbtk-theme = { version = "0.1.0", path="crates/theme" }
orbtk-utils = { version = "0.1.0", path = "crates/utils" }
orbtk-tree = { version = "0.1.0", path="crates/tree" }
lazy_static = "1.3.0"
# dces = { path = "../dces-rust"}
......@@ -41,6 +42,7 @@ orbgl_api = { git = "https://gitlab.redox-os.org/redox-os/orbgl.git" }
[workspace]
members = [
"crates/css-engine",
"crates/theme",
"crates/utils",
"crates/tree"
]
\ No newline at end of file
[package]
name = "orbtk-theme"
version = "0.1.0"
authors = ["Florian Blasius <flovanpt@posteo.de>"]
description = "Default theme of OrbTk."
repository = "https://gitlab.redox-os.org/redox-os/orbtk"
license = "MIT"
keywords = ["css", "theme", "styling", "ui"]
edition = "2018"
[dependencies]
orbtk-css-engine = { version = "0.1.0", path = "../css-engine" }
lazy_static = "1.3.0"
orbfont = { git = "https://gitlab.redox-os.org/redox-os/orbfont.git" }
\ No newline at end of file
/*!
This crate provides the default theme resources of OrbTks default theme dark and light.
It provides fonts, icons and colors.
*/
pub mod prelude;
pub mod colors;
pub mod fonts;
pub mod vector_graphics;
use std::sync::Arc;
use crate::prelude::Theme;
use orbtk_css_engine::prelude::*;
#[macro_use]
extern crate lazy_static;
pub static DEFAULT_THEME_CSS: &'static str = include_str!("dark.css");
pub static LIGHT_THEME_EXTENSION_CSS: &'static str = include_str!("light.css");
......
pub use crate::{
colors,
fonts,
vector_graphics,
default_theme,
light_theme,
};
\ No newline at end of file
......@@ -56,3 +56,98 @@ impl From<&str> for Alignment {
}
}
}
#[cfg(test)]
mod tests {
use crate::prelude::*;
#[test]
fn test_align_position() {
let available_measure = 100.0;
let measure = 50.0;
let alignment = Alignment::Stretch;
assert_eq!(
alignment.align_position(available_measure, measure, 0.0, 0.0),
0.0
);
let alignment = Alignment::Center;
assert_eq!(
alignment.align_position(available_measure, measure, 0.0, 0.0),
25.0
);
let alignment = Alignment::Start;
assert_eq!(
alignment.align_position(available_measure, measure, 0.0, 0.0),
0.0
);
let alignment = Alignment::End;
assert_eq!(
alignment.align_position(available_measure, measure, 0.0, 0.0),
50.0
);
}
#[test]
fn test_align_measure() {
let available_measure = 100.0;
let measure = 50.0;
let alignment = Alignment::Stretch;
assert_eq!(
alignment.align_measure(available_measure, measure, 0.0, 0.0),
available_measure
);
let alignment = Alignment::Center;
assert_eq!(
alignment.align_measure(available_measure, measure, 0.0, 0.0),
measure
);
let alignment = Alignment::Start;
assert_eq!(
alignment.align_measure(available_measure, measure, 0.0, 0.0),
measure
);
let alignment = Alignment::End;
assert_eq!(
alignment.align_measure(available_measure, measure, 0.0, 0.0),
measure
);
}
#[test]
fn test_into() {
let alignment: Alignment = "Start".into();
assert_eq!(alignment, Alignment::Start);
let alignment: Alignment = "start".into();
assert_eq!(alignment, Alignment::Start);
let alignment: Alignment = "Center".into();
assert_eq!(alignment, Alignment::Center);
let alignment: Alignment = "center".into();
assert_eq!(alignment, Alignment::Center);
let alignment: Alignment = "End".into();
assert_eq!(alignment, Alignment::End);
let alignment: Alignment = "end".into();
assert_eq!(alignment, Alignment::End);
let alignment: Alignment = "Stretch".into();
assert_eq!(alignment, Alignment::Stretch);
let alignment: Alignment = "stretch".into();
assert_eq!(alignment, Alignment::Stretch);
let alignment: Alignment = "other".into();
assert_eq!(alignment, Alignment::Stretch);
}
}
\ No newline at end of file
pub use self::alignment::*;
pub use self::border::*;
pub use self::brush::*;
pub use self::dirty_size::*;
......@@ -7,6 +8,7 @@ pub use self::thickness::*;
pub use orbgl_api::Color as Color;
mod alignment;
mod border;
mod brush;
mod dirty_size;
......
......@@ -4,7 +4,7 @@ use std::sync::Arc;
use orbclient::{Color, Renderer as OrbRenderer, Window as OrbWindow};
use orbfont::Font;
use crate::{prelude::*, styling::fonts::*, backend::Renderer};
use crate::{prelude::*, backend::Renderer};
pub struct OrbFontRenderer {
pub fonts: HashMap<&'static str, Font>,
......@@ -40,11 +40,11 @@ lazy_static! {
pub static ref FONT_RENDERER: Arc<OrbFontRenderer> = {
let mut fonts = HashMap::new();
if let Ok(font) = Font::from_data(ROBOTO_REGULAR_FONT.to_vec().into_boxed_slice()) {
if let Ok(font) = Font::from_data(fonts::ROBOTO_REGULAR_FONT.to_vec().into_boxed_slice()) {
fonts.insert("Roboto Regular", font);
}
if let Ok(font) = Font::from_data(MATERIAL_ICONS_REGULAR_FONT.to_vec().into_boxed_slice()) {
if let Ok(font) = Font::from_data(fonts::MATERIAL_ICONS_REGULAR_FONT.to_vec().into_boxed_slice()) {
fonts.insert("Material Icons Regular", font);
}
......
use crate::Entity;
/// Used as return type if a requested widget 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),
}
//! This module contains the collection of important enums used in OrbTk.
pub use self::alignment::Alignment;
pub use self::error::*;
pub use self::parent_type::ParentType;
mod alignment;
mod error;
mod parent_type;
#[cfg(test)]
mod tests;
/// Used to define the `parent_type`of a widget.
pub enum ParentType {
/// None children could add to the widget.
None,
/// Only one child could be added to the widget.
Single,
/// Multiple children could be added tot the widget.
Multi,
}
use super::*;
#[test]
fn test_align_position() {
let available_measure = 100.0;
let measure = 50.0;
let alignment = Alignment::Stretch;
assert_eq!(
alignment.align_position(available_measure, measure, 0.0, 0.0),
0.0
);
let alignment = Alignment::Center;
assert_eq!(
alignment.align_position(available_measure, measure, 0.0, 0.0),
25.0
);
let alignment = Alignment::Start;
assert_eq!(
alignment.align_position(available_measure, measure, 0.0, 0.0),
0.0
);
let alignment = Alignment::End;
assert_eq!(
alignment.align_position(available_measure, measure, 0.0, 0.0),
50.0
);
}
#[test]
fn test_align_measure() {
let available_measure = 100.0;
let measure = 50.0;
let alignment = Alignment::Stretch;
assert_eq!(
alignment.align_measure(available_measure, measure, 0.0, 0.0),
available_measure
);
let alignment = Alignment::Center;
assert_eq!(
alignment.align_measure(available_measure, measure, 0.0, 0.0),
measure
);
let alignment = Alignment::Start;
assert_eq!(
alignment.align_measure(available_measure, measure, 0.0, 0.0),
measure
);
let alignment = Alignment::End;
assert_eq!(
alignment.align_measure(available_measure, measure, 0.0, 0.0),
measure
);
}
#[test]
fn test_into() {
let alignment: Alignment = "Start".into();
assert_eq!(alignment, Alignment::Start);
let alignment: Alignment = "start".into();
assert_eq!(alignment, Alignment::Start);
let alignment: Alignment = "Center".into();
assert_eq!(alignment, Alignment::Center);
let alignment: Alignment = "center".into();
assert_eq!(alignment, Alignment::Center);
let alignment: Alignment = "End".into();
assert_eq!(alignment, Alignment::End);
let alignment: Alignment = "end".into();
assert_eq!(alignment, Alignment::End);
let alignment: Alignment = "Stretch".into();
assert_eq!(alignment, Alignment::Stretch);
let alignment: Alignment = "stretch".into();
assert_eq!(alignment, Alignment::Stretch);
let alignment: Alignment = "other".into();
assert_eq!(alignment, Alignment::Stretch);
}
use super::*;
mod alignment;
......@@ -11,31 +11,26 @@ pub mod macros;
pub use crate::application::*;
pub use crate::backend::*;
pub use crate::enums::*;
pub use crate::event::*;
pub use crate::layout::*;
pub use crate::properties::*;
pub use crate::render_object::*;
pub use crate::utils::*;
pub use crate::styling::theme::{DEFAULT_THEME_CSS, LIGHT_THEME_EXTENSION_CSS};
pub use crate::styling::vector_graphics::*;
pub use crate::systems::*;
pub use crate::widgets::*;
pub use dces::prelude::*;
pub use orbtk_css_engine::prelude as css_engine;
pub use orbtk_theme::prelude as theme;
pub use orbtk_utils::prelude as utils;
pub use orbtk_tree::prelude as tree;
pub mod application;
pub mod backend;
pub mod enums;
pub mod event;
pub mod layout;
pub mod properties;
pub mod render_object;
pub mod styling;
pub mod systems;
pub mod widgets;
pub mod prelude;
......@@ -11,12 +11,11 @@ pub use dces::prelude::*;
pub use crate::{
application::*,
event::*,
enums::*,
layout::*,
properties::*,
render_object::*,
utils::*,
styling::*,
theme::{colors, fonts, vector_graphics::material_font_icons, default_theme, light_theme},
widgets::*,
widget,
property,
......
use super::*;
use crate::enums::Alignment;
use crate::prelude::*;
#[test]
fn test_align_position() {
......
use super::*;
use crate::enums::Alignment;
use crate::prelude::*;
#[test]
fn test_align_y() {
......
pub use self::theme::*;
pub use self::vector_graphics::*;
pub mod colors;
pub mod fonts;
pub mod theme;
pub mod vector_graphics;
......@@ -36,6 +36,18 @@ pub fn remove_selector_from_widget(pseudo_class: &str, widget: &mut WidgetContai
}
}
/// Used to define the `parent_type`of a widget.
pub enum ParentType {
/// None children could add to the widget.
None,
/// Only one child could be added to the widget.
Single,
/// Multiple children could be added tot the widget.
Multi,
}
/// The `Widget` trait is used to define a new widget.
pub trait Widget: Template {
/// Creates a new widget.
......
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