mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-02-21 18:49:04 +01:00
refactor(output,tui): fix errors, now there's more...
Some checks failed
/ build (push) Has been cancelled
Some checks failed
/ build (push) Has been cancelled
This commit is contained in:
parent
4fa5d74fa2
commit
2dc74657d5
9 changed files with 713 additions and 754 deletions
|
|
@ -13,34 +13,29 @@ pub struct Tui {
|
|||
pub perf: PerfModel,
|
||||
}
|
||||
|
||||
#[derive(Default)] pub struct BigBuffer {
|
||||
pub width: usize,
|
||||
pub height: usize,
|
||||
pub content: Vec<Cell>
|
||||
#[derive(Debug, Clone)] pub struct TuiIn {
|
||||
/// Input event
|
||||
pub event: TuiEvent,
|
||||
/// Exit flag
|
||||
pub exited: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd)] pub struct TuiEvent(pub Event);
|
||||
|
||||
pub struct TuiKey(Option<KeyCode>, KeyModifiers);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TuiIn {
|
||||
/// Exit flag
|
||||
pub exited: Arc<AtomicBool>,
|
||||
/// Input event
|
||||
pub event: TuiEvent,
|
||||
#[derive(Default)] pub struct TuiOut {
|
||||
pub buffer: Buffer,
|
||||
pub area: XYWH<u16>,
|
||||
}
|
||||
|
||||
/// Performance counter
|
||||
#[derive(Debug)]
|
||||
pub struct PerfModel {
|
||||
pub enabled: bool,
|
||||
pub clock: quanta::Clock,
|
||||
// In nanoseconds. Time used by last iteration.
|
||||
pub used: AtomicF64,
|
||||
// In microseconds. Max prescribed time for iteration (frame, chunk...).
|
||||
pub window: AtomicF64,
|
||||
/// TUI buffer sized by `usize` instead of `u16`.
|
||||
#[derive(Default)] pub struct BigBuffer {
|
||||
pub width: usize,
|
||||
pub height: usize,
|
||||
pub content: Vec<Cell>
|
||||
}
|
||||
|
||||
/// A color in OKHSL and RGB representations.
|
||||
#[derive(Debug, Default, Copy, Clone, PartialEq)] pub struct ItemColor {
|
||||
pub okhsl: Okhsl<f32>,
|
||||
|
|
@ -57,29 +52,10 @@ pub struct PerfModel {
|
|||
pub darkest: ItemColor,
|
||||
}
|
||||
|
||||
/// A cell that takes up 3 rows on its own,
|
||||
/// but stacks, giving (N+1)*2 rows per N cells.
|
||||
pub struct Phat<T> {
|
||||
pub width: u16,
|
||||
pub height: u16,
|
||||
pub content: T,
|
||||
pub colors: [Color;4],
|
||||
}
|
||||
pub struct Repeat<'a>(pub &'a str);
|
||||
pub struct RepeatV<'a>(pub &'a str);
|
||||
pub struct RepeatH<'a>(pub &'a str);
|
||||
pub struct Modify<T>(pub bool, pub Modifier, pub T);
|
||||
|
||||
pub struct ScrollbarV {
|
||||
pub offset: usize,
|
||||
pub length: usize,
|
||||
pub total: usize,
|
||||
}
|
||||
pub struct Styled<T>(pub Option<Style>, pub T);
|
||||
|
||||
pub struct ScrollbarH {
|
||||
pub offset: usize,
|
||||
pub length: usize,
|
||||
pub total: usize,
|
||||
}
|
||||
/// Displays an owned [str]-like with fixed maximum width.
|
||||
///
|
||||
/// Width is computed using [unicode_width].
|
||||
|
|
@ -90,35 +66,32 @@ pub struct TrimString<T: AsRef<str>>(pub u16, pub T);
|
|||
/// Width is computed using [unicode_width].
|
||||
pub struct TrimStringRef<'a, T: AsRef<str>>(pub u16, pub &'a T);
|
||||
|
||||
// Thunks can be natural error boundaries!
|
||||
/// Thunks can be natural error boundaries!
|
||||
pub struct ErrorBoundary<O: Out, T: Draw<O>>(
|
||||
std::marker::PhantomData<O>, Perhaps<T>
|
||||
std::marker::PhantomData<O>,
|
||||
Perhaps<T>
|
||||
);
|
||||
|
||||
pub struct Modify<T>(pub bool, pub Modifier, pub T);
|
||||
|
||||
pub struct Styled<T>(pub Option<Style>, pub T);
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct TuiOut {
|
||||
pub buffer: Buffer,
|
||||
pub area: XYWH<u16>,
|
||||
/// Repeat a string, e.g. for background
|
||||
pub enum Repeat<'a> {
|
||||
X(&'a str),
|
||||
Y(&'a str),
|
||||
XY(&'a str)
|
||||
}
|
||||
|
||||
impl Out for TuiOut {
|
||||
type Unit = u16;
|
||||
#[inline] fn area (&self) -> XYWH<u16> {
|
||||
self.area
|
||||
}
|
||||
#[inline] fn area_mut (&mut self) -> &mut XYWH<u16> {
|
||||
&mut self.area
|
||||
}
|
||||
#[inline] fn place_at <'t, T: Draw<Self> + ?Sized> (
|
||||
&mut self, area: XYWH<u16>, content: &'t T
|
||||
) {
|
||||
let last = self.area();
|
||||
*self.area_mut() = area;
|
||||
content.draw(self);
|
||||
*self.area_mut() = last;
|
||||
}
|
||||
/// Scroll indicator
|
||||
pub enum Scrollbar {
|
||||
/// Horizontal scrollbar
|
||||
X { offset: usize, length: usize, total: usize, },
|
||||
/// Vertical scrollbar
|
||||
Y { offset: usize, length: usize, total: usize, }
|
||||
}
|
||||
|
||||
/// A cell that takes up 3 rows on its own,
|
||||
/// but stacks, giving (N+1)*2 rows per N cells.
|
||||
pub struct Phat<T> {
|
||||
pub width: u16,
|
||||
pub height: u16,
|
||||
pub content: T,
|
||||
pub colors: [Color;4],
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue