mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
genericize layout rendering
This commit is contained in:
parent
1d21071c86
commit
4855609a7d
8 changed files with 167 additions and 118 deletions
|
|
@ -26,6 +26,7 @@ pub struct Tui {
|
|||
}
|
||||
impl Engine for Tui {
|
||||
type Unit = u16;
|
||||
type Area = Rect;
|
||||
type HandleInput = Self;
|
||||
type Handled = bool;
|
||||
type RenderInput = Self;
|
||||
|
|
@ -47,6 +48,15 @@ impl Engine for Tui {
|
|||
stdout().execute(LeaveAlternateScreen)?;
|
||||
disable_raw_mode().map_err(Into::into)
|
||||
}
|
||||
// FIXME
|
||||
fn area (&self) -> Self::Area {
|
||||
self.area
|
||||
}
|
||||
#[inline]
|
||||
fn with_area (&mut self, x: u16, y: u16, w: u16, h: u16) -> &mut Self {
|
||||
self.with_rect(Rect { x, y, width: w, height: h });
|
||||
self
|
||||
}
|
||||
}
|
||||
impl Tui {
|
||||
/// Run the main loop.
|
||||
|
|
@ -113,9 +123,6 @@ impl Tui {
|
|||
pub fn event (&self) -> TuiEvent {
|
||||
self.event.read().unwrap().clone().unwrap()
|
||||
}
|
||||
pub fn area (&self) -> Rect {
|
||||
self.area
|
||||
}
|
||||
pub fn buffer (&mut self) -> &mut Buffer {
|
||||
&mut self.buffers[self.buffer]
|
||||
}
|
||||
|
|
@ -172,11 +179,6 @@ impl Tui {
|
|||
self.with_area(x, y, width, height)
|
||||
}
|
||||
#[inline]
|
||||
pub fn with_area (&mut self, x: u16, y: u16, w: u16, h: u16) -> &mut Self {
|
||||
self.with_rect(Rect { x, y, width: w, height: h });
|
||||
self
|
||||
}
|
||||
#[inline]
|
||||
pub fn with_rect (&mut self, area: Rect) -> &mut Self {
|
||||
self.area = area;
|
||||
self
|
||||
|
|
@ -221,3 +223,11 @@ pub fn half_block (lower: bool, upper: bool) -> Option<char> {
|
|||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
impl Rectangle<u16> for Rect {
|
||||
fn x (&self) -> u16 { self.x }
|
||||
fn y (&self) -> u16 { self.y }
|
||||
fn w (&self) -> u16 { self.width }
|
||||
fn h (&self) -> u16 { self.height }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue