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)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use client_application::{ClientApp, RepaintCommand};
|
||||
use client_domain::BoundingBox;
|
||||
use protocol::{
|
||||
ServerMessage, WidgetDescriptor, WireContainerNode, WireDirection, WireDisplayHint,
|
||||
WireKeyValue, WireLayoutChild, WireLayoutNode, WireSizing, WireValue, WireWidgetState,
|
||||
ServerMessage, WidgetDescriptor, WireAlignItems, WireContainerNode, WireDirection,
|
||||
WireDisplayHint, WireDisplayHintKind, WireJustifyContent, WireKeyValue, WireLayoutChild,
|
||||
WireLayoutNode, WireSizing, WireValue, WireWidgetState,
|
||||
};
|
||||
|
||||
fn screen() -> BoundingBox {
|
||||
@@ -12,7 +13,7 @@ fn screen() -> BoundingBox {
|
||||
fn weather_descriptor(id: u16, temp: &str) -> WidgetDescriptor {
|
||||
WidgetDescriptor {
|
||||
id,
|
||||
display_hint: WireDisplayHint::IconValue,
|
||||
display_hint: WireDisplayHint::new(WireDisplayHintKind::IconValue),
|
||||
state: WireWidgetState {
|
||||
data: vec![WireKeyValue {
|
||||
key: "temperature".into(),
|
||||
@@ -28,6 +29,8 @@ fn two_widget_layout() -> WireLayoutNode {
|
||||
direction: WireDirection::Row,
|
||||
gap: 0,
|
||||
padding: 0,
|
||||
justify_content: WireJustifyContent::Start,
|
||||
align_items: WireAlignItems::Stretch,
|
||||
children: vec![
|
||||
WireLayoutChild {
|
||||
sizing: WireSizing::Flex(1),
|
||||
@@ -121,6 +124,8 @@ fn second_screen_update_repaints_all_widgets_with_new_layout() {
|
||||
direction: WireDirection::Column,
|
||||
gap: 0,
|
||||
padding: 0,
|
||||
justify_content: WireJustifyContent::Start,
|
||||
align_items: WireAlignItems::Stretch,
|
||||
children: vec![
|
||||
WireLayoutChild {
|
||||
sizing: WireSizing::Flex(1),
|
||||
|
||||
Reference in New Issue
Block a user