new rendering engine
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::error::SqliteConfigError;
|
||||
use domain::{ContainerNode, Direction, Layout, LayoutChild, LayoutNode, Sizing};
|
||||
use domain::{AlignItems, ContainerNode, Direction, JustifyContent, Layout, LayoutChild, LayoutNode, Sizing};
|
||||
|
||||
pub fn layout_to_json(layout: &Layout) -> Result<String, SqliteConfigError> {
|
||||
let v = node_to_json(&layout.root);
|
||||
@@ -97,6 +97,8 @@ fn node_from_json(v: &serde_json::Value) -> Result<LayoutNode, SqliteConfigError
|
||||
direction,
|
||||
gap,
|
||||
padding,
|
||||
justify_content: JustifyContent::Start,
|
||||
align_items: AlignItems::Stretch,
|
||||
children,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
use crate::error::SqliteConfigError;
|
||||
use domain::{DisplayHint, KeyMapping, WidgetConfig};
|
||||
use domain::{DisplayHint, DisplayHintKind, KeyMapping, WidgetConfig};
|
||||
use sqlx::Row;
|
||||
use sqlx::sqlite::SqliteRow;
|
||||
|
||||
pub fn display_hint_to_str(hint: &DisplayHint) -> &'static str {
|
||||
match hint {
|
||||
DisplayHint::IconValue => "icon_value",
|
||||
DisplayHint::TextBlock => "text_block",
|
||||
DisplayHint::KeyValue => "key_value",
|
||||
match hint.kind {
|
||||
DisplayHintKind::IconValue => "icon_value",
|
||||
DisplayHintKind::TextBlock => "text_block",
|
||||
DisplayHintKind::KeyValue => "key_value",
|
||||
}
|
||||
}
|
||||
|
||||
fn display_hint_from_str(s: &str) -> Result<DisplayHint, SqliteConfigError> {
|
||||
match s {
|
||||
"icon_value" => Ok(DisplayHint::IconValue),
|
||||
"text_block" => Ok(DisplayHint::TextBlock),
|
||||
"key_value" => Ok(DisplayHint::KeyValue),
|
||||
"icon_value" => Ok(DisplayHint::new(DisplayHintKind::IconValue)),
|
||||
"text_block" => Ok(DisplayHint::new(DisplayHintKind::TextBlock)),
|
||||
"key_value" => Ok(DisplayHint::new(DisplayHintKind::KeyValue)),
|
||||
_ => Err(SqliteConfigError::Serialization(format!(
|
||||
"unknown display hint: {s}"
|
||||
))),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use config_sqlite::SqliteConfigStore;
|
||||
use domain::{
|
||||
ConfigRepository, ContainerNode, DataSource, DataSourceConfig, DataSourceType, Direction,
|
||||
DisplayHint, KeyMapping, Layout, LayoutChild, LayoutNode, LayoutPreset, Sizing, WidgetConfig,
|
||||
AlignItems, ConfigRepository, ContainerNode, DataSource, DataSourceConfig, DataSourceType,
|
||||
Direction, DisplayHint, DisplayHintKind, JustifyContent, KeyMapping, Layout, LayoutChild, LayoutNode,
|
||||
LayoutPreset, Sizing, WidgetConfig,
|
||||
};
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -13,7 +14,7 @@ fn weather_widget() -> WidgetConfig {
|
||||
WidgetConfig {
|
||||
id: 1,
|
||||
name: "weather".into(),
|
||||
display_hint: DisplayHint::IconValue,
|
||||
display_hint: DisplayHint::new(DisplayHintKind::IconValue),
|
||||
data_source_id: 10,
|
||||
mappings: vec![
|
||||
KeyMapping {
|
||||
@@ -49,6 +50,8 @@ fn test_layout() -> Layout {
|
||||
direction: Direction::Row,
|
||||
gap: 4,
|
||||
padding: 2,
|
||||
justify_content: JustifyContent::Start,
|
||||
align_items: AlignItems::Stretch,
|
||||
children: vec![
|
||||
LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
@@ -71,7 +74,7 @@ async fn save_and_retrieve_widget() {
|
||||
let w = store.get_widget(1).await.unwrap().unwrap();
|
||||
assert_eq!(w.id, 1);
|
||||
assert_eq!(w.name, "weather");
|
||||
assert_eq!(w.display_hint, DisplayHint::IconValue);
|
||||
assert_eq!(w.display_hint, DisplayHint::new(DisplayHintKind::IconValue));
|
||||
assert_eq!(w.data_source_id, 10);
|
||||
assert_eq!(w.mappings.len(), 2);
|
||||
assert_eq!(w.mappings[0].source_path, "$.temp");
|
||||
@@ -92,7 +95,7 @@ async fn list_widgets_returns_all() {
|
||||
.save_widget(&WidgetConfig {
|
||||
id: 2,
|
||||
name: "portfolio".into(),
|
||||
display_hint: DisplayHint::KeyValue,
|
||||
display_hint: DisplayHint::new(DisplayHintKind::KeyValue),
|
||||
data_source_id: 20,
|
||||
mappings: vec![],
|
||||
max_data_size: 1024,
|
||||
|
||||
Reference in New Issue
Block a user