From c9b9ff15191ec3a37e8da35f382ce0d4af74d0d8 Mon Sep 17 00:00:00 2001 From: i do not exist Date: Fri, 17 Apr 2026 04:07:14 +0300 Subject: [PATCH] fix signatures of iter_ helpers --- examples/tui_00.rs | 24 ++++++++++----- src/color.rs | 4 +++ src/space.rs | 75 ++++++++++++++++++++++------------------------ 3 files changed, 56 insertions(+), 47 deletions(-) diff --git a/examples/tui_00.rs b/examples/tui_00.rs index ff2ca2d..929c56d 100644 --- a/examples/tui_00.rs +++ b/examples/tui_00.rs @@ -6,13 +6,6 @@ use ::{ tui_main!(State { cursor: 10, ..Default::default() }); -//namespace!(State: bool {}); -//namespace!(State: u16 {}); -//namespace!(State: Color {}); - //handle!(TuiIn: |self: State, input|Action::from(input).eval(self).map(|_|None)); - //view!(State: Tui: [ evaluate_output_expression, evaluate_output_expression_tui ]); - //draw!(State: Tui: [ draw_example ]); - impl Apply> for State { fn apply (&mut self, input: &TuiEvent) -> Usually { todo!() @@ -53,19 +46,27 @@ fn draw_example (state: &State, to: &mut Tui) { } impl Action { - const BINDS: &'static str = stringify! { (@left prev) (@right next) }; + + const BINDS: &'static str = stringify! { + (@left prev) + (@right next) + }; + fn eval (&self, state: &mut State) -> Perhaps { use Action::*; match self { Next => Self::next(state), Prev => Self::prev(state), } } + fn next (state: &mut State) -> Perhaps { state.cursor = (state.cursor + 1) % VIEWS.len(); Ok(Some(Self::Prev)) } + fn prev (state: &mut State) -> Perhaps { state.cursor = if state.cursor > 0 { state.cursor - 1 } else { VIEWS.len() - 1 }; Ok(Some(Self::Next)) } + } const VIEWS: &'static [&'static str] = &[ @@ -148,3 +149,10 @@ const VIEWS: &'static [&'static str] = &[ }, ]; + +//namespace!(State: bool {}); +//namespace!(State: u16 {}); +//namespace!(State: Color {}); + //handle!(TuiIn: |self: State, input|Action::from(input).eval(self).map(|_|None)); + //view!(State: Tui: [ evaluate_output_expression, evaluate_output_expression_tui ]); + //draw!(State: Tui: [ draw_example ]); diff --git a/src/color.rs b/src/color.rs index 13caf71..f16358a 100644 --- a/src/color.rs +++ b/src/color.rs @@ -11,6 +11,10 @@ pub fn rgb (r: u8, g: u8, b: u8) -> ItemColor { ItemColor { okhsl: rgb_to_okhsl(term), term } } +pub fn g (g: u8) -> Color { + Color::Rgb(g, g, g) +} + pub fn okhsl_to_rgb (color: Okhsl) -> Color { let Srgb { red, green, blue, .. }: Srgb = Srgb::from_color_unclamped(color); Color::Rgb((red * 255.0) as u8, (green * 255.0) as u8, (blue * 255.0) as u8,) diff --git a/src/space.rs b/src/space.rs index b3916a5..0bb159a 100644 --- a/src/space.rs +++ b/src/space.rs @@ -424,22 +424,26 @@ pub const fn w_full (a: impl Draw) -> impl Draw { a } pub const fn h_full (a: impl Draw) -> impl Draw { a } #[macro_export] macro_rules! north { - ($($tt:tt)*) => { unimplemented!() }; + ($head:expr $(,)?) => { $head }; + ($head:expr, $($tail:expr),* $(,)?) => { north($head, north!($($tail,)*)) }; } #[macro_export] macro_rules! south { - ($($tt:tt)*) => { unimplemented!() }; + ($head:expr $(,)?) => { $head }; + ($head:expr, $($tail:expr),* $(,)?) => { south($head, south!($($tail,)*)) }; } #[macro_export] macro_rules! east { - ($($tt:tt)*) => { unimplemented!() }; + ($head:expr $(,)?) => { $head }; + ($head:expr, $($tail:expr),* $(,)?) => { east($head, east!($($tail,)*)) }; } #[macro_export] macro_rules! west { - ($($tt:tt)*) => { unimplemented!() }; + ($head:expr $(, $tail:expr)* $(,)?) => { west($head, west!($($tail,)*)) }; } #[macro_export] macro_rules! above { - ($($tt:tt)*) => { unimplemented!() }; + ($head:expr $(, $tail:expr)* $(,)?) => { above($head, above!($($tail,)*)) }; } #[macro_export] macro_rules! below { - ($($tt:tt)*) => { unimplemented!() }; + ($head:expr $(,)?) => { $head }; + ($head:expr, $($tail:expr),* $(,)?) => { below($head, below!($($tail,)*)) }; } /// Iterate over a collection of renderables: @@ -453,44 +457,37 @@ pub const fn h_full (a: impl Draw) -> impl Draw { a } /// ].iter(), |x|x); /// ``` pub fn iter < - T: Screen, + S: Screen, + D: Draw, V: Fn()->I, - I: Iterator>, - F: Fn(&dyn Draw)->dyn Draw, -> (_items: V, _cb: F) -> impl Draw { - thunk(move|_to: &mut T|{ todo!() }) + I: Iterator, + F: Fn(&D)->dyn Draw, +> (_items: V, _cb: F) -> impl Draw { + thunk(move|_to: &mut S|{ todo!() }) } -pub fn iter_north < - T: Screen, - V: Fn()->I, - I: Iterator>, - F: Fn(&dyn Draw)->dyn Draw, -> (_items: V, _cb: F) -> impl Draw { - thunk(move|_to: &mut T|{ todo!() }) + +pub fn iter_north <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( + _iter: impl Fn()->I, _draw: impl Fn(D)->U, +) -> impl Draw { + thunk(move|_to: &mut S|{ todo!() }) } -pub fn iter_east < - T: Screen, - V: Fn()->I, - I: Iterator>, - F: Fn(&dyn Draw)->dyn Draw, -> (_items: V, _cb: F) -> impl Draw { - thunk(move|_to: &mut T|{ todo!() }) + +pub fn iter_east <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( + _iter: impl Fn()->I, _draw: impl Fn(D)->U, +) -> impl Draw { + thunk(move|_to: &mut S|{ todo!() }) } -pub fn iter_south < - T: Screen, - V: Fn()->I, - I: Iterator>, - F: Fn(&dyn Draw)->dyn Draw, -> (_items: V, _cb: F) -> impl Draw { - thunk(move|_to: &mut T|{ todo!() }) + +pub fn iter_south <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( + _iter: impl Fn()->I, _draw: impl Fn(D)->U, +) -> impl Draw { + thunk(move|_to: &mut S|{ todo!() }) } -pub fn iter_west < - T: Screen, - V: Fn()->I, - I: Iterator>, - F: Fn(&dyn Draw)->dyn Draw, -> (_items: V, _cb: F) -> impl Draw { - thunk(move|_to: &mut T|{ todo!() }) + +pub fn iter_west <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( + _iter: impl Fn()->I, _draw: impl Fn(D)->U, +) -> impl Draw { + thunk(move|_to: &mut S|{ todo!() }) } #[derive(Default, Debug)]