From a0fbbc62577718ab513cf7ef6e3eed2e26644438 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Fri, 13 Sep 2024 02:37:21 +0300 Subject: [PATCH] split Outset into 2 phases --- crates/tek_core/examples/demo.rs | 57 +++++++++++++++++++++++++++----- crates/tek_core/src/demo.rs | 0 crates/tek_core/src/tui.rs | 41 +++++++++++++++-------- 3 files changed, 76 insertions(+), 22 deletions(-) delete mode 100644 crates/tek_core/src/demo.rs diff --git a/crates/tek_core/examples/demo.rs b/crates/tek_core/examples/demo.rs index 91405159..ab7e6d1f 100644 --- a/crates/tek_core/examples/demo.rs +++ b/crates/tek_core/examples/demo.rs @@ -37,25 +37,66 @@ impl Content for Demo { type Engine = Tui; fn content (&self) -> impl Widget { Layers::new(|add|{ - add(&FillBg(Color::Rgb(128,0,0)))?; - add(&Outset::X(1, "foo"))?; + + add(&FillBg(Color::Rgb(0,128,128)))?; + + add(&Outset::XY(1, 1, Split::down(|add|{ + + add(&Layers::new(|add|{ + add(&FillBg(Color::Rgb(255,0,0)))?; + add(&Outset::X(1, "."))?; + Ok(()) + }))?; + + add(&Layers::new(|add|{ + add(&FillBg(Color::Rgb(255,128,0)))?; + add(&Outset::Y(1, "---"))?; + Ok(()) + }))?; + + add(&Layers::new(|add|{ + add(&FillBg(Color::Rgb(128,0,0)))?; + add(&Outset::XY(0, 0, "~~~"))?; + Ok(()) + }))?; + + Ok(()) + })))?; + Ok(()) + }) + //Align::Center(Outset::X(1, Layers::new(|add|{ + //add(&FillBg(Color::Rgb(128,0,0)))?; + //add(&Split::down(|add|{ + //add(&Outset::Y(1, Layers::new(|add|{ + //add(&FillBg(Color::Rgb(0,128,0)))?; + //add(&Align::Center("12345"))?; + //add(&Align::Center("FOO")) + //})))?; + //add(&Outset::XY(1, 1, Layers::new(|add|{ + //add(&Align::Center("1234567"))?; + //add(&Align::Center("BAR"))?; + //add(&FillBg(Color::Rgb(0,0,128))) + //}))) + //})) + //}))) + //Align::Y(Layers::new(|add|{ //add(&FillBg(Color::Rgb(128,0,0)))?; //add(&Outset::X(1, Align::Center(Split::down(|add|{ - //add(&Align::X(Layers::new(|add|{ + //add(&Align::X(Outset::Y(1, Layers::new(|add|{ //add(&FillBg(Color::Rgb(0,128,0)))?; - //add(&Outset::Y(1, Align::Center("12345")))?; + //add(&Align::Center("12345"))?; //add(&Align::Center("FOO")) //})))?; - //add(&Layers::new(|add|{ - //add(&Outset::XY(1, 1, Align::Center("1234567")))?; + //add(&Outset::XY(1, 1, Layers::new(|add|{ + //add(&Align::Center("1234567"))?; //add(&Align::Center("BAR"))?; //add(&FillBg(Color::Rgb(0,0,128))) - //}))?; + //})))?; //Ok(()) - //})))) + //}))))) //})) } } diff --git a/crates/tek_core/src/demo.rs b/crates/tek_core/src/demo.rs deleted file mode 100644 index e69de29b..00000000 diff --git a/crates/tek_core/src/tui.rs b/crates/tek_core/src/tui.rs index 2bdfbc21..4a6ade8b 100644 --- a/crates/tek_core/src/tui.rs +++ b/crates/tek_core/src/tui.rs @@ -568,12 +568,8 @@ where Ok(Some([x, y, w, h])) } fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { - let layout = self.layout(to.area())?; self.layout(to.area())? - .map(|area|(self.0)(&mut |layer| { - to.render_in(area, &layer)?; - Ok(()) - }).map(|_|area)) + .map(|area|(self.0)(&mut |layer|to.render_in(area, &layer).map(|_|())).map(|_|area)) .transpose() } } @@ -606,19 +602,36 @@ impl> Content for Inset { //} //} -impl> Content for Outset { +impl> Widget for Outset { type Engine = Tui; - fn content (&self) -> impl Widget { + fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> { match *self { - Self::X(x, ref inner) => - Grow::X(x + x, inner as &dyn Widget), - Self::Y(y, ref inner) => - Grow::Y(y + y, inner as &dyn Widget), - Self::XY(x, y, ref inner) => - Grow::XY(x, y, inner as &dyn Widget), - } + Self::X(x, ref inner) => Grow::X(x + x, inner as &dyn Widget), + Self::Y(y, ref inner) => Grow::Y(y + y, inner as &dyn Widget), + Self::XY(x, y, ref inner) => Grow::XY(x + x, y + y, inner as &dyn Widget), + }.layout(to) + } + fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { + match *self { + Self::X(x, ref inner) => Plus::X(x, inner as &dyn Widget), + Self::Y(y, ref inner) => Plus::Y(y, inner as &dyn Widget), + Self::XY(x, y, ref inner) => Plus::XY(x, y, inner as &dyn Widget), + }.render(to) } } +//impl> Content for Outset { + //type Engine = Tui; + //fn content (&self) -> impl Widget { + //match *self { + //Self::X(x, ref inner) => + //Grow::X(x + x, inner as &dyn Widget), + //Self::Y(y, ref inner) => + //Grow::Y(y + y, inner as &dyn Widget), + //Self::XY(x, y, ref inner) => + //Grow::XY(x, y, inner as &dyn Widget), + //} + //} +//} pub trait BorderStyle { const NW: &'static str = "";