Commit 403371d3 authored by Florian Blasius's avatar Florian Blasius 🤘

[wip | extend | orbrender] window background, shape udpate by state

parent 3e3c4d10
Pipeline #2501 passed with stages
in 4 minutes and 32 seconds
......@@ -15,7 +15,7 @@ use crate::{
Renderer,
},
properties::{Bounds, Point},
theme::{material_font_icons::MATERIAL_ICONS_REGULAR_FONT, Theme, ROBOTO_REGULAR_FONT},
theme::{material_font_icons::MATERIAL_ICONS_REGULAR_FONT, Theme, ROBOTO_REGULAR_FONT, Selector},
};
pub struct OrbContext {
......@@ -69,6 +69,12 @@ impl OrbContext {
}
impl RenderContext2D for OrbContext {
fn fill_background(&mut self) {
// todo store windwo selector
self.set_fill_style_brush(&self.theme.brush("background", &Selector::from("window")));
self.switch_context();
self.orbclient_context.set(self.fill_color);
}
/// Creates a circular arc centered at (x, y) with a radius of radius. The path starts at startAngle and ends at endAngle, and travels in the direction given by anticlockwise (defaulting to clockwise).
fn arc(
&mut self,
......
......@@ -108,6 +108,9 @@ pub enum Instruction {
/// translater
pub trait RenderContext2D {
/// Fills the whole background with the fill color.
fn fill_background(&mut self);
/// Creates a circular arc centered at (x, y) with a radius of radius. The path starts at startAngle and ends at endAngle, and travels in the direction given by anticlockwise (defaulting to clockwise).
fn arc(
&mut self,
......
......@@ -45,6 +45,7 @@ impl System<Tree> for RenderSystem {
// render window background
{
let render_context = backend.render_context();
render_context.fill_background();
for node in tree.into_iter() {
let mut global_position = Point::default();
......@@ -63,26 +64,6 @@ impl System<Tree> for RenderSystem {
}
}
// render debug border for each widget
// if self.debug_flag.get() {
// if let Ok(bounds) = ecm.borrow_component::<Bounds>(node) {
// if let Ok(parent_bounds) = ecm.borrow_component::<Bounds>(tree.parent[&node]) {
// let selector = Selector::from("debugborder");
// render_context.renderer.render_rectangle(
// bounds,
// parent_bounds,
// &global_position,
// render_context.theme.uint("border-radius", &selector),
// render_context.theme.color("background", &selector),
// render_context.theme.uint("border-width", &selector),
// render_context.theme.color("border-color", &selector),
// render_context.theme.float("opcaity", &selector),
// );
// }
// }
// }
// hide hidden widget
if let Ok(visibility) = ecm.borrow_component::<Visibility>(node) {
if *visibility != Visibility::Visible {
......
......@@ -29,8 +29,7 @@ impl StateSystem {
fn init(&self, theme: &Theme, tree: &Tree, ecm: &mut EntityComponentManager) {
for node in tree.into_iter() {
// Add css id to global id map.
let id = if let Ok(selector) = ecm.borrow_component::<Selector>(node) {
let id = if let Ok(selector) = ecm.borrow_mut_component::<Selector>(node) {
// intialize render shape from theme
if let Some(shape) = self.shapes.borrow_mut().get_mut(&node) {
shape.update_by_selector(selector, theme);
......@@ -141,7 +140,6 @@ impl System<Tree> for StateSystem {
return;
}
let state_context = backend.state_context();
let mut context = Context::new(tree.root, ecm, tree, &state_context.theme);
......@@ -163,6 +161,12 @@ impl System<Tree> for StateSystem {
if let Some(state) = self.states.borrow().get(&node) {
state.update(&mut context);
}
if let Ok(selector) = context.widget().borrow_mut_property::<Selector>() {
if let Some(shape) = self.shapes.borrow_mut().get_mut(&node) {
shape.update_by_selector(selector, &state_context.theme);
}
}
}
}
}
......
......@@ -11,6 +11,10 @@
icon-font-family: "Material Icons Regular";
}
window {
background: "#242424"
}
.space {
width: 100;
}
......
......@@ -34,6 +34,7 @@ pub struct Selector {
pub classes: HashSet<String>,
pub pseudo_classes: HashSet<String>,
pub relation: Option<Box<SelectorRelation>>,
pub dirty: bool,
}
impl Selector {
......@@ -44,9 +45,18 @@ impl Selector {
classes: HashSet::new(),
pseudo_classes: HashSet::new(),
relation: None,
dirty: true,
}
}
pub fn is_dirty(&self) -> bool {
self.dirty
}
pub fn set_dirty(&mut self, dirty: bool) {
self.dirty = dirty;
}
pub fn specificity(&self) -> Specificity {
let s = Specificity([
if self.id.is_some() { 1 } else { 0 },
......@@ -133,6 +143,7 @@ impl Clone for Selector {
classes: self.classes.clone(),
pseudo_classes: self.pseudo_classes.clone(),
relation: self.relation.clone(),
dirty: true,
}
}
}
......@@ -6,19 +6,24 @@ use crate::{
use super::{Selector, Theme};
pub trait UpdateableShape: Shape2D {
fn update_by_selector(&mut self, selector: &Selector, theme: &Theme);
fn update_by_selector(&mut self, selector: &mut Selector, theme: &Theme);
fn update_by_bounds(&mut self, x: f64, y: f64, width: f64, height: f64);
}
impl UpdateableShape for Rectangle {
fn update_by_selector(&mut self, selector: &Selector, theme: &Theme) {
// todo selector dirty!!!
fn update_by_selector(&mut self, selector: &mut Selector, theme: &Theme) {
if !selector.is_dirty() {
return;
}
let left = theme.uint("border-left", selector) as f64;
let right = theme.uint("border-left", selector) as f64;
let top = theme.uint("border-left", selector) as f64;
let bottom = theme.uint("border-left", selector) as f64;
let width = theme.uint("border-width", selector) as f64;
// todo radius
let radius = theme.uint("border-radius", selector) as f64;
let brush = theme.brush("border-color", selector);
let background = theme.brush("background", selector);
......@@ -35,6 +40,7 @@ impl UpdateableShape for Rectangle {
self.set_border_brush(brush);
self.set_background(background);
self.create_shape();
selector.set_dirty(false);
}
fn update_by_bounds(&mut self, x: f64, y: f64, width: f64, height: f64) {
......
......@@ -22,6 +22,7 @@ pub trait Widget {
pub fn add_selector_to_widget(pseudo_class: &str, widget: &mut WidgetContainer<'_>) {
if let Ok(selector) = widget.borrow_mut_property::<Selector>() {
selector.pseudo_classes.insert(String::from(pseudo_class));
selector.set_dirty(true);
}
}
......@@ -29,5 +30,6 @@ pub fn add_selector_to_widget(pseudo_class: &str, widget: &mut WidgetContainer<'
pub fn remove_selector_from_widget(pseudo_class: &str, widget: &mut WidgetContainer<'_>) {
if let Ok(selector) = widget.borrow_mut_property::<Selector>() {
selector.pseudo_classes.remove(pseudo_class);
selector.set_dirty(true);
}
}
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