new rendering engine
This commit is contained in:
@@ -15,6 +15,7 @@ pub use ports::{
|
||||
EventPublisher, PasswordHashPort, SecretStore, WidgetStateReader,
|
||||
};
|
||||
pub use value_objects::{
|
||||
ContainerNode, Direction, DisplayHint, KeyMapping, Layout, LayoutChild, LayoutNode,
|
||||
LayoutValidationError, Sizing, Value, WidgetError, WidgetState,
|
||||
AlignItems, ContainerNode, Direction, DisplayHint, DisplayHintKind, HAlign, JustifyContent,
|
||||
KeyMapping, Layout, LayoutChild, LayoutNode, LayoutValidationError, Sizing, VAlign, Value,
|
||||
WidgetError, WidgetState,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::entities::WidgetId;
|
||||
use crate::value_objects::{Layout, WidgetState};
|
||||
use crate::value_objects::{DisplayHint, Layout, WidgetState};
|
||||
use std::future::Future;
|
||||
|
||||
pub trait BroadcastPort {
|
||||
@@ -8,11 +8,11 @@ pub trait BroadcastPort {
|
||||
fn push_screen_update(
|
||||
&self,
|
||||
layout: &Layout,
|
||||
widgets: &[(WidgetId, WidgetState)],
|
||||
widgets: &[(WidgetId, DisplayHint, WidgetState)],
|
||||
) -> impl Future<Output = Result<(), Self::Error>> + Send;
|
||||
|
||||
fn push_data_update(
|
||||
&self,
|
||||
updates: &[(WidgetId, WidgetState)],
|
||||
updates: &[(WidgetId, DisplayHint, WidgetState)],
|
||||
) -> impl Future<Output = Result<(), Self::Error>> + Send;
|
||||
}
|
||||
|
||||
@@ -13,11 +13,30 @@ pub enum Direction {
|
||||
Column,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum JustifyContent {
|
||||
Start,
|
||||
Center,
|
||||
End,
|
||||
SpaceBetween,
|
||||
SpaceEvenly,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum AlignItems {
|
||||
Start,
|
||||
Center,
|
||||
End,
|
||||
Stretch,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ContainerNode {
|
||||
pub direction: Direction,
|
||||
pub gap: u8,
|
||||
pub padding: u8,
|
||||
pub justify_content: JustifyContent,
|
||||
pub align_items: AlignItems,
|
||||
pub children: Vec<LayoutChild>,
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ mod widget_state;
|
||||
|
||||
pub use key_mapping::KeyMapping;
|
||||
pub use layout::{
|
||||
ContainerNode, Direction, Layout, LayoutChild, LayoutNode, LayoutValidationError, Sizing,
|
||||
AlignItems, ContainerNode, Direction, JustifyContent, Layout, LayoutChild, LayoutNode,
|
||||
LayoutValidationError, Sizing,
|
||||
};
|
||||
pub use value::Value;
|
||||
pub use widget_state::{DisplayHint, WidgetError, WidgetState};
|
||||
pub use widget_state::{DisplayHint, DisplayHintKind, HAlign, VAlign, WidgetError, WidgetState};
|
||||
|
||||
@@ -13,8 +13,39 @@ pub enum WidgetError {
|
||||
ExtractionFailed,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum HAlign {
|
||||
Left,
|
||||
Center,
|
||||
Right,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum VAlign {
|
||||
Top,
|
||||
Middle,
|
||||
Bottom,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum DisplayHint {
|
||||
pub struct DisplayHint {
|
||||
pub kind: DisplayHintKind,
|
||||
pub h_align: HAlign,
|
||||
pub v_align: VAlign,
|
||||
}
|
||||
|
||||
impl DisplayHint {
|
||||
pub fn new(kind: DisplayHintKind) -> Self {
|
||||
Self {
|
||||
kind,
|
||||
h_align: HAlign::Left,
|
||||
v_align: VAlign::Top,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum DisplayHintKind {
|
||||
IconValue,
|
||||
TextBlock,
|
||||
KeyValue,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use domain::{
|
||||
ContainerNode, Direction, Layout, LayoutChild, LayoutNode, LayoutValidationError, Sizing,
|
||||
WidgetId,
|
||||
AlignItems, ContainerNode, Direction, JustifyContent, Layout, LayoutChild, LayoutNode,
|
||||
LayoutValidationError, Sizing, WidgetId,
|
||||
};
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
@@ -16,6 +16,8 @@ fn row(children: Vec<LayoutChild>) -> LayoutNode {
|
||||
direction: Direction::Row,
|
||||
gap: 0,
|
||||
padding: 0,
|
||||
justify_content: JustifyContent::Start,
|
||||
align_items: AlignItems::Stretch,
|
||||
children,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use domain::{DisplayHint, KeyMapping, Value, WidgetConfig};
|
||||
use domain::{DisplayHint, DisplayHintKind, KeyMapping, Value, WidgetConfig};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[test]
|
||||
@@ -6,7 +6,7 @@ fn extract_applies_all_mappings_to_produce_widget_state() {
|
||||
let config = WidgetConfig {
|
||||
id: 1,
|
||||
name: "weather".into(),
|
||||
display_hint: DisplayHint::IconValue,
|
||||
display_hint: DisplayHint::new(DisplayHintKind::IconValue),
|
||||
data_source_id: 1,
|
||||
mappings: vec![
|
||||
KeyMapping {
|
||||
@@ -51,7 +51,7 @@ fn extract_truncates_string_values_exceeding_max_data_size() {
|
||||
let config = WidgetConfig {
|
||||
id: 1,
|
||||
name: "news".into(),
|
||||
display_hint: DisplayHint::TextBlock,
|
||||
display_hint: DisplayHint::new(DisplayHintKind::TextBlock),
|
||||
data_source_id: 1,
|
||||
mappings: vec![KeyMapping {
|
||||
source_path: "$.text".into(),
|
||||
@@ -74,7 +74,7 @@ fn extract_respects_max_data_size_across_total_state() {
|
||||
let config = WidgetConfig {
|
||||
id: 1,
|
||||
name: "big".into(),
|
||||
display_hint: DisplayHint::TextBlock,
|
||||
display_hint: DisplayHint::new(DisplayHintKind::TextBlock),
|
||||
data_source_id: 1,
|
||||
mappings: vec![
|
||||
KeyMapping {
|
||||
@@ -109,7 +109,7 @@ fn extract_skips_mappings_that_dont_match() {
|
||||
let config = WidgetConfig {
|
||||
id: 1,
|
||||
name: "weather".into(),
|
||||
display_hint: DisplayHint::IconValue,
|
||||
display_hint: DisplayHint::new(DisplayHintKind::IconValue),
|
||||
data_source_id: 1,
|
||||
mappings: vec![
|
||||
KeyMapping {
|
||||
|
||||
Reference in New Issue
Block a user