mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-04-25 13:40:43 +02:00
fix signatures of iter_ helpers
This commit is contained in:
parent
6c382e2627
commit
c9b9ff1519
3 changed files with 56 additions and 47 deletions
|
|
@ -6,13 +6,6 @@ use ::{
|
||||||
|
|
||||||
tui_main!(State { cursor: 10, ..Default::default() });
|
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 {
|
impl Apply<TuiEvent, Usually<Self>> for State {
|
||||||
fn apply (&mut self, input: &TuiEvent) -> Usually<Self> {
|
fn apply (&mut self, input: &TuiEvent) -> Usually<Self> {
|
||||||
todo!()
|
todo!()
|
||||||
|
|
@ -53,19 +46,27 @@ fn draw_example (state: &State, to: &mut Tui) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action {
|
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> {
|
fn eval (&self, state: &mut State) -> Perhaps<Self> {
|
||||||
use Action::*;
|
use Action::*;
|
||||||
match self { Next => Self::next(state), Prev => Self::prev(state), }
|
match self { Next => Self::next(state), Prev => Self::prev(state), }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next (state: &mut State) -> Perhaps<Self> {
|
fn next (state: &mut State) -> Perhaps<Self> {
|
||||||
state.cursor = (state.cursor + 1) % VIEWS.len();
|
state.cursor = (state.cursor + 1) % VIEWS.len();
|
||||||
Ok(Some(Self::Prev))
|
Ok(Some(Self::Prev))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prev (state: &mut State) -> Perhaps<Self> {
|
fn prev (state: &mut State) -> Perhaps<Self> {
|
||||||
state.cursor = if state.cursor > 0 { state.cursor - 1 } else { VIEWS.len() - 1 };
|
state.cursor = if state.cursor > 0 { state.cursor - 1 } else { VIEWS.len() - 1 };
|
||||||
Ok(Some(Self::Next))
|
Ok(Some(Self::Next))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const VIEWS: &'static [&'static str] = &[
|
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 ]);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ pub fn rgb (r: u8, g: u8, b: u8) -> ItemColor {
|
||||||
ItemColor { okhsl: rgb_to_okhsl(term), term }
|
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 {
|
pub fn okhsl_to_rgb (color: Okhsl<f32>) -> Color {
|
||||||
let Srgb { red, green, blue, .. }: Srgb<f32> = Srgb::from_color_unclamped(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,)
|
Color::Rgb((red * 255.0) as u8, (green * 255.0) as u8, (blue * 255.0) as u8,)
|
||||||
|
|
|
||||||
75
src/space.rs
75
src/space.rs
|
|
@ -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 }
|
pub const fn h_full <T: Screen> (a: impl Draw<T>) -> impl Draw<T> { a }
|
||||||
|
|
||||||
#[macro_export] macro_rules! north {
|
#[macro_export] macro_rules! north {
|
||||||
($($tt:tt)*) => { unimplemented!() };
|
($head:expr $(,)?) => { $head };
|
||||||
|
($head:expr, $($tail:expr),* $(,)?) => { north($head, north!($($tail,)*)) };
|
||||||
}
|
}
|
||||||
#[macro_export] macro_rules! south {
|
#[macro_export] macro_rules! south {
|
||||||
($($tt:tt)*) => { unimplemented!() };
|
($head:expr $(,)?) => { $head };
|
||||||
|
($head:expr, $($tail:expr),* $(,)?) => { south($head, south!($($tail,)*)) };
|
||||||
}
|
}
|
||||||
#[macro_export] macro_rules! east {
|
#[macro_export] macro_rules! east {
|
||||||
($($tt:tt)*) => { unimplemented!() };
|
($head:expr $(,)?) => { $head };
|
||||||
|
($head:expr, $($tail:expr),* $(,)?) => { east($head, east!($($tail,)*)) };
|
||||||
}
|
}
|
||||||
#[macro_export] macro_rules! west {
|
#[macro_export] macro_rules! west {
|
||||||
($($tt:tt)*) => { unimplemented!() };
|
($head:expr $(, $tail:expr)* $(,)?) => { west($head, west!($($tail,)*)) };
|
||||||
}
|
}
|
||||||
#[macro_export] macro_rules! above {
|
#[macro_export] macro_rules! above {
|
||||||
($($tt:tt)*) => { unimplemented!() };
|
($head:expr $(, $tail:expr)* $(,)?) => { above($head, above!($($tail,)*)) };
|
||||||
}
|
}
|
||||||
#[macro_export] macro_rules! below {
|
#[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:
|
/// 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);
|
/// ].iter(), |x|x);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn iter <
|
pub fn iter <
|
||||||
T: Screen,
|
S: Screen,
|
||||||
|
D: Draw<S>,
|
||||||
V: Fn()->I,
|
V: Fn()->I,
|
||||||
I: Iterator<Item = dyn Draw<T>>,
|
I: Iterator<Item = D>,
|
||||||
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
|
F: Fn(&D)->dyn Draw<S>,
|
||||||
> (_items: V, _cb: F) -> impl Draw<T> {
|
> (_items: V, _cb: F) -> impl Draw<S> {
|
||||||
thunk(move|_to: &mut T|{ todo!() })
|
thunk(move|_to: &mut S|{ todo!() })
|
||||||
}
|
}
|
||||||
pub fn iter_north <
|
|
||||||
T: Screen,
|
pub fn iter_north <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
|
||||||
V: Fn()->I,
|
_iter: impl Fn()->I, _draw: impl Fn(D)->U,
|
||||||
I: Iterator<Item = dyn Draw<T>>,
|
) -> impl Draw<S> {
|
||||||
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
|
thunk(move|_to: &mut S|{ todo!() })
|
||||||
> (_items: V, _cb: F) -> impl Draw<T> {
|
|
||||||
thunk(move|_to: &mut T|{ todo!() })
|
|
||||||
}
|
}
|
||||||
pub fn iter_east <
|
|
||||||
T: Screen,
|
pub fn iter_east <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
|
||||||
V: Fn()->I,
|
_iter: impl Fn()->I, _draw: impl Fn(D)->U,
|
||||||
I: Iterator<Item = dyn Draw<T>>,
|
) -> impl Draw<S> {
|
||||||
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
|
thunk(move|_to: &mut S|{ todo!() })
|
||||||
> (_items: V, _cb: F) -> impl Draw<T> {
|
|
||||||
thunk(move|_to: &mut T|{ todo!() })
|
|
||||||
}
|
}
|
||||||
pub fn iter_south <
|
|
||||||
T: Screen,
|
pub fn iter_south <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
|
||||||
V: Fn()->I,
|
_iter: impl Fn()->I, _draw: impl Fn(D)->U,
|
||||||
I: Iterator<Item = dyn Draw<T>>,
|
) -> impl Draw<S> {
|
||||||
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
|
thunk(move|_to: &mut S|{ todo!() })
|
||||||
> (_items: V, _cb: F) -> impl Draw<T> {
|
|
||||||
thunk(move|_to: &mut T|{ todo!() })
|
|
||||||
}
|
}
|
||||||
pub fn iter_west <
|
|
||||||
T: Screen,
|
pub fn iter_west <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
|
||||||
V: Fn()->I,
|
_iter: impl Fn()->I, _draw: impl Fn(D)->U,
|
||||||
I: Iterator<Item = dyn Draw<T>>,
|
) -> impl Draw<S> {
|
||||||
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
|
thunk(move|_to: &mut S|{ todo!() })
|
||||||
> (_items: V, _cb: F) -> impl Draw<T> {
|
|
||||||
thunk(move|_to: &mut T|{ todo!() })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue