new rendering engine
This commit is contained in:
@@ -8,6 +8,22 @@ pub struct WidgetDescriptor {
|
||||
pub state: WireWidgetState,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct WireColor {
|
||||
pub r: u8,
|
||||
pub g: u8,
|
||||
pub b: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct WireTheme {
|
||||
pub primary: WireColor,
|
||||
pub secondary: WireColor,
|
||||
pub accent: WireColor,
|
||||
pub text: WireColor,
|
||||
pub background: WireColor,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum ServerMessage {
|
||||
ScreenUpdate {
|
||||
@@ -17,6 +33,9 @@ pub enum ServerMessage {
|
||||
DataUpdate {
|
||||
widgets: Vec<WidgetDescriptor>,
|
||||
},
|
||||
ThemeUpdate {
|
||||
theme: WireTheme,
|
||||
},
|
||||
Heartbeat,
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,11 @@ mod frame;
|
||||
mod wire;
|
||||
|
||||
pub use frame::{
|
||||
ClientMessage, MAX_FRAME_SIZE, ServerMessage, WidgetDescriptor, decode_client_message,
|
||||
decode_server_message, encode, encode_client,
|
||||
ClientMessage, MAX_FRAME_SIZE, ServerMessage, WireColor, WireTheme, WidgetDescriptor,
|
||||
decode_client_message, decode_server_message, encode, encode_client,
|
||||
};
|
||||
pub use wire::{
|
||||
WireContainerNode, WireDirection, WireDisplayHint, WireKeyValue, WireLayoutChild,
|
||||
WireLayoutNode, WireSizing, WireValue, WireWidgetError, WireWidgetState,
|
||||
WireAlignItems, WireContainerNode, WireDirection, WireDisplayHint, WireDisplayHintKind,
|
||||
WireHAlign, WireJustifyContent, WireKeyValue, WireLayoutChild, WireLayoutNode, WireSizing,
|
||||
WireVAlign, WireValue, WireWidgetError, WireWidgetState,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use domain::value_objects::{
|
||||
ContainerNode, Direction, DisplayHint, LayoutChild, LayoutNode, Sizing, Value, WidgetError,
|
||||
WidgetState,
|
||||
AlignItems, ContainerNode, Direction, DisplayHint, DisplayHintKind, HAlign, JustifyContent,
|
||||
LayoutChild, LayoutNode, Sizing, VAlign, Value, WidgetError, WidgetState,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
@@ -111,28 +111,119 @@ impl From<WireWidgetState> for WidgetState {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireDisplayHint {
|
||||
pub enum WireDisplayHintKind {
|
||||
IconValue,
|
||||
TextBlock,
|
||||
KeyValue,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireHAlign {
|
||||
Left,
|
||||
Center,
|
||||
Right,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireVAlign {
|
||||
Top,
|
||||
Middle,
|
||||
Bottom,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct WireDisplayHint {
|
||||
pub kind: WireDisplayHintKind,
|
||||
pub h_align: WireHAlign,
|
||||
pub v_align: WireVAlign,
|
||||
}
|
||||
|
||||
impl WireDisplayHint {
|
||||
pub fn new(kind: WireDisplayHintKind) -> Self {
|
||||
Self {
|
||||
kind,
|
||||
h_align: WireHAlign::Left,
|
||||
v_align: WireVAlign::Top,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&DisplayHintKind> for WireDisplayHintKind {
|
||||
fn from(k: &DisplayHintKind) -> Self {
|
||||
match k {
|
||||
DisplayHintKind::IconValue => WireDisplayHintKind::IconValue,
|
||||
DisplayHintKind::TextBlock => WireDisplayHintKind::TextBlock,
|
||||
DisplayHintKind::KeyValue => WireDisplayHintKind::KeyValue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireDisplayHintKind> for DisplayHintKind {
|
||||
fn from(w: WireDisplayHintKind) -> Self {
|
||||
match w {
|
||||
WireDisplayHintKind::IconValue => DisplayHintKind::IconValue,
|
||||
WireDisplayHintKind::TextBlock => DisplayHintKind::TextBlock,
|
||||
WireDisplayHintKind::KeyValue => DisplayHintKind::KeyValue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&HAlign> for WireHAlign {
|
||||
fn from(h: &HAlign) -> Self {
|
||||
match h {
|
||||
HAlign::Left => WireHAlign::Left,
|
||||
HAlign::Center => WireHAlign::Center,
|
||||
HAlign::Right => WireHAlign::Right,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireHAlign> for HAlign {
|
||||
fn from(w: WireHAlign) -> Self {
|
||||
match w {
|
||||
WireHAlign::Left => HAlign::Left,
|
||||
WireHAlign::Center => HAlign::Center,
|
||||
WireHAlign::Right => HAlign::Right,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&VAlign> for WireVAlign {
|
||||
fn from(v: &VAlign) -> Self {
|
||||
match v {
|
||||
VAlign::Top => WireVAlign::Top,
|
||||
VAlign::Middle => WireVAlign::Middle,
|
||||
VAlign::Bottom => WireVAlign::Bottom,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireVAlign> for VAlign {
|
||||
fn from(w: WireVAlign) -> Self {
|
||||
match w {
|
||||
WireVAlign::Top => VAlign::Top,
|
||||
WireVAlign::Middle => VAlign::Middle,
|
||||
WireVAlign::Bottom => VAlign::Bottom,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&DisplayHint> for WireDisplayHint {
|
||||
fn from(h: &DisplayHint) -> Self {
|
||||
match h {
|
||||
DisplayHint::IconValue => WireDisplayHint::IconValue,
|
||||
DisplayHint::TextBlock => WireDisplayHint::TextBlock,
|
||||
DisplayHint::KeyValue => WireDisplayHint::KeyValue,
|
||||
WireDisplayHint {
|
||||
kind: (&h.kind).into(),
|
||||
h_align: (&h.h_align).into(),
|
||||
v_align: (&h.v_align).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireDisplayHint> for DisplayHint {
|
||||
fn from(w: WireDisplayHint) -> Self {
|
||||
match w {
|
||||
WireDisplayHint::IconValue => DisplayHint::IconValue,
|
||||
WireDisplayHint::TextBlock => DisplayHint::TextBlock,
|
||||
WireDisplayHint::KeyValue => DisplayHint::KeyValue,
|
||||
DisplayHint {
|
||||
kind: w.kind.into(),
|
||||
h_align: w.h_align.into(),
|
||||
v_align: w.v_align.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,11 +276,76 @@ impl From<WireDirection> for Direction {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireJustifyContent {
|
||||
Start,
|
||||
Center,
|
||||
End,
|
||||
SpaceBetween,
|
||||
SpaceEvenly,
|
||||
}
|
||||
|
||||
impl From<&JustifyContent> for WireJustifyContent {
|
||||
fn from(j: &JustifyContent) -> Self {
|
||||
match j {
|
||||
JustifyContent::Start => WireJustifyContent::Start,
|
||||
JustifyContent::Center => WireJustifyContent::Center,
|
||||
JustifyContent::End => WireJustifyContent::End,
|
||||
JustifyContent::SpaceBetween => WireJustifyContent::SpaceBetween,
|
||||
JustifyContent::SpaceEvenly => WireJustifyContent::SpaceEvenly,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireJustifyContent> for JustifyContent {
|
||||
fn from(w: WireJustifyContent) -> Self {
|
||||
match w {
|
||||
WireJustifyContent::Start => JustifyContent::Start,
|
||||
WireJustifyContent::Center => JustifyContent::Center,
|
||||
WireJustifyContent::End => JustifyContent::End,
|
||||
WireJustifyContent::SpaceBetween => JustifyContent::SpaceBetween,
|
||||
WireJustifyContent::SpaceEvenly => JustifyContent::SpaceEvenly,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireAlignItems {
|
||||
Start,
|
||||
Center,
|
||||
End,
|
||||
Stretch,
|
||||
}
|
||||
|
||||
impl From<&AlignItems> for WireAlignItems {
|
||||
fn from(a: &AlignItems) -> Self {
|
||||
match a {
|
||||
AlignItems::Start => WireAlignItems::Start,
|
||||
AlignItems::Center => WireAlignItems::Center,
|
||||
AlignItems::End => WireAlignItems::End,
|
||||
AlignItems::Stretch => WireAlignItems::Stretch,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireAlignItems> for AlignItems {
|
||||
fn from(w: WireAlignItems) -> Self {
|
||||
match w {
|
||||
WireAlignItems::Start => AlignItems::Start,
|
||||
WireAlignItems::Center => AlignItems::Center,
|
||||
WireAlignItems::End => AlignItems::End,
|
||||
WireAlignItems::Stretch => AlignItems::Stretch,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct WireContainerNode {
|
||||
pub direction: WireDirection,
|
||||
pub gap: u8,
|
||||
pub padding: u8,
|
||||
pub justify_content: WireJustifyContent,
|
||||
pub align_items: WireAlignItems,
|
||||
pub children: Vec<WireLayoutChild>,
|
||||
}
|
||||
|
||||
@@ -213,6 +369,8 @@ impl From<&LayoutNode> for WireLayoutNode {
|
||||
direction: (&c.direction).into(),
|
||||
gap: c.gap,
|
||||
padding: c.padding,
|
||||
justify_content: (&c.justify_content).into(),
|
||||
align_items: (&c.align_items).into(),
|
||||
children: c
|
||||
.children
|
||||
.iter()
|
||||
@@ -234,6 +392,8 @@ impl From<WireLayoutNode> for LayoutNode {
|
||||
direction: c.direction.into(),
|
||||
gap: c.gap,
|
||||
padding: c.padding,
|
||||
justify_content: c.justify_content.into(),
|
||||
align_items: c.align_items.into(),
|
||||
children: c
|
||||
.children
|
||||
.into_iter()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use domain::{
|
||||
ContainerNode, Direction, DisplayHint, LayoutChild, LayoutNode, Sizing, Value, WidgetError,
|
||||
WidgetState,
|
||||
AlignItems, ContainerNode, Direction, DisplayHint, DisplayHintKind, JustifyContent,
|
||||
LayoutChild, LayoutNode, Sizing, Value, WidgetError, WidgetState,
|
||||
};
|
||||
use protocol::{
|
||||
WireContainerNode, WireDirection, WireDisplayHint, WireKeyValue, WireLayoutChild,
|
||||
@@ -43,6 +43,8 @@ fn layout_tree_converts_to_wire_and_back() {
|
||||
direction: Direction::Row,
|
||||
gap: 4,
|
||||
padding: 2,
|
||||
justify_content: JustifyContent::Start,
|
||||
align_items: AlignItems::Stretch,
|
||||
children: vec![
|
||||
LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
@@ -54,6 +56,8 @@ fn layout_tree_converts_to_wire_and_back() {
|
||||
direction: Direction::Column,
|
||||
gap: 2,
|
||||
padding: 0,
|
||||
justify_content: JustifyContent::Start,
|
||||
align_items: AlignItems::Stretch,
|
||||
children: vec![LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
node: LayoutNode::Leaf(2),
|
||||
@@ -71,9 +75,9 @@ fn layout_tree_converts_to_wire_and_back() {
|
||||
#[test]
|
||||
fn display_hint_converts_to_wire_and_back() {
|
||||
for hint in [
|
||||
DisplayHint::IconValue,
|
||||
DisplayHint::TextBlock,
|
||||
DisplayHint::KeyValue,
|
||||
DisplayHint::new(DisplayHintKind::IconValue),
|
||||
DisplayHint::new(DisplayHintKind::TextBlock),
|
||||
DisplayHint::new(DisplayHintKind::KeyValue),
|
||||
] {
|
||||
let wire: WireDisplayHint = (&hint).into();
|
||||
let roundtripped: DisplayHint = wire.into();
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use protocol::{
|
||||
ClientMessage, ServerMessage, WidgetDescriptor, WireContainerNode, WireDirection,
|
||||
WireDisplayHint, WireKeyValue, WireLayoutChild, WireLayoutNode, WireSizing, WireValue,
|
||||
WireWidgetState, decode_client_message, decode_server_message, encode, encode_client,
|
||||
ClientMessage, ServerMessage, WidgetDescriptor, WireAlignItems, WireContainerNode,
|
||||
WireDirection, WireDisplayHint, WireDisplayHintKind, WireJustifyContent, WireKeyValue,
|
||||
WireLayoutChild, WireLayoutNode, WireSizing, WireValue, WireWidgetState,
|
||||
decode_client_message, decode_server_message, encode, encode_client,
|
||||
};
|
||||
|
||||
#[test]
|
||||
@@ -11,6 +12,8 @@ fn screen_update_round_trips() {
|
||||
direction: WireDirection::Row,
|
||||
gap: 4,
|
||||
padding: 2,
|
||||
justify_content: WireJustifyContent::Start,
|
||||
align_items: WireAlignItems::Stretch,
|
||||
children: vec![
|
||||
WireLayoutChild {
|
||||
sizing: WireSizing::Flex(1),
|
||||
@@ -24,7 +27,7 @@ fn screen_update_round_trips() {
|
||||
}),
|
||||
widgets: vec![WidgetDescriptor {
|
||||
id: 1,
|
||||
display_hint: WireDisplayHint::IconValue,
|
||||
display_hint: WireDisplayHint::new(WireDisplayHintKind::IconValue),
|
||||
state: WireWidgetState {
|
||||
data: vec![
|
||||
WireKeyValue {
|
||||
@@ -52,7 +55,7 @@ fn data_update_round_trips() {
|
||||
let msg = ServerMessage::DataUpdate {
|
||||
widgets: vec![WidgetDescriptor {
|
||||
id: 3,
|
||||
display_hint: WireDisplayHint::TextBlock,
|
||||
display_hint: WireDisplayHint::new(WireDisplayHintKind::TextBlock),
|
||||
state: WireWidgetState {
|
||||
data: vec![WireKeyValue {
|
||||
key: "body".into(),
|
||||
|
||||
Reference in New Issue
Block a user