From 281900fe61d7df4c18826576a3ed56064e914e45 Mon Sep 17 00:00:00 2001 From: TerraMaster85 Date: Thu, 16 Jul 2026 22:26:56 -0400 Subject: [PATCH] fmt: all --- .rustfmt.toml | 2 ++ examples/empty_container.rs | 2 +- src/elements/container.rs | 15 ++++++++------- src/elements/element.rs | 11 +++++++++-- src/elements/macros.rs | 29 +++++++++++++++++++---------- src/elements/mod.rs | 1 - src/error.rs | 4 +--- src/tests.rs | 1 + 8 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000000000000000000000000000000000000..4cca3bdfeca7aca42ac5afd425c1bb5f5329c5cc --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,2 @@ +max_width = 80 +edition = "2024" diff --git a/examples/empty_container.rs b/examples/empty_container.rs index 2e9b42ff48fbc74961defd899d385bb9b9d9dfe5..a582c9e4932034666a491e6e780a653bd772ae0e 100644 --- a/examples/empty_container.rs +++ b/examples/empty_container.rs @@ -1,6 +1,6 @@ extern crate lintuini; -use lintuini::elements::Element; use lintuini::elements::Container; +use lintuini::elements::Element; use crossterm::event; diff --git a/src/elements/container.rs b/src/elements/container.rs index 4892dcaee12c0c027766a4c803477d86c996d237..872285a9bbd7f12d3cd9805f8dafe2269dfb75bc 100644 --- a/src/elements/container.rs +++ b/src/elements/container.rs @@ -1,11 +1,9 @@ use ratatui_core::layout; use ratatui_core::terminal::Frame; -use ratatui_widgets::block; - -use crate::error; -use crate::elements::{Element, ElementWithChildren}; use crate::elements::macros::*; +use crate::elements::{Element, ElementWithChildren}; +use crate::error; #[derive(Default)] pub struct Container<'a> { @@ -17,7 +15,7 @@ pub struct Container<'a> { #[derive(Clone, Default)] struct ContainerWidgets<'a> { - block0: block::Block<'a>, + block0: ratatui_widgets::block::Block<'a>, } basic_config_methods!(Container<'_>); @@ -29,7 +27,11 @@ impl Element for Container<'_> { self.constraint } - fn render(&self, frm: &mut Frame, rect: layout::Rect) -> Result<(), error::LintuiniError> { + fn render( + &self, + frm: &mut Frame, + rect: layout::Rect, + ) -> Result<(), error::LintuiniError> { frm.render_widget(&self.widgets.block0, rect); for (el, r) in self.children.iter().zip(&*self.layout.split(rect)) { @@ -39,4 +41,3 @@ impl Element for Container<'_> { Ok(()) } } - diff --git a/src/elements/element.rs b/src/elements/element.rs index 6fdd529c69547a431d3fb096041ca1a3799f88e2..c472415defa15fec9f2dbe31a4b4696c8428c960 100644 --- a/src/elements/element.rs +++ b/src/elements/element.rs @@ -5,11 +5,18 @@ use crate::error; pub trait Element { fn constraint(&self) -> layout::Constraint; - fn render(&self, frm: &mut Frame, rect: layout::Rect) -> Result<(), error::LintuiniError>; + fn render( + &self, + frm: &mut Frame, + rect: layout::Rect, + ) -> Result<(), error::LintuiniError>; } pub trait ElementWithChildren: Element { - fn add_child(&mut self, child: impl Into>) -> 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]; } diff --git a/src/elements/macros.rs b/src/elements/macros.rs index 42cea00df8e26f59aa5b492bf886fa84db51efe0..48e69fb4d35bb66657eb5e4d03ea6c27bbfc081c 100644 --- a/src/elements/macros.rs +++ b/src/elements/macros.rs @@ -2,7 +2,10 @@ macro_rules! element_with_children { ($el:ty) => { impl ElementWithChildren for $el { #[inline(always)] - fn add_child(&mut self, child: impl Into>) -> Result<(), crate::error::LintuiniError>{ + fn add_child( + &mut self, + child: impl Into>, + ) -> Result<(), crate::error::LintuiniError> { self.children.push(child.into()); self.regenerate_layout(); Ok(()) @@ -18,12 +21,12 @@ macro_rules! element_with_children { self.children.as_mut_slice() } } - } + }; } pub(crate) use element_with_children; macro_rules! basic_config_methods { - ($el:ty) => { + ($el:ty) => { impl $el { #[inline(always)] pub fn new() -> Self { @@ -31,29 +34,35 @@ macro_rules! basic_config_methods { } #[inline(always)] - pub fn constraint(&mut self, constraint: ratatui_core::layout::Constraint) -> &mut Self { + pub fn constraint( + &mut self, + constraint: ratatui_core::layout::Constraint, + ) -> &mut Self { self.constraint = constraint; self } // beware the owned self! #[inline(always)] - pub fn direction(mut self, direction: ratatui_core::layout::Direction) -> Self { + pub fn direction( + mut self, + direction: ratatui_core::layout::Direction, + ) -> Self { self.layout = self.layout.direction(direction); self.regenerate_layout(); self } pub fn regenerate_layout(&mut self) -> &mut Self { - if self.children.len() == 0 { return self; } + if self.children.len() == 0 { + return self; + } self.layout = self.layout.clone().constraints( - self.children - .iter() - .map(|el| el.constraint()) + self.children.iter().map(|el| el.constraint()), ); self } } - } + }; } pub(crate) use basic_config_methods; diff --git a/src/elements/mod.rs b/src/elements/mod.rs index 0a6e194da33cdb3da3bb1d086a9db05029d7fd89..796466cd9d7d34935cfdc1815c42848de9494388 100644 --- a/src/elements/mod.rs +++ b/src/elements/mod.rs @@ -5,4 +5,3 @@ pub mod element; pub use element::*; pub mod macros; - diff --git a/src/error.rs b/src/error.rs index 71c40a5c5356afe9afdd0f9126f15f454a53b16f..c3b165db427f7d69c0c1e5489c28d42e2e25c9b6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -15,6 +15,4 @@ pub enum ElementError { } #[derive(Debug, Error)] -pub enum RenderError { - -} +pub enum RenderError {} diff --git a/src/tests.rs b/src/tests.rs index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..8b137891791fe96927ad78e64b0aad7bded08bdc 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -0,0 +1 @@ +