fix signatures of iter_ helpers

This commit is contained in:
i do not exist 2026-04-17 04:07:14 +03:00
parent 6c382e2627
commit c9b9ff1519
3 changed files with 56 additions and 47 deletions

View file

@ -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<TuiEvent, Usually<Self>> for State {
fn apply (&mut self, input: &TuiEvent) -> Usually<Self> {
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<Self> {
use Action::*;
match self { Next => Self::next(state), Prev => Self::prev(state), }
}
fn next (state: &mut State) -> Perhaps<Self> {
state.cursor = (state.cursor + 1) % VIEWS.len();
Ok(Some(Self::Prev))
}
fn prev (state: &mut State) -> Perhaps<Self> {
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 ]);

View file

@ -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<f32>) -> Color {
let Srgb { red, green, blue, .. }: Srgb<f32> = Srgb::from_color_unclamped(color);
Color::Rgb((red * 255.0) as u8, (green * 255.0) as u8, (blue * 255.0) as u8,)

View file

@ -424,22 +424,26 @@ pub const fn w_full <T: Screen> (a: impl Draw<T>) -> impl Draw<T> { a }
pub const fn h_full <T: Screen> (a: impl Draw<T>) -> impl Draw<T> { 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 <T: Screen> (a: impl Draw<T>) -> impl Draw<T> { a }
/// ].iter(), |x|x);
/// ```
pub fn iter <
T: Screen,
S: Screen,
D: Draw<S>,
V: Fn()->I,
I: Iterator<Item = dyn Draw<T>>,
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
> (_items: V, _cb: F) -> impl Draw<T> {
thunk(move|_to: &mut T|{ todo!() })
I: Iterator<Item = D>,
F: Fn(&D)->dyn Draw<S>,
> (_items: V, _cb: F) -> impl Draw<S> {
thunk(move|_to: &mut S|{ todo!() })
}
pub fn iter_north <
T: Screen,
V: Fn()->I,
I: Iterator<Item = dyn Draw<T>>,
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
> (_items: V, _cb: F) -> impl Draw<T> {
thunk(move|_to: &mut T|{ todo!() })
pub fn iter_north <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
_iter: impl Fn()->I, _draw: impl Fn(D)->U,
) -> impl Draw<S> {
thunk(move|_to: &mut S|{ todo!() })
}
pub fn iter_east <
T: Screen,
V: Fn()->I,
I: Iterator<Item = dyn Draw<T>>,
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
> (_items: V, _cb: F) -> impl Draw<T> {
thunk(move|_to: &mut T|{ todo!() })
pub fn iter_east <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
_iter: impl Fn()->I, _draw: impl Fn(D)->U,
) -> impl Draw<S> {
thunk(move|_to: &mut S|{ todo!() })
}
pub fn iter_south <
T: Screen,
V: Fn()->I,
I: Iterator<Item = dyn Draw<T>>,
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
> (_items: V, _cb: F) -> impl Draw<T> {
thunk(move|_to: &mut T|{ todo!() })
pub fn iter_south <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
_iter: impl Fn()->I, _draw: impl Fn(D)->U,
) -> impl Draw<S> {
thunk(move|_to: &mut S|{ todo!() })
}
pub fn iter_west <
T: Screen,
V: Fn()->I,
I: Iterator<Item = dyn Draw<T>>,
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
> (_items: V, _cb: F) -> impl Draw<T> {
thunk(move|_to: &mut T|{ todo!() })
pub fn iter_west <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
_iter: impl Fn()->I, _draw: impl Fn(D)->U,
) -> impl Draw<S> {
thunk(move|_to: &mut S|{ todo!() })
}
#[derive(Default, Debug)]