new rendering engine
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
use client_domain::{BoundingBox, LayoutEngine, RenderTree};
|
||||
use client_domain::{BoundingBox, Color, LayoutEngine, RenderTree, ThemeConfig};
|
||||
use domain::LayoutNode;
|
||||
use protocol::{ServerMessage, WidgetDescriptor, WireDisplayHint, WireLayoutNode, WireWidgetState};
|
||||
use protocol::{
|
||||
ServerMessage, WireColor, WidgetDescriptor, WireDisplayHint, WireLayoutNode, WireWidgetState,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct ClientApp {
|
||||
screen: BoundingBox,
|
||||
render_tree: Option<RenderTree>,
|
||||
widget_states: HashMap<u16, (WireDisplayHint, WireWidgetState)>,
|
||||
theme: ThemeConfig,
|
||||
theme_changed: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -23,19 +27,47 @@ impl ClientApp {
|
||||
screen,
|
||||
render_tree: None,
|
||||
widget_states: HashMap::new(),
|
||||
theme: ThemeConfig::default(),
|
||||
theme_changed: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn theme(&self) -> &ThemeConfig {
|
||||
&self.theme
|
||||
}
|
||||
|
||||
pub fn take_theme_changed(&mut self) -> bool {
|
||||
let changed = self.theme_changed;
|
||||
self.theme_changed = false;
|
||||
changed
|
||||
}
|
||||
|
||||
pub fn handle_message(&mut self, msg: ServerMessage) -> Vec<RepaintCommand> {
|
||||
match msg {
|
||||
ServerMessage::ScreenUpdate { layout, widgets } => {
|
||||
self.handle_screen_update(layout, widgets)
|
||||
}
|
||||
ServerMessage::DataUpdate { widgets } => self.handle_data_update(widgets),
|
||||
ServerMessage::ThemeUpdate { theme } => self.handle_theme_update(theme),
|
||||
ServerMessage::Heartbeat => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_theme_update(&mut self, wire_theme: protocol::WireTheme) -> Vec<RepaintCommand> {
|
||||
self.theme = ThemeConfig {
|
||||
primary: wire_color(wire_theme.primary),
|
||||
secondary: wire_color(wire_theme.secondary),
|
||||
accent: wire_color(wire_theme.accent),
|
||||
text: wire_color(wire_theme.text),
|
||||
background: wire_color(wire_theme.background),
|
||||
};
|
||||
self.theme_changed = true;
|
||||
match &self.render_tree {
|
||||
Some(tree) => self.build_repaints_for_all(tree),
|
||||
None => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_screen_update(
|
||||
&mut self,
|
||||
wire_layout: WireLayoutNode,
|
||||
@@ -103,3 +135,7 @@ impl ClientApp {
|
||||
repaints
|
||||
}
|
||||
}
|
||||
|
||||
fn wire_color(c: WireColor) -> Color {
|
||||
Color(c.r, c.g, c.b)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user