Commit 618acef3 authored by Florian Blasius's avatar Florian Blasius 🤘

[#157] complete moved theme to sub crate.

parent 5a827093
Pipeline #3837 passed with stages
in 4 minutes and 53 seconds
This diff is collapsed.
......@@ -133,9 +133,9 @@ fn main() {
application
.create_window()
.bounds((100.0, 100.0, 420.0, 730.0))
.title("OrbTk -- light theme example")
.debug_flag(true)
.theme(Theme::default_light())
.title("OrbTk - light theme example")
.debug_flag(false)
.theme(light_theme())
.build(MainView::create());
application.run();
}
//! This module contains the base elements of an OrbTk application (Application, WindowBuilder and Window).
use crate::{Bounds, Theme};
use crate::prelude::*;
pub use self::global::*;
pub use self::tree::*;
......@@ -28,7 +28,7 @@ impl Application {
application: self,
bounds: Bounds::default(),
title: String::from(""),
theme: Theme::default(),
theme: default_theme(),
resizable: false,
debug_flag: false,
}
......
......@@ -6,21 +6,9 @@ use std::{
use dces::prelude::{Entity, World};
use crate::{
application::{Application, Tree},
backend::{target_backend, BackendRunner},
event::EventHandler,
layout::Layout,
properties::*,
render_object::RenderObject,
structs::{Size, Rect, Point},
systems::{
EventSystem, InitSystem, LayoutSystem, PostLayoutStateSystem, RenderSystem, StateSystem,
},
theme::Theme,
widgets::{State, BuildContext, Widget},
Global,
};
use crate::prelude::*;
use crate::backend::*;
use crate::systems::*;
/// Represents a window. Each window has its own tree, event pipeline and backend.
pub struct Window {
......
......@@ -13,10 +13,7 @@ use orbclient::Color;
use orbfont::Font;
use orbgl_api::prelude::Canvas;
use crate::{
application::Tree, event::EventQueue, properties::Bounds, structs::Point, theme::Theme,
widgets::MessageBox,
};
use crate::prelude::*;
/// Provides the context for the `InitSystem`.
pub struct InitContext<'a> {
......
......@@ -8,18 +8,8 @@ use dces::prelude::{Entity, World};
use orbgl::prelude::{CairoRenderEngine, FramebufferSurface};
use orbgl_api::Canvas;
use crate::application::Tree;
use crate::backend::{
Backend, BackendRunner, EventContext, InitContext, LayoutContext, RenderContext, StateContext,
};
use crate::event::{
EventQueue, Key, KeyDownEvent, KeyUpEvent, MouseButton, MouseDownEvent, MouseUpEvent,
SystemEvent, WindowEvent,
};
use crate::structs::Point;
use crate::theme::Theme;
use crate::widgets::MessageBox;
use crate::prelude::*;
use crate::backend::*;
/// Implementation of the OrbClient based backend.
pub struct OrbitalBackend {
......
......@@ -8,10 +8,8 @@ use orbclient::{Window as OrbWindow, WindowFlag};
use orbfont::Font;
use self::backend::{OrbitalBackend, OrbitalBackendRunner};
use crate::backend::{Backend, FontMeasure};
use crate::properties::Bounds;
use crate::structs::{Position, Size};
use crate::theme::Theme;
use crate::prelude::*;
use crate::backend::*;
mod backend;
mod renderer;
......
......@@ -6,18 +6,8 @@ use std::{
use dces::prelude::{Entity, EntityComponentManager};
use crate::{
application::Tree,
backend::{FontMeasure, FONT_MEASURE},
properties::{
Bounds, Constraint, Font, FontIcon, FontSize, HorizontalAlignment, IconFont, IconSize,
Image, Text, VerticalAlignment, Visibility, VisibilityValue, WaterMark, ImageExt, ConstraintExt,
},
enums::Alignment,
structs::{DirtySize, Size},
theme::Theme,
widgets::WidgetContainer,
};
use crate::prelude::*;
use crate::backend::{FontMeasure, FONT_MEASURE};
use super::Layout;
......
......@@ -6,13 +6,7 @@ use std::{
use dces::prelude::{Entity, EntityComponentManager};
use crate::{
application::Tree,
properties::*,
structs::{DirtySize, Position, Size, Spacer},
enums::Alignment,
theme::Theme,
};
use crate::prelude::*;
use super::Layout;
......
......@@ -2,11 +2,7 @@ use std::{cell::RefCell, collections::BTreeMap, rc::Rc, any::Any};
use dces::prelude::{Entity, EntityComponentManager};
use crate::{
application::Tree,
structs::DirtySize,
theme::Theme,
};
use crate::prelude::*;
pub use self::fixed_size::*;
pub use self::grid::*;
......
......@@ -6,15 +6,7 @@ use std::{
use dces::prelude::{Entity, EntityComponentManager};
use crate::{
application::Tree,
properties::{
Bounds, Constraint, HorizontalAlignment, Margin, Padding, VerticalAlignment, Visibility, VisibilityValue, ConstraintExt,
},
enums::Alignment,
structs::{DirtySize, Position, Size, Spacer},
theme::Theme,
};
use crate::prelude::*;
use super::Layout;
......
......@@ -7,13 +7,7 @@ use std::{
use dces::prelude::{Entity, EntityComponentManager};
use crate::{
application::Tree,
properties::*,
enums::Alignment,
structs::*,
theme::Theme,
};
use crate::prelude::*;
use super::Layout;
......
......@@ -6,13 +6,7 @@ use std::{
use dces::prelude::{Entity, EntityComponentManager};
use crate::{
application::Tree,
properties::*,
structs::{DirtySize, Position, Size, Spacer},
enums::Alignment,
theme::Theme,
};
use crate::prelude::*;
use super::Layout;
......
......@@ -6,14 +6,8 @@ use std::{
use dces::prelude::{Entity, EntityComponentManager};
use crate::{
application::Tree,
backend::{FontMeasure, FONT_MEASURE},
properties::*,
structs::{DirtySize, Size, Spacer},
theme::Theme,
widgets::WidgetContainer,
};
use crate::prelude::*;
use crate::backend::{FontMeasure, FONT_MEASURE};
use super::Layout;
......@@ -122,13 +116,13 @@ impl Layout for TextSelectionLayout {
if let Some(selection) = widget.try_get::<TextSelection>() {
if let Some(text_part) = text.0.get(0..selection.0.start_index) {
pos = FONT_MEASURE
pos = crate::FONT_MEASURE
.measure(text_part, &(font.0).0, font_size.0 as u32)
.0 as f64;
if text_part.ends_with(" ") {
pos +=
(FONT_MEASURE.measure("a", &(font.0).0, font_size.0 as u32).0 / 2) as f64;
(crate::FONT_MEASURE.measure("a", &(font.0).0, font_size.0 as u32).0 / 2) as f64;
}
}
}
......
......@@ -20,7 +20,6 @@ pub use crate::structs::*;
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::theme::*;
pub use crate::widgets::*;
pub use dces::prelude::*;
......@@ -37,6 +36,5 @@ pub mod properties;
pub mod render_object;
pub mod styling;
pub mod systems;
pub mod theme;
pub mod widgets;
pub mod prelude;
......@@ -17,9 +17,8 @@ pub use crate::{
render_object::*,
structs::*,
styling::*,
theme::*,
widgets::*,
widget,
property,
css_engine::Selector as SelectorValue
css_engine::{Selector as SelectorValue, Theme, ThemeBuilder, SelectorRelation}
};
\ No newline at end of file
use std::sync::Arc;
use crate::prelude::Theme;
pub static DEFAULT_THEME_CSS: &'static str = include_str!("dark.css");
pub static LIGHT_THEME_EXTENSION_CSS: &'static str = include_str!("light.css");
lazy_static! {
pub static ref DEFAULT_THEME: Arc<Theme> = {
Arc::new(Theme::create_from_css(DEFAULT_THEME_CSS).build())
};
}
lazy_static! {
pub static ref LIGHT_THEME_CSS: String =
format!("{}{}", LIGHT_THEME_EXTENSION_CSS, DEFAULT_THEME_CSS);
}
pub fn default_theme() -> Theme {
Theme::create_from_css(DEFAULT_THEME_CSS).build()
}
pub fn light_theme() -> Theme {
Theme::create_from_css(&LIGHT_THEME_CSS[..]).build()
}
\ No newline at end of file
......@@ -6,14 +6,8 @@ use std::{
use dces::prelude::{Entity, EntityComponentManager, System};
use crate::{
application::Tree,
backend::Backend,
properties::*,
render_object::RenderObject,
structs::{Point, Position, Brush, Size},
widgets::Context,
};
use crate::prelude::*;
use crate::backend::*;
/// The `RenderSystem` iterates over all visual widgets and used its render objects to draw them on the screen.
pub struct RenderSystem {
......@@ -39,7 +33,8 @@ impl System<Tree> for RenderSystem {
offsets.insert(tree.root, (0.0, 0.0));
// render window background
if let Some(background) = render_context.theme.brush("background", &"window".into()) {
let selector = SelectorValue::new().with("window");
if let Some(background) = render_context.theme.brush("background", &selector) {
render_context.renderer.render(background.into())
}
......@@ -89,7 +84,7 @@ impl System<Tree> for RenderSystem {
if let Ok(bounds) = ecm.borrow_component::<Bounds>(node) {
let selector = Selector::from("debug-border");
let brush = render_context.theme.brush("border-color", &selector).unwrap();
let brush = render_context.theme.brush("border-color", &selector.0).unwrap();
match brush {
Brush::SolidColor(color) => render_context.canvas.set_stroke_style(color),
......
This diff is collapsed.
......@@ -141,43 +141,43 @@ impl<'a> Context<'a> {
}
if self.widget().has::<Foreground>() {
if let Some(color) = self.theme.brush("color", &selector) {
if let Some(color) = self.theme.brush("color", &selector.0) {
self.widget().set::<Foreground>(Foreground::from(color));
}
}
if self.widget().has::<Background>() {
if let Some(background) = self.theme.brush("background", &selector) {
if let Some(background) = self.theme.brush("background", &selector.0) {
self.widget().set::<Background>(Background::from(background));
}
}
if self.widget().has::<BorderBrush>() {
if let Some(border_color) = self.theme.brush("border-color", &selector) {
if let Some(border_color) = self.theme.brush("border-color", &selector.0) {
self.widget().set::<BorderBrush>(BorderBrush::from(border_color));
}
}
if self.widget().has::<BorderRadius>() {
if let Some(radius) = self.theme.float("border-radius", &selector) {
if let Some(radius) = self.theme.float("border-radius", &selector.0) {
self.widget().set::<BorderRadius>(BorderRadius::from(radius as f64));
}
}
if self.widget().has::<BorderThickness>() {
if let Some(border_width) = self.theme.uint("border-width", &selector) {
if let Some(border_width) = self.theme.uint("border-width", &selector.0) {
self.widget().set::<BorderThickness>(BorderThickness::from(border_width as f64));
}
}
if self.widget().has::<FontSize>() {
if let Some(size) = self.theme.uint("font-size", &selector) {
if let Some(size) = self.theme.uint("font-size", &selector.0) {
self.widget().set::<FontSize>(FontSize::from(size as f64));
}
}
if self.widget().has::<Font>() {
if let Some(font_family) = self.theme.string("font-family", &selector) {
if let Some(font_family) = self.theme.string("font-family", &selector.0) {
if let Some(inner_font) = fonts::font_by_key(&font_family[..]) {
self.widget().set::<Font>(Font::from(inner_font));
}
......@@ -185,19 +185,19 @@ impl<'a> Context<'a> {
}
if self.widget().has::<IconBrush>() {
if let Some(color) = self.theme.brush("icon-color", &selector) {
if let Some(color) = self.theme.brush("icon-color", &selector.0) {
self.widget().set::<IconBrush>(IconBrush::from(color));
}
}
if self.widget().has::<IconSize>() {
if let Some(size) = self.theme.uint("icon-size", &selector) {
if let Some(size) = self.theme.uint("icon-size", &selector.0) {
self.widget().set::<IconSize>(IconSize::from(size as f64));
}
}
if self.widget().has::<IconFont>() {
if let Some(font_family) = self.theme.string("icon-family", &selector) {
if let Some(font_family) = self.theme.string("icon-family", &selector.0) {
if let Some(inner_font) = fonts::font_by_key(&font_family[..]) {
self.widget().set::<IconFont>(IconFont::from(inner_font));
}
......@@ -205,7 +205,7 @@ impl<'a> Context<'a> {
}
if let Some(padding) = self.widget().try_clone::<Padding>() {
if let Some(pad) = self.theme.uint("padding", &selector) {
if let Some(pad) = self.theme.uint("padding", &selector.0) {
let mut padding = padding;
padding.set_thickness(pad as f64);
self.widget().set::<Padding>(padding);
......@@ -213,7 +213,7 @@ impl<'a> Context<'a> {
}
if let Some(padding) = self.widget().try_clone::<Padding>() {
if let Some(left) = self.theme.uint("padding-left", &selector) {
if let Some(left) = self.theme.uint("padding-left", &selector.0) {
let mut padding = padding;
padding.set_left(left as f64);
self.widget().set::<Padding>(padding);
......@@ -221,7 +221,7 @@ impl<'a> Context<'a> {
}
if let Some(padding) = self.widget().try_clone::<Padding>() {
if let Some(top) = self.theme.uint("padding-top", &selector) {
if let Some(top) = self.theme.uint("padding-top", &selector.0) {
let mut padding = padding;
padding.set_top(top as f64);
self.widget().set::<Padding>(padding);
......@@ -229,7 +229,7 @@ impl<'a> Context<'a> {
}
if let Some(padding) = self.widget().try_clone::<Padding>() {
if let Some(right) = self.theme.uint("padding-right", &selector) {
if let Some(right) = self.theme.uint("padding-right", &selector.0) {
let mut padding = padding;
padding.set_right(right as f64);
self.widget().set::<Padding>(padding);
......@@ -237,7 +237,7 @@ impl<'a> Context<'a> {
}
if let Some(padding) = self.widget().try_clone::<Padding>() {
if let Some(bottom) = self.theme.uint("padding-bottom", &selector) {
if let Some(bottom) = self.theme.uint("padding-bottom", &selector.0) {
let mut padding = padding;
padding.set_bottom(bottom as f64);
self.widget().set::<Padding>(padding);
......
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