mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-02-22 18:59:02 +01:00
parent
006cddcc16
commit
06f8ed3ae3
13 changed files with 133 additions and 125 deletions
124
examples/tui_00.rs
Normal file
124
examples/tui_00.rs
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
use ::{std::sync::{Arc, RwLock}, ratatui::style::Color,
|
||||
tengri::{*, input::*, output::*}, tengri_tui::*};
|
||||
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));
|
||||
from!(Action: |input: &TuiIn| todo!());
|
||||
view!(State: TuiOut: [ evaluate_output_expression, evaluate_output_expression_tui ]);
|
||||
draw!(State: TuiOut: [ draw_example ]);
|
||||
#[derive(Debug, Default)] struct State {
|
||||
/** Rendered window size */ size: Measure<TuiOut>,
|
||||
/** Command history (undo/redo) */ history: Vec<Action>,
|
||||
/** User-controllable value */ cursor: usize,
|
||||
}
|
||||
#[derive(Debug)] enum Action {
|
||||
/** Increment cursor */ Next,
|
||||
/** Decrement cursor */ Prev
|
||||
}
|
||||
fn draw_example (state: &State, to: &mut TuiOut) {
|
||||
let index = state.cursor + 1;
|
||||
let wh = state.size.wh();
|
||||
let src = VIEWS.get(state.cursor).unwrap_or(&"");
|
||||
let heading = format!("State {}/{} in {:?}", index, VIEWS.len(), &wh);
|
||||
let title = Tui::bg(Color::Rgb(60, 10, 10), Push::Y(1, Align::n(heading)));
|
||||
let code = Tui::bg(Color::Rgb(10, 60, 10), Push::Y(2, Align::n(format!("{}", src))));
|
||||
//let content = ;//();//Tui::bg(Color::Rgb(10, 10, 60), View(state, CstIter::new(src)));
|
||||
state.size.of(Bsp::s(title, Bsp::n(code, state.view(to, &src).unwrap()))).draw(to)
|
||||
}
|
||||
impl Action {
|
||||
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] = &[
|
||||
|
||||
stringify! { :hello-world },
|
||||
|
||||
stringify! { (fill/xy :hello-world) },
|
||||
|
||||
stringify! { (bsp/s :hello :world) },
|
||||
|
||||
stringify! { (fixed/xy 20 10 :hello-world) },
|
||||
|
||||
stringify! { (bsp/s (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)) },
|
||||
|
||||
stringify! { (bsp/e (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)) },
|
||||
|
||||
stringify! { (bsp/n (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)) },
|
||||
|
||||
stringify! { (bsp/w (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)) },
|
||||
|
||||
stringify! { (bsp/a (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)) },
|
||||
|
||||
stringify! { (bsp/b (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)) },
|
||||
|
||||
stringify! {
|
||||
(bsp/s
|
||||
(bsp/e (align/nw (fixed/xy 5 3 :hello))
|
||||
(bsp/e (align/n (fixed/xy 5 3 :hello))
|
||||
(align/ne (fixed/xy 5 3 :hello))))
|
||||
(bsp/s
|
||||
(bsp/e (align/w (fixed/xy 5 3 :hello))
|
||||
(bsp/e (align/c (fixed/xy 5 3 :hello))
|
||||
(align/e (fixed/xy 5 3 :hello))))
|
||||
(bsp/e (align/sw (fixed/xy 5 3 :hello))
|
||||
(bsp/e (align/s (fixed/xy 5 3 :hello))
|
||||
(align/se (fixed/xy 5 3 :hello))))))
|
||||
},
|
||||
|
||||
stringify! {
|
||||
(bsp/s
|
||||
(bsp/e (fixed/xy 8 5 (align/nw :hello))
|
||||
(bsp/e (fixed/xy 8 5 (align/n :hello))
|
||||
(fixed/xy 8 5 (align/ne :hello))))
|
||||
(bsp/s
|
||||
(bsp/e (fixed/xy 8 5 (align/w :hello))
|
||||
(bsp/e (fixed/xy 8 5 (align/c :hello))
|
||||
(fixed/xy 8 5 (align/e :hello))))
|
||||
(bsp/e (fixed/xy 8 5 (align/sw :hello))
|
||||
(bsp/e (fixed/xy 8 5 (align/s :hello))
|
||||
(fixed/xy 8 5 (align/se :hello))))))
|
||||
},
|
||||
|
||||
stringify! {
|
||||
(bsp/s
|
||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/nw :hello)))
|
||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/n :hello)))
|
||||
(grow/xy 1 1 (fixed/xy 8 5 (align/ne :hello)))))
|
||||
(bsp/s
|
||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/w :hello)))
|
||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/c :hello)))
|
||||
(grow/xy 1 1 (fixed/xy 8 5 (align/e :hello)))))
|
||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/sw :hello)))
|
||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/s :hello)))
|
||||
(grow/xy 1 1 (fixed/xy 8 5 (align/se :hello)))))))
|
||||
},
|
||||
|
||||
stringify! { :map-e },
|
||||
|
||||
stringify! { (align/c :map-e) },
|
||||
|
||||
stringify! { :map-s },
|
||||
|
||||
stringify! { (align/c :map-s) },
|
||||
|
||||
stringify! {
|
||||
(align/c (bg/behind :bg0 (margin/xy 1 1 (col
|
||||
(bg/behind :bg1 (border/around :border1 (margin/xy 2 1 :label1)))
|
||||
(bg/behind :bg2 (border/around :border2 (margin/xy 4 2 :label2)))
|
||||
(bg/behind :bg3 (border/around :border3 (margin/xy 6 3 :label3)))))))
|
||||
},
|
||||
|
||||
];
|
||||
105
examples/tui_01.rs
Normal file
105
examples/tui_01.rs
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
fn main () {}
|
||||
|
||||
//#[tengri_proc::expose]
|
||||
//impl Example {
|
||||
//fn _todo_u16_stub (&self) -> u16 { todo!() }
|
||||
//fn _todo_bool_stub (&self) -> bool { todo!() }
|
||||
//fn _todo_usize_stub (&self) -> usize { todo!() }
|
||||
////[bool] => {}
|
||||
////[u16] => {}
|
||||
////[usize] => {}
|
||||
//}
|
||||
|
||||
//#[tengri_proc::view(TuiOut)]
|
||||
//impl Example {
|
||||
//pub fn title (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
//Tui::bg(Color::Rgb(60, 10, 10), Push::y(1, Align::n(format!("Example {}/{}:", self.0 + 1, VIEWS.len())))).boxed()
|
||||
//}
|
||||
//pub fn code (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
//Tui::bg(Color::Rgb(10, 60, 10), Push::y(2, Align::n(format!("{}", VIEWS[self.0])))).boxed()
|
||||
//}
|
||||
//pub fn hello (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
//Tui::bg(Color::Rgb(10, 100, 10), "Hello").boxed()
|
||||
//}
|
||||
//pub fn world (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
//Tui::bg(Color::Rgb(100, 10, 10), "world").boxed()
|
||||
//}
|
||||
//pub fn hello_world (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
//"Hello world!".boxed()
|
||||
//}
|
||||
//pub fn map_e (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
//Map::east(5u16, ||0..5u16, |n, _i|format!("{n}")).boxed()
|
||||
//}
|
||||
//pub fn map_s (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
//Map::south(5u16, ||0..5u16, |n, _i|format!("{n}")).boxed()
|
||||
//}
|
||||
//}
|
||||
|
||||
//fn content (&self) -> dyn Draw<Engine = Tui> {
|
||||
//let border_style = Style::default().fg(Color::Rgb(0,0,0));
|
||||
//Align::Center(Layers::new(move|add|{
|
||||
|
||||
//add(&Background(Color::Rgb(0,128,128)))?;
|
||||
|
||||
//add(&Margin::XY(1, 1, Stack::down(|add|{
|
||||
|
||||
//add(&Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(128,96,0)))?;
|
||||
//add(&Border(Square(border_style)))?;
|
||||
//add(&Margin::XY(2, 1, "..."))?;
|
||||
//Ok(())
|
||||
//}).debug())?;
|
||||
|
||||
//add(&Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(128,64,0)))?;
|
||||
//add(&Border(Lozenge(border_style)))?;
|
||||
//add(&Margin::XY(4, 2, "---"))?;
|
||||
//Ok(())
|
||||
//}).debug())?;
|
||||
|
||||
//add(&Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(96,64,0)))?;
|
||||
//add(&Border(SquareBold(border_style)))?;
|
||||
//add(&Margin::XY(6, 3, "~~~"))?;
|
||||
//Ok(())
|
||||
//}).debug())?;
|
||||
|
||||
//Ok(())
|
||||
//})).debug())?;
|
||||
|
||||
//Ok(())
|
||||
|
||||
//}))
|
||||
////Align::Center(Margin::X(1, Layers::new(|add|{
|
||||
////add(&Background(Color::Rgb(128,0,0)))?;
|
||||
////add(&Stack::down(|add|{
|
||||
////add(&Margin::Y(1, Layers::new(|add|{
|
||||
////add(&Background(Color::Rgb(0,128,0)))?;
|
||||
////add(&Align::Center("12345"))?;
|
||||
////add(&Align::Center("FOO"))
|
||||
////})))?;
|
||||
////add(&Margin::XY(1, 1, Layers::new(|add|{
|
||||
////add(&Align::Center("1234567"))?;
|
||||
////add(&Align::Center("BAR"))?;
|
||||
////add(&Background(Color::Rgb(0,0,128)))
|
||||
////})))
|
||||
////}))
|
||||
////})))
|
||||
|
||||
////Align::Y(Layers::new(|add|{
|
||||
////add(&Background(Color::Rgb(128,0,0)))?;
|
||||
////add(&Margin::X(1, Align::Center(Stack::down(|add|{
|
||||
////add(&Align::X(Margin::Y(1, Layers::new(|add|{
|
||||
////add(&Background(Color::Rgb(0,128,0)))?;
|
||||
////add(&Align::Center("12345"))?;
|
||||
////add(&Align::Center("FOO"))
|
||||
////})))?;
|
||||
////add(&Margin::XY(1, 1, Layers::new(|add|{
|
||||
////add(&Align::Center("1234567"))?;
|
||||
////add(&Align::Center("BAR"))?;
|
||||
////add(&Background(Color::Rgb(0,0,128)))
|
||||
////})))?;
|
||||
////Ok(())
|
||||
////})))))
|
||||
////}))
|
||||
//}
|
||||
Loading…
Add table
Add a link
Reference in a new issue