From 3873712ae1cc616bff72c3dae4513bc21bf5f67f Mon Sep 17 00:00:00 2001 From: TerraMaster85 Date: Wed, 15 Jul 2026 22:27:53 -0400 Subject: [PATCH] feat: element.rs: wow it compiles again. api general idea now stable ish? --- examples/empty_container.rs | 6 +- src/elements/.container.rs.swp | Bin 0 -> 12288 bytes src/elements/.element.rs.swp | Bin 0 -> 12288 bytes src/elements/container.rs | 107 ++++++++++----------------------- src/elements/element.rs | 4 +- 5 files changed, 36 insertions(+), 81 deletions(-) create mode 100644 src/elements/.container.rs.swp create mode 100644 src/elements/.element.rs.swp diff --git a/examples/empty_container.rs b/examples/empty_container.rs index 8ac0af4924b83e220b23c989165c0f6fe899a736..f7f12062c3405cb74c6a547a928a99b849f33ec8 100644 --- a/examples/empty_container.rs +++ b/examples/empty_container.rs @@ -11,11 +11,7 @@ fn main() -> std::io::Result<()> { let fill = Style::default().bg(Color::Blue); let bord_style = Style::default().bg(Color::Green).fg(Color::Black); let bord_type = BorderType::Double; - let cont = lintuini::elements::ContainerBuilder::new() - .fill(fill) - .border_style(bord_style) - .border_type(bord_type) - .build(); + let cont = lintuini::elements::Container::new(); ratatui::run(|mut terminal| { loop { diff --git a/src/elements/.container.rs.swp b/src/elements/.container.rs.swp new file mode 100644 index 0000000000000000000000000000000000000000..d732bb03a6ed4d59dc5d92664a497581b191e665 GIT binary patch literal 12288 zcmeI2UuYaf9LFcET4RkZ76cVxY9!sO+e_LY)VUIF#AJhk}PlAHq`Llm=fAYtIP@IKN_jcwt zGr#%%ezS9z&dkusiw6j8{%!-%Jn2)+k^UFbWt2i~>dhqkvJsC}0%0&J~D*9`YjQutm=!`9;v9 zpOgD_K277kQNSo*6fg=H1&jhl0i%FXz$jo8FbWt2{?`gP6+#}miI5MrK?eN)fAahP zryYcR0p0_bz{_9`%z|OC8&J>(uHHt-m*6sZ1I&XtFbf#C4}8)`$VG4-ybhMZ8So4k z0y{u2_~TYWJ^~lOdGH!I2j;*8*bREYRQd=Kqk0yS_B_~2p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I8Htdb;VK0u1%Oex@G8^=CtP^cq)_m#OY|2J>4FL$; zOdxl|&dQv4z5HsaSoreAb9($}=Vp6gHUuC50SG_<0uX=z1R!v$1>9&xeB}ye>ni5! z=gh>j?&1Lf2tWV=5P$##AOHafKmY;|fWR#jP@xdt=Y*KQ&&l)u|IP3JU;O1K#}AHk zjx&yL9G^Juaopv&!*RjujyX0t9&!}>Jmo-x00bZa0SG_<0uX=z1Rwx`|5@PVL=d;3 zq2M5jL#xdo$z5xKKPc1jaFIGbmAwz|(l7n+$k1AKd)xo$O)hOMTrRn0x(dTVdD`VM z?do_*Q8J2Y!??6Rd7NLSvaPc`cKz03oA?fTYNgz)Zlmon zZgu?fFR2$<=9#9zDyO9^EB2}(9#MRweh{RV-|&U}Br+, +#[derive(Default)] +pub struct Container<'a> { children: Vec>, constraint: layout::Constraint, - direction: layout::Direction, - fill: style::Style, - layout: Option, + layout: layout::Layout, + widgets: ContainerWidgets<'a>, } -impl ElementWithChildren for Container { +impl ElementWithChildren for Container<'_> { #[inline(always)] - fn add_child(&mut self, child: Box) -> Result<(), error::LintuiniError>{ - self.children.push(child); + fn add_child(&mut self, child: impl Into>) -> Result<(), error::LintuiniError>{ + self.children.push(child.into()); + + Ok(()) } #[inline(always)] @@ -33,94 +34,52 @@ impl ElementWithChildren for Container { } } -impl Element for Container { +impl Element for Container<'_> { #[inline(always)] - fn constraint(&self) -> &layout::Constraint { - &self.constraint + fn constraint(&self) -> layout::Constraint { + self.constraint } fn render(&self, frm: &mut Frame, rect: layout::Rect) -> Result<(), error::LintuiniError> { - let blk = match &self.border { - Some(bs) => block::Block::bordered().style(self.fill).border_type(bs.kind).border_style(bs.style), - None => block::Block::new().style(self.fill), - }; + frm.render_widget(&self.widgets.block0, rect); - frm.render_widget(blk, rect); - - if self.layout.is_none() { - debug_assert!( - self.children.len() == 0, - "child count did not match number of layout fields" - ); - return Ok(()); + for (el, r) in self.children.iter().zip(&*self.layout.split(rect)) { + el.render(frm, *r); } - - // TODO: children - Ok(()) } } -#[derive(Default)] -pub struct ContainerBuilder { - border: Option, - constraint: layout::Constraint, - direction: layout::Direction, - fill: style::Style, -} - -impl ContainerBuilder { +impl Container<'_> { #[inline(always)] pub fn new() -> Self { - ContainerBuilder::default() - } - #[inline(always)] - pub fn fill(mut self, style: style::Style) -> Self { - self.fill = style; - self + Container::default() } + #[inline(always)] pub fn constraint(mut self, constraint: layout::Constraint) -> Self { self.constraint = constraint; self } + #[inline(always)] pub fn direction(mut self, direction: layout::Direction) -> Self { - self.direction = direction; - self - } - #[inline(always)] - pub fn border_style(mut self, style: style::Style) -> Self { - match self.border { - Some(mut bs) => { bs.style = style; }, - None => { self.border = Some(ContainerBorder { style: style, ..Default::default() }) }, - } - self - } - #[inline(always)] - pub fn border_type(mut self, kind: borders::BorderType) -> Self { - match self.border { - Some(mut bs) => { bs.kind = kind; }, - None => { self.border = Some(ContainerBorder { kind: kind, ..Default::default() }) }, - } - self + self.layout = self.layout.direction(direction); + self.regenerate_layout() } - #[inline(always)] - pub fn build(self) -> Container { - Container { - border: self.border, - constraint: self.constraint, - children: Vec::new(), - direction: self.direction, - fill: self.fill, - layout: None, - } + fn regenerate_layout(mut self) -> Self { + if self.children.len() == 0 { return self; } + self.layout = self.layout.constraints( + self.children + .iter() + .map(|el| el.constraint()) + ); + self } } -#[derive(Clone, Copy, Default)] -pub struct ContainerBorder { - style: style::Style, - kind: borders::BorderType, +#[derive(Clone, Default)] +struct ContainerWidgets<'a> { + block0: block::Block<'a>, } diff --git a/src/elements/element.rs b/src/elements/element.rs index e42ef96beb85f435a75c4372246d92f6a3ea848f..6fdd529c69547a431d3fb096041ca1a3799f88e2 100644 --- a/src/elements/element.rs +++ b/src/elements/element.rs @@ -4,12 +4,12 @@ use ratatui_core::terminal::Frame; use crate::error; pub trait Element { - fn constraint(&self) -> &layout::Constraint; + fn constraint(&self) -> layout::Constraint; fn render(&self, frm: &mut Frame, rect: layout::Rect) -> Result<(), error::LintuiniError>; } pub trait ElementWithChildren: Element { - fn add_child(&mut self, child: Box) -> Result<(), error::LintuiniError>; + fn add_child(&mut self, child: impl Into>) -> Result<(), error::LintuiniError>; fn children(&self) -> &[Box]; fn children_mut(&mut self) -> &mut [Box]; }