add SPA config UI, wire media/rss adapters, event-driven layout push
- React SPA: dashboard, data sources CRUD, widgets CRUD, layout builder, presets. TanStack Router + Query, shadcn/ui, Vite proxy to :3000 - wire media + rss adapters into polling loop, remove xtb source type - media adapter: read username/password from headers, proper subsonic auth - event handler: subscribe to LayoutChanged, push screen update to clients - fix clippy warnings across workspace (Default impls, collapsible ifs, redundant closures, is_none_or, unused imports)
This commit is contained in:
@@ -8,10 +8,20 @@ pub struct BoundingBox {
|
||||
|
||||
impl BoundingBox {
|
||||
pub fn new(x: u16, y: u16, width: u16, height: u16) -> Self {
|
||||
Self { x, y, width, height }
|
||||
Self {
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn screen(width: u16, height: u16) -> Self {
|
||||
Self { x: 0, y: 0, width, height }
|
||||
Self {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width,
|
||||
height,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
use domain::{LayoutNode, ContainerNode, Direction, Sizing};
|
||||
use crate::{BoundingBox, RenderTree};
|
||||
use domain::{ContainerNode, Direction, LayoutNode, Sizing};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct LayoutEngine;
|
||||
|
||||
@@ -11,11 +11,7 @@ impl LayoutEngine {
|
||||
RenderTree { widget_bounds }
|
||||
}
|
||||
|
||||
fn compute_node(
|
||||
node: &LayoutNode,
|
||||
bounds: BoundingBox,
|
||||
out: &mut HashMap<u16, BoundingBox>,
|
||||
) {
|
||||
fn compute_node(node: &LayoutNode, bounds: BoundingBox, out: &mut HashMap<u16, BoundingBox>) {
|
||||
match node {
|
||||
LayoutNode::Leaf(id) => {
|
||||
out.insert(*id, bounds);
|
||||
@@ -48,16 +44,22 @@ impl LayoutEngine {
|
||||
let total_gap = container.gap as u16 * (children.len() as u16).saturating_sub(1);
|
||||
let available = total_axis.saturating_sub(total_gap);
|
||||
|
||||
let fixed_total: u16 = children.iter().map(|c| match c.sizing {
|
||||
Sizing::Fixed(px) => px,
|
||||
Sizing::Flex(_) => 0,
|
||||
}).sum();
|
||||
let fixed_total: u16 = children
|
||||
.iter()
|
||||
.map(|c| match c.sizing {
|
||||
Sizing::Fixed(px) => px,
|
||||
Sizing::Flex(_) => 0,
|
||||
})
|
||||
.sum();
|
||||
|
||||
let flex_space = available.saturating_sub(fixed_total);
|
||||
let flex_total: u16 = children.iter().map(|c| match c.sizing {
|
||||
Sizing::Flex(w) => w as u16,
|
||||
Sizing::Fixed(_) => 0,
|
||||
}).sum();
|
||||
let flex_total: u16 = children
|
||||
.iter()
|
||||
.map(|c| match c.sizing {
|
||||
Sizing::Flex(w) => w as u16,
|
||||
Sizing::Fixed(_) => 0,
|
||||
})
|
||||
.sum();
|
||||
|
||||
let mut offset = 0u16;
|
||||
|
||||
@@ -74,19 +76,9 @@ impl LayoutEngine {
|
||||
};
|
||||
|
||||
let child_bounds = if is_row {
|
||||
BoundingBox::new(
|
||||
inner.x + offset,
|
||||
inner.y,
|
||||
child_size,
|
||||
inner.height,
|
||||
)
|
||||
BoundingBox::new(inner.x + offset, inner.y, child_size, inner.height)
|
||||
} else {
|
||||
BoundingBox::new(
|
||||
inner.x,
|
||||
inner.y + offset,
|
||||
inner.width,
|
||||
child_size,
|
||||
)
|
||||
BoundingBox::new(inner.x, inner.y + offset, inner.width, child_size)
|
||||
};
|
||||
|
||||
Self::compute_node(&child.node, child_bounds, out);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
mod bounding_box;
|
||||
mod layout_engine;
|
||||
mod render_tree;
|
||||
pub mod ports;
|
||||
mod render_tree;
|
||||
|
||||
pub use bounding_box::BoundingBox;
|
||||
pub use layout_engine::LayoutEngine;
|
||||
pub use ports::{ClientConfig, DisplayPort, NetworkPort, StoragePort};
|
||||
pub use render_tree::RenderTree;
|
||||
pub use ports::{DisplayPort, NetworkPort, StoragePort, ClientConfig};
|
||||
|
||||
@@ -4,7 +4,13 @@ pub trait DisplayPort {
|
||||
type Error;
|
||||
|
||||
fn clear_region(&mut self, bounds: BoundingBox) -> Result<(), Self::Error>;
|
||||
fn draw_text(&mut self, text: &str, x: u16, y: u16, bounds: BoundingBox) -> Result<(), Self::Error>;
|
||||
fn draw_text(
|
||||
&mut self,
|
||||
text: &str,
|
||||
x: u16,
|
||||
y: u16,
|
||||
bounds: BoundingBox,
|
||||
) -> Result<(), Self::Error>;
|
||||
fn draw_icon(&mut self, icon: &str, x: u16, y: u16) -> Result<(), Self::Error>;
|
||||
fn fill_background(&mut self, bounds: BoundingBox) -> Result<(), Self::Error>;
|
||||
fn flush(&mut self) -> Result<(), Self::Error>;
|
||||
|
||||
@@ -4,4 +4,4 @@ mod storage;
|
||||
|
||||
pub use display::DisplayPort;
|
||||
pub use network::NetworkPort;
|
||||
pub use storage::{StoragePort, ClientConfig};
|
||||
pub use storage::{ClientConfig, StoragePort};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
use domain::WidgetId;
|
||||
use crate::BoundingBox;
|
||||
use domain::WidgetId;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct RenderTree {
|
||||
pub widget_bounds: HashMap<WidgetId, BoundingBox>,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use domain::{
|
||||
LayoutNode, ContainerNode, LayoutChild, Direction, Sizing,
|
||||
};
|
||||
use client_domain::{BoundingBox, LayoutEngine, RenderTree};
|
||||
use domain::{ContainerNode, Direction, LayoutChild, LayoutNode, Sizing};
|
||||
|
||||
fn screen() -> BoundingBox {
|
||||
BoundingBox::screen(240, 320)
|
||||
@@ -73,9 +71,18 @@ fn row_splits_width_among_equal_flex_children() {
|
||||
let layout = row(vec![leaf(1), leaf(2), leaf(3)]);
|
||||
let tree = LayoutEngine::compute(&layout, screen());
|
||||
|
||||
assert_eq!(tree.get_widget_bounds(1), Some(&BoundingBox::new(0, 0, 80, 320)));
|
||||
assert_eq!(tree.get_widget_bounds(2), Some(&BoundingBox::new(80, 0, 80, 320)));
|
||||
assert_eq!(tree.get_widget_bounds(3), Some(&BoundingBox::new(160, 0, 80, 320)));
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(1),
|
||||
Some(&BoundingBox::new(0, 0, 80, 320))
|
||||
);
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(2),
|
||||
Some(&BoundingBox::new(80, 0, 80, 320))
|
||||
);
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(3),
|
||||
Some(&BoundingBox::new(160, 0, 80, 320))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -83,8 +90,14 @@ fn column_splits_height_among_equal_flex_children() {
|
||||
let layout = column(vec![leaf(1), leaf(2)]);
|
||||
let tree = LayoutEngine::compute(&layout, screen());
|
||||
|
||||
assert_eq!(tree.get_widget_bounds(1), Some(&BoundingBox::new(0, 0, 240, 160)));
|
||||
assert_eq!(tree.get_widget_bounds(2), Some(&BoundingBox::new(0, 160, 240, 160)));
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(1),
|
||||
Some(&BoundingBox::new(0, 0, 240, 160))
|
||||
);
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(2),
|
||||
Some(&BoundingBox::new(0, 160, 240, 160))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -92,8 +105,14 @@ fn fixed_and_flex_children_coexist() {
|
||||
let layout = row(vec![leaf_fixed(1, 40), leaf(2)]);
|
||||
let tree = LayoutEngine::compute(&layout, screen());
|
||||
|
||||
assert_eq!(tree.get_widget_bounds(1), Some(&BoundingBox::new(0, 0, 40, 320)));
|
||||
assert_eq!(tree.get_widget_bounds(2), Some(&BoundingBox::new(40, 0, 200, 320)));
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(1),
|
||||
Some(&BoundingBox::new(0, 0, 40, 320))
|
||||
);
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(2),
|
||||
Some(&BoundingBox::new(40, 0, 200, 320))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -102,8 +121,14 @@ fn gap_is_subtracted_before_distributing_space() {
|
||||
let layout = row_with_gap(10, vec![leaf(1), leaf(2)]);
|
||||
let tree = LayoutEngine::compute(&layout, screen());
|
||||
|
||||
assert_eq!(tree.get_widget_bounds(1), Some(&BoundingBox::new(0, 0, 115, 320)));
|
||||
assert_eq!(tree.get_widget_bounds(2), Some(&BoundingBox::new(125, 0, 115, 320)));
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(1),
|
||||
Some(&BoundingBox::new(0, 0, 115, 320))
|
||||
);
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(2),
|
||||
Some(&BoundingBox::new(125, 0, 115, 320))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -112,7 +137,10 @@ fn padding_insets_available_area() {
|
||||
let layout = row_with_padding(10, vec![leaf(1)]);
|
||||
let tree = LayoutEngine::compute(&layout, screen());
|
||||
|
||||
assert_eq!(tree.get_widget_bounds(1), Some(&BoundingBox::new(10, 10, 220, 300)));
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(1),
|
||||
Some(&BoundingBox::new(10, 10, 220, 300))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -125,9 +153,18 @@ fn nested_containers_compute_correctly() {
|
||||
let layout = row(vec![leaf(1), inner_col]);
|
||||
let tree = LayoutEngine::compute(&layout, screen());
|
||||
|
||||
assert_eq!(tree.get_widget_bounds(1), Some(&BoundingBox::new(0, 0, 120, 320)));
|
||||
assert_eq!(tree.get_widget_bounds(2), Some(&BoundingBox::new(120, 0, 120, 160)));
|
||||
assert_eq!(tree.get_widget_bounds(3), Some(&BoundingBox::new(120, 160, 120, 160)));
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(1),
|
||||
Some(&BoundingBox::new(0, 0, 120, 320))
|
||||
);
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(2),
|
||||
Some(&BoundingBox::new(120, 0, 120, 160))
|
||||
);
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(3),
|
||||
Some(&BoundingBox::new(120, 160, 120, 160))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -138,14 +175,32 @@ fn weighted_flex_distributes_proportionally() {
|
||||
gap: 0,
|
||||
padding: 0,
|
||||
children: vec![
|
||||
LayoutChild { sizing: Sizing::Flex(1), node: LayoutNode::Leaf(1) },
|
||||
LayoutChild { sizing: Sizing::Flex(2), node: LayoutNode::Leaf(2) },
|
||||
LayoutChild { sizing: Sizing::Flex(1), node: LayoutNode::Leaf(3) },
|
||||
LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
node: LayoutNode::Leaf(1),
|
||||
},
|
||||
LayoutChild {
|
||||
sizing: Sizing::Flex(2),
|
||||
node: LayoutNode::Leaf(2),
|
||||
},
|
||||
LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
node: LayoutNode::Leaf(3),
|
||||
},
|
||||
],
|
||||
});
|
||||
let tree = LayoutEngine::compute(&layout, screen());
|
||||
|
||||
assert_eq!(tree.get_widget_bounds(1), Some(&BoundingBox::new(0, 0, 60, 320)));
|
||||
assert_eq!(tree.get_widget_bounds(2), Some(&BoundingBox::new(60, 0, 120, 320)));
|
||||
assert_eq!(tree.get_widget_bounds(3), Some(&BoundingBox::new(180, 0, 60, 320)));
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(1),
|
||||
Some(&BoundingBox::new(0, 0, 60, 320))
|
||||
);
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(2),
|
||||
Some(&BoundingBox::new(60, 0, 120, 320))
|
||||
);
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(3),
|
||||
Some(&BoundingBox::new(180, 0, 60, 320))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use domain::{
|
||||
LayoutNode, ContainerNode, LayoutChild, Direction, Sizing,
|
||||
};
|
||||
use client_domain::{BoundingBox, LayoutEngine};
|
||||
use domain::{ContainerNode, Direction, LayoutChild, LayoutNode, Sizing};
|
||||
|
||||
fn screen() -> BoundingBox {
|
||||
BoundingBox::screen(240, 320)
|
||||
@@ -14,8 +12,14 @@ fn diff_detects_moved_widget_after_layout_change() {
|
||||
gap: 0,
|
||||
padding: 0,
|
||||
children: vec![
|
||||
LayoutChild { sizing: Sizing::Flex(1), node: LayoutNode::Leaf(1) },
|
||||
LayoutChild { sizing: Sizing::Flex(1), node: LayoutNode::Leaf(2) },
|
||||
LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
node: LayoutNode::Leaf(1),
|
||||
},
|
||||
LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
node: LayoutNode::Leaf(2),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -24,8 +28,14 @@ fn diff_detects_moved_widget_after_layout_change() {
|
||||
gap: 0,
|
||||
padding: 0,
|
||||
children: vec![
|
||||
LayoutChild { sizing: Sizing::Flex(1), node: LayoutNode::Leaf(1) },
|
||||
LayoutChild { sizing: Sizing::Flex(1), node: LayoutNode::Leaf(2) },
|
||||
LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
node: LayoutNode::Leaf(1),
|
||||
},
|
||||
LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
node: LayoutNode::Leaf(2),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -44,8 +54,14 @@ fn diff_returns_empty_for_identical_layouts() {
|
||||
gap: 0,
|
||||
padding: 0,
|
||||
children: vec![
|
||||
LayoutChild { sizing: Sizing::Flex(1), node: LayoutNode::Leaf(1) },
|
||||
LayoutChild { sizing: Sizing::Flex(1), node: LayoutNode::Leaf(2) },
|
||||
LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
node: LayoutNode::Leaf(1),
|
||||
},
|
||||
LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
node: LayoutNode::Leaf(2),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -61,18 +77,20 @@ fn diff_detects_added_and_removed_widgets() {
|
||||
direction: Direction::Row,
|
||||
gap: 0,
|
||||
padding: 0,
|
||||
children: vec![
|
||||
LayoutChild { sizing: Sizing::Flex(1), node: LayoutNode::Leaf(1) },
|
||||
],
|
||||
children: vec![LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
node: LayoutNode::Leaf(1),
|
||||
}],
|
||||
});
|
||||
|
||||
let layout_b = LayoutNode::Container(ContainerNode {
|
||||
direction: Direction::Row,
|
||||
gap: 0,
|
||||
padding: 0,
|
||||
children: vec![
|
||||
LayoutChild { sizing: Sizing::Flex(1), node: LayoutNode::Leaf(2) },
|
||||
],
|
||||
children: vec![LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
node: LayoutNode::Leaf(2),
|
||||
}],
|
||||
});
|
||||
|
||||
let tree_a = LayoutEngine::compute(&layout_a, screen());
|
||||
|
||||
Reference in New Issue
Block a user