From 3e5dbb75fbb52539febdc683e88ec68ffca4cf30 Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Sat, 25 Dec 2021 04:00:04 -0500 Subject: [PATCH] Move over to datarow --- src/app.rs | 2 +- src/tuine/application.rs | 2 +- src/tuine/component/base/container.rs | 12 ++++---- src/tuine/component/base/flex/flex_element.rs | 16 +++++----- src/tuine/component/base/flex/mod.rs | 16 +++++----- .../component/base/text_table/data_cell.rs | 2 ++ .../component/base/text_table/data_row.rs | 21 +++++++++++-- src/tuine/component/base/text_table/mod.rs | 30 +++++++++++++++---- src/tuine/component/widget/temp_table.rs | 8 ++--- src/tuine/element.rs | 10 +++---- src/tuine/layout/build_layout.rs | 2 +- src/tuine/runtime.rs | 8 ++--- 12 files changed, 81 insertions(+), 48 deletions(-) diff --git a/src/app.rs b/src/app.rs index 2ca564d2..fdf7db0f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -238,7 +238,7 @@ impl Application for AppState { self.terminator.load(SeqCst) } - fn view<'b>(&mut self, ctx: &mut ViewContext<'_>) -> Element<'static, Self::Message> { + fn view<'b>(&mut self, ctx: &mut ViewContext<'_>) -> Element { use crate::tuine::FlexElement; use crate::tuine::TempTable; use crate::tuine::TextTable; diff --git a/src/tuine/application.rs b/src/tuine/application.rs index e2bb5815..6390abf0 100644 --- a/src/tuine/application.rs +++ b/src/tuine/application.rs @@ -21,7 +21,7 @@ pub trait Application: Sized { /// always returning false. fn is_terminated(&self) -> bool; - fn view<'b>(&mut self, ctx: &mut ViewContext<'_>) -> Element<'static, Self::Message>; + fn view<'b>(&mut self, ctx: &mut ViewContext<'_>) -> Element; /// To run upon stopping the application. fn destructor(&mut self) {} diff --git a/src/tuine/component/base/container.rs b/src/tuine/component/base/container.rs index 5e12572d..48261504 100644 --- a/src/tuine/component/base/container.rs +++ b/src/tuine/component/base/container.rs @@ -8,16 +8,16 @@ use crate::tuine::{ /// /// Inspired by Flutter's [Container class](https://api.flutter.dev/flutter/widgets/Container-class.html). #[derive(Default)] -pub struct Container<'a, Message> { +pub struct Container { width: Option, height: Option, - child: Option>>, + child: Option>>, } -impl<'a, Message> Container<'a, Message> { +impl Container { pub fn with_child(child: C) -> Self where - C: Into>, + C: Into>, { Self { width: None, @@ -28,7 +28,7 @@ impl<'a, Message> Container<'a, Message> { pub fn child(mut self, child: Option) -> Self where - C: Into>, + C: Into>, { self.child = child.map(|c| Box::new(c.into())); self @@ -45,7 +45,7 @@ impl<'a, Message> Container<'a, Message> { } } -impl<'a, Message> TmpComponent for Container<'a, Message> { +impl TmpComponent for Container { fn draw( &mut self, state_ctx: &mut StateContext<'_>, draw_ctx: &DrawContext<'_>, frame: &mut Frame<'_, B>, diff --git a/src/tuine/component/base/flex/flex_element.rs b/src/tuine/component/base/flex/flex_element.rs index baad1bda..deffc6a0 100644 --- a/src/tuine/component/base/flex/flex_element.rs +++ b/src/tuine/component/base/flex/flex_element.rs @@ -6,28 +6,28 @@ use crate::tuine::{ use super::Axis; -pub struct FlexElement<'a, Message> { +pub struct FlexElement { /// Represents a ratio with other [`FlexElement`]s on how far to expand. pub flex: u16, - element: Element<'a, Message>, + element: Element, } -impl<'a, Message> FlexElement<'a, Message> { - pub fn new>>(element: I) -> Self { +impl FlexElement { + pub fn new>>(element: I) -> Self { Self { flex: 1, element: element.into(), } } - pub fn with_flex>>(element: I, flex: u16) -> Self { + pub fn with_flex>>(element: I, flex: u16) -> Self { Self { flex, element: element.into(), } } - pub fn with_no_flex>>(element: I) -> Self { + pub fn with_no_flex>>(element: I) -> Self { Self { flex: 0, element: element.into(), @@ -86,8 +86,8 @@ impl<'a, Message> FlexElement<'a, Message> { } } -impl<'a, Message> From> for FlexElement<'a, Message> { - fn from(element: Element<'a, Message>) -> Self { +impl From> for FlexElement { + fn from(element: Element) -> Self { Self { flex: 0, element } } } diff --git a/src/tuine/component/base/flex/mod.rs b/src/tuine/component/base/flex/mod.rs index e07c83df..84584647 100644 --- a/src/tuine/component/base/flex/mod.rs +++ b/src/tuine/component/base/flex/mod.rs @@ -16,12 +16,12 @@ pub enum Axis { Vertical, } -pub struct Flex<'a, Message> { - children: Vec>, +pub struct Flex { + children: Vec>, alignment: Axis, } -impl<'a, Message> Flex<'a, Message> { +impl Flex { pub fn new(alignment: Axis) -> Self { Self { children: vec![], @@ -40,7 +40,7 @@ impl<'a, Message> Flex<'a, Message> { /// Creates a new [`Flex`] with a horizontal alignment with the given children. pub fn row_with_children(children: Vec) -> Self where - C: Into>, + C: Into>, { Self { children: children.into_iter().map(Into::into).collect(), @@ -59,7 +59,7 @@ impl<'a, Message> Flex<'a, Message> { /// Creates a new [`Flex`] with a vertical alignment with the given children. pub fn column_with_children(children: Vec) -> Self where - C: Into>, + C: Into>, { Self { children: children.into_iter().map(Into::into).collect(), @@ -69,7 +69,7 @@ impl<'a, Message> Flex<'a, Message> { pub fn with_child(mut self, child: E) -> Self where - E: Into>, + E: Into>, { self.children.push(FlexElement::with_no_flex(child.into())); self @@ -77,7 +77,7 @@ impl<'a, Message> Flex<'a, Message> { pub fn with_flex_child(mut self, child: E, flex: u16) -> Self where - E: Into>, + E: Into>, { self.children .push(FlexElement::with_flex(child.into(), flex)); @@ -85,7 +85,7 @@ impl<'a, Message> Flex<'a, Message> { } } -impl<'a, Message> TmpComponent for Flex<'a, Message> { +impl TmpComponent for Flex { fn draw( &mut self, state_ctx: &mut StateContext<'_>, draw_ctx: &DrawContext<'_>, frame: &mut Frame<'_, B>, diff --git a/src/tuine/component/base/text_table/data_cell.rs b/src/tuine/component/base/text_table/data_cell.rs index cd51f473..f52cabae 100644 --- a/src/tuine/component/base/text_table/data_cell.rs +++ b/src/tuine/component/base/text_table/data_cell.rs @@ -19,6 +19,7 @@ impl Numeric for u8 {} impl Numeric for usize {} #[allow(non_camel_case_types)] +#[derive(Clone, Copy)] #[enum_dispatch(Numeric)] pub enum Number { f64, @@ -54,6 +55,7 @@ impl Display for Number { } } +#[derive(Clone)] pub enum DataCell { NumberCell(Number), String(Cow<'static, str>), diff --git a/src/tuine/component/base/text_table/data_row.rs b/src/tuine/component/base/text_table/data_row.rs index a805c5d9..478d3c7e 100644 --- a/src/tuine/component/base/text_table/data_row.rs +++ b/src/tuine/component/base/text_table/data_row.rs @@ -1,15 +1,30 @@ -use tui::style::Style; +use tui::{style::Style, widgets::Row}; use super::DataCell; +#[derive(Clone)] pub struct DataRow { - cells: Vec, - style: Option