summaryrefslogtreecommitdiffstats
path: root/src/tuice/component/base/row.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tuice/component/base/row.rs')
-rw-r--r--src/tuice/component/base/row.rs53
1 files changed, 35 insertions, 18 deletions
diff --git a/src/tuice/component/base/row.rs b/src/tuice/component/base/row.rs
index dcdbf5d2..93c5b317 100644
--- a/src/tuice/component/base/row.rs
+++ b/src/tuice/component/base/row.rs
@@ -1,42 +1,59 @@
use tui::{backend::Backend, layout::Rect, Frame};
-use crate::tuice::{Bounds, Component, DrawContext, Event, Size, Status};
+use crate::tuice::{Bounds, Event, FlexElement, LayoutNode, Size, Status, TmpComponent};
#[derive(Default)]
-pub struct Row<'a, Message, B>
-where
- B: Backend,
-{
- children: Vec<Box<dyn Component<Message, B> + 'a>>, // FIXME: For performance purposes, let's cheat and use enum-dispatch
+pub struct Row<'a, Message> {
+ children: Vec<FlexElement<'a, Message>>,
}
-impl<'a, Message, B> Row<'a, Message, B>
-where
- B: Backend,
-{
+impl<'a, Message> Row<'a, Message> {
/// Creates a new [`Row`] with the given children.
pub fn with_children<C>(children: Vec<C>) -> Self
where
- C: Into<Box<dyn Component<Message, B> + 'a>>,
+ C: Into<FlexElement<'a, Message>>,
{
Self {
children: children.into_iter().map(Into::into).collect(),
}
}
+
+ pub fn with_child(mut self) -> Self {
+ self
+ }
+
+ pub fn with_flex_child(mut self) -> Self {
+ self
+ }
}
-impl<'a, Message, B> Component<Message, B> for Row<'a, Message, B>
-where
- B: Backend,
-{
- fn draw(&mut self, area: Rect, context: &DrawContext, frame: &mut Frame<'_, B>) {
+impl<'a, Message> TmpComponent<Message> for Row<'a, Message> {
+ fn draw<B>(&mut self, area: Rect, frame: &mut Frame<'_, B>)
+ where
+ B: Backend,
+ {
self.children.iter_mut().for_each(|child| {
- // TODO: This is just temp! We need layout!
- child.draw(area, context, frame);
+ child.draw(area, frame);
})
}
fn on_event(&mut self, _area: Rect, _event: Event, _messages: &mut Vec<Message>) -> Status {
Status::Ignored
}
+
+ fn layout(&self, bounds: Bounds, node: &mut LayoutNode) -> Size {
+ let mut remaining_bounds = bounds;
+
+ let child_nodes: Vec<LayoutNode> = self
+ .children
+ .iter()
+ .map(|child| {
+ let mut child_node = LayoutNode::default();
+ let size = child.layout(remaining_bounds, &mut child_node);
+ child_node
+ })
+ .collect();
+
+ todo!()
+ }
}