mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
separate Engine from RenderTarget
This commit is contained in:
parent
60acb20a57
commit
ff6751d393
4 changed files with 70 additions and 56 deletions
|
|
@ -310,13 +310,13 @@ impl<E: Engine> Widget for JackDevice<E> {
|
||||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||||
self.state.read().unwrap().layout(to)
|
self.state.read().unwrap().layout(to)
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
self.state.read().unwrap().render(to)
|
self.state.read().unwrap().render(to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: Engine> Handle<E> for JackDevice<E> {
|
impl<E: Engine> Handle<E> for JackDevice<E> {
|
||||||
fn handle (&mut self, from: &E::HandleInput) -> Perhaps<E::Handled> {
|
fn handle (&mut self, from: &E::Input) -> Perhaps<E::Handled> {
|
||||||
self.state.write().unwrap().handle(from)
|
self.state.write().unwrap().handle(from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,38 +16,37 @@ pub trait Engine: Send + Sync + Sized {
|
||||||
type Area: Area<Self::Unit> + From<[Self::Unit;4]> + Debug;
|
type Area: Area<Self::Unit> + From<[Self::Unit;4]> + Debug;
|
||||||
type Size: Size<Self::Unit> + From<[Self::Unit;2]> + Debug;
|
type Size: Size<Self::Unit> + From<[Self::Unit;2]> + Debug;
|
||||||
|
|
||||||
type HandleInput;
|
type Input;
|
||||||
type Handled;
|
type Handled;
|
||||||
|
type Output: RenderTarget<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
#[inline] fn area (&self) -> Self::Area;
|
pub trait RenderTarget<E: Engine> {
|
||||||
#[inline] fn area_mut (&mut self) -> &mut Self::Area;
|
fn area (&self)
|
||||||
#[inline] fn render_in (
|
-> E::Area;
|
||||||
&mut self, area: Self::Area, widget: &impl Widget<Engine = Self>
|
fn area_mut (&mut self)
|
||||||
) -> Perhaps<Self::Area> {
|
-> &mut E::Area;
|
||||||
let last = self.area();
|
fn render_in (&mut self, area: E::Area, widget: &impl Widget<Engine = E>)
|
||||||
*self.area_mut() = area;
|
-> Perhaps<E::Area>;
|
||||||
let next = widget.render(self)?;
|
|
||||||
*self.area_mut() = last;
|
|
||||||
Ok(next)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Widget: Send + Sync {
|
pub trait Widget: Send + Sync {
|
||||||
type Engine: Engine;
|
type Engine: Engine;
|
||||||
fn layout (&self, to: <<Self as Widget>::Engine as Engine>::Size) ->
|
fn layout (
|
||||||
Perhaps<<<Self as Widget>::Engine as Engine>::Size>
|
&self, to: <Self::Engine as Engine>::Size
|
||||||
{
|
) -> Perhaps<<Self::Engine as Engine>::Size> {
|
||||||
Ok(Some(to))
|
Ok(Some(to))
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut Self::Engine) ->
|
fn render (
|
||||||
Perhaps<<<Self as Widget>::Engine as Engine>::Area>;
|
&self, to: &mut <Self::Engine as Engine>::Output
|
||||||
|
) -> Perhaps<<<Self as Widget>::Engine as Engine>::Area>;
|
||||||
}
|
}
|
||||||
impl<'a, E: Engine> Widget for Box<dyn Widget<Engine = E> + 'a> {
|
impl<'a, E: Engine> Widget for Box<dyn Widget<Engine = E> + 'a> {
|
||||||
type Engine = E;
|
type Engine = E;
|
||||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||||
(**self).layout(to)
|
(**self).layout(to)
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
(**self).render(to)
|
(**self).render(to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -56,7 +55,7 @@ impl<E: Engine> Widget for &dyn Widget<Engine = E> {
|
||||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||||
(*self).layout(to)
|
(*self).layout(to)
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
(*self).render(to)
|
(*self).render(to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -65,7 +64,7 @@ impl<E: Engine> Widget for &mut dyn Widget<Engine = E> {
|
||||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||||
(**self).layout(to)
|
(**self).layout(to)
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
(**self).render(to)
|
(**self).render(to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +73,7 @@ impl<E: Engine, W: Widget<Engine = E>> Widget for Arc<W> {
|
||||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||||
self.as_ref().layout(to)
|
self.as_ref().layout(to)
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
self.as_ref().render(to)
|
self.as_ref().render(to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -83,7 +82,7 @@ impl<E: Engine, W: Widget<Engine = E>> Widget for Mutex<W> {
|
||||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||||
self.lock().unwrap().layout(to)
|
self.lock().unwrap().layout(to)
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
self.lock().unwrap().render(to)
|
self.lock().unwrap().render(to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +91,7 @@ impl<E: Engine, W: Widget<Engine = E>> Widget for RwLock<W> {
|
||||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||||
self.read().unwrap().layout(to)
|
self.read().unwrap().layout(to)
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
self.read().unwrap().render(to)
|
self.read().unwrap().render(to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -101,7 +100,7 @@ impl<E: Engine, W: Widget<Engine = E>> Widget for Option<W> {
|
||||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||||
Ok(self.as_ref().map(|widget|widget.layout(to)).transpose()?.flatten())
|
Ok(self.as_ref().map(|widget|widget.layout(to)).transpose()?.flatten())
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
Ok(self.as_ref().map(|widget|widget.render(to)).transpose()?.flatten())
|
Ok(self.as_ref().map(|widget|widget.render(to)).transpose()?.flatten())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -120,7 +119,7 @@ impl<E: Engine, W: Content<Engine = E>> Widget for W {
|
||||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||||
self.content().layout(to)
|
self.content().layout(to)
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
match self.layout(to.area().wh().into())? {
|
match self.layout(to.area().wh().into())? {
|
||||||
Some(wh) => to.render_in(to.area().clip(wh).into(), &self.content()),
|
Some(wh) => to.render_in(to.area().clip(wh).into(), &self.content()),
|
||||||
None => Ok(None)
|
None => Ok(None)
|
||||||
|
|
@ -154,17 +153,17 @@ impl<E: Engine, C: Component<E> + Exit> ExitableComponent<E> for C {}
|
||||||
|
|
||||||
/// Handle input
|
/// Handle input
|
||||||
pub trait Handle<E: Engine>: Send + Sync {
|
pub trait Handle<E: Engine>: Send + Sync {
|
||||||
fn handle (&mut self, context: &E::HandleInput) -> Perhaps<E::Handled>;
|
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<H, E: Engine> Handle<E> for &mut H where H: Handle<E> {
|
impl<H, E: Engine> Handle<E> for &mut H where H: Handle<E> {
|
||||||
fn handle (&mut self, context: &E::HandleInput) -> Perhaps<E::Handled> {
|
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled> {
|
||||||
(*self).handle(context)
|
(*self).handle(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<H, E: Engine> Handle<E> for Option<H> where H: Handle<E> {
|
impl<H, E: Engine> Handle<E> for Option<H> where H: Handle<E> {
|
||||||
fn handle (&mut self, context: &E::HandleInput) -> Perhaps<E::Handled> {
|
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled> {
|
||||||
if let Some(ref mut handle) = self {
|
if let Some(ref mut handle) = self {
|
||||||
handle.handle(context)
|
handle.handle(context)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -174,25 +173,25 @@ impl<H, E: Engine> Handle<E> for Option<H> where H: Handle<E> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<H, E: Engine> Handle<E> for Mutex<H> where H: Handle<E> {
|
impl<H, E: Engine> Handle<E> for Mutex<H> where H: Handle<E> {
|
||||||
fn handle (&mut self, context: &E::HandleInput) -> Perhaps<E::Handled> {
|
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled> {
|
||||||
self.lock().unwrap().handle(context)
|
self.lock().unwrap().handle(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<H, E: Engine> Handle<E> for Arc<Mutex<H>> where H: Handle<E> {
|
impl<H, E: Engine> Handle<E> for Arc<Mutex<H>> where H: Handle<E> {
|
||||||
fn handle (&mut self, context: &E::HandleInput) -> Perhaps<E::Handled> {
|
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled> {
|
||||||
self.lock().unwrap().handle(context)
|
self.lock().unwrap().handle(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<H, E: Engine> Handle<E> for RwLock<H> where H: Handle<E> {
|
impl<H, E: Engine> Handle<E> for RwLock<H> where H: Handle<E> {
|
||||||
fn handle (&mut self, context: &E::HandleInput) -> Perhaps<E::Handled> {
|
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled> {
|
||||||
self.write().unwrap().handle(context)
|
self.write().unwrap().handle(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<H, E: Engine> Handle<E> for Arc<RwLock<H>> where H: Handle<E> {
|
impl<H, E: Engine> Handle<E> for Arc<RwLock<H>> where H: Handle<E> {
|
||||||
fn handle (&mut self, context: &E::HandleInput) -> Perhaps<E::Handled> {
|
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled> {
|
||||||
self.write().unwrap().handle(context)
|
self.write().unwrap().handle(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -450,7 +449,7 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Align<T> {
|
||||||
//Self::SE(_) => { todo!() },
|
//Self::SE(_) => { todo!() },
|
||||||
//})
|
//})
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
let outer_area = to.area();
|
let outer_area = to.area();
|
||||||
Ok(if let Some(inner_size) = self.layout(outer_area.wh().into())? {
|
Ok(if let Some(inner_size) = self.layout(outer_area.wh().into())? {
|
||||||
let inner_area = outer_area.clip(inner_size);
|
let inner_area = outer_area.clip(inner_size);
|
||||||
|
|
@ -505,7 +504,7 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Min<E::Unit, T> {
|
||||||
}.into()))
|
}.into()))
|
||||||
}
|
}
|
||||||
// TODO: 🡘 🡙 ←🡙→
|
// TODO: 🡘 🡙 ←🡙→
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
Ok(self.layout(to.area().wh().into())?
|
Ok(self.layout(to.area().wh().into())?
|
||||||
.map(|size|to.render_in(to.area().clip(size).into(), self.inner()))
|
.map(|size|to.render_in(to.area().clip(size).into(), self.inner()))
|
||||||
.transpose()?.flatten())
|
.transpose()?.flatten())
|
||||||
|
|
@ -537,7 +536,7 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Max<E:: Unit, T> {
|
||||||
Self::XY(w, h, _) => [to.w().min(w), to.h().min(h)],
|
Self::XY(w, h, _) => [to.w().min(w), to.h().min(h)],
|
||||||
}.into()))
|
}.into()))
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
Ok(self.layout(to.area().wh().into())?
|
Ok(self.layout(to.area().wh().into())?
|
||||||
.map(|size|to.render_in(to.area().clip(size).into(), self.inner()))
|
.map(|size|to.render_in(to.area().clip(size).into(), self.inner()))
|
||||||
.transpose()?.flatten())
|
.transpose()?.flatten())
|
||||||
|
|
@ -569,7 +568,7 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Grow<E::Unit, T> {
|
||||||
Self::XY(w, h, _) => [to.w() + w, to.h() + h],
|
Self::XY(w, h, _) => [to.w() + w, to.h() + h],
|
||||||
}.into()))
|
}.into()))
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
Ok(self.layout(to.area().wh().into())?
|
Ok(self.layout(to.area().wh().into())?
|
||||||
.map(|size|to.render_in(to.area().clip(size).into(), self.inner()))
|
.map(|size|to.render_in(to.area().clip(size).into(), self.inner()))
|
||||||
.transpose()?.flatten())
|
.transpose()?.flatten())
|
||||||
|
|
@ -601,7 +600,7 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Shrink<E::Unit, T> {
|
||||||
Self::XY(w, h, _) => [to.w() - w, to.h() - h]
|
Self::XY(w, h, _) => [to.w() - w, to.h() - h]
|
||||||
}.into()))
|
}.into()))
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
Ok(self.layout(to.area().wh().into())?
|
Ok(self.layout(to.area().wh().into())?
|
||||||
.map(|size|to.render_in(to.area().clip(size).into(), self.inner()))
|
.map(|size|to.render_in(to.area().clip(size).into(), self.inner()))
|
||||||
.transpose()?.flatten())
|
.transpose()?.flatten())
|
||||||
|
|
@ -649,7 +648,7 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Inset<E::Unit, T> {
|
||||||
Self::XY(x, y, ref inner) => Shrink::XY(x + x, y + y, inner as &dyn Widget<Engine = E>),
|
Self::XY(x, y, ref inner) => Shrink::XY(x + x, y + y, inner as &dyn Widget<Engine = E>),
|
||||||
}.layout(to)
|
}.layout(to)
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
match *self {
|
match *self {
|
||||||
Self::X(x, ref inner) => Plus::X(x, inner as &dyn Widget<Engine = E>),
|
Self::X(x, ref inner) => Plus::X(x, inner as &dyn Widget<Engine = E>),
|
||||||
Self::Y(y, ref inner) => Plus::Y(y, inner as &dyn Widget<Engine = E>),
|
Self::Y(y, ref inner) => Plus::Y(y, inner as &dyn Widget<Engine = E>),
|
||||||
|
|
@ -667,7 +666,7 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Outset<E::Unit, T> {
|
||||||
Self::XY(x, y, ref inner) => Grow::XY(x + x, y + y, inner as &dyn Widget<Engine = E>),
|
Self::XY(x, y, ref inner) => Grow::XY(x + x, y + y, inner as &dyn Widget<Engine = E>),
|
||||||
}.layout(to)
|
}.layout(to)
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
match *self {
|
match *self {
|
||||||
Self::X(x, ref inner) => Plus::X(x, inner as &dyn Widget<Engine = E>),
|
Self::X(x, ref inner) => Plus::X(x, inner as &dyn Widget<Engine = E>),
|
||||||
Self::Y(y, ref inner) => Plus::Y(y, inner as &dyn Widget<Engine = E>),
|
Self::Y(y, ref inner) => Plus::Y(y, inner as &dyn Widget<Engine = E>),
|
||||||
|
|
@ -703,7 +702,7 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Plus<E::Unit, T> {
|
||||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||||
self.inner().layout(to)
|
self.inner().layout(to)
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
let area = to.area();
|
let area = to.area();
|
||||||
Ok(self.layout(area.wh().into())?
|
Ok(self.layout(area.wh().into())?
|
||||||
.map(|size|to.render_in(match *self {
|
.map(|size|to.render_in(match *self {
|
||||||
|
|
@ -741,7 +740,7 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Minus<E::Unit, T> {
|
||||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||||
self.inner().layout(to)
|
self.inner().layout(to)
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
fn render (&self, to: &mut E::Output) -> Perhaps<E::Area> {
|
||||||
let area = to.area();
|
let area = to.area();
|
||||||
Ok(self.layout(area.wh().into())?
|
Ok(self.layout(area.wh().into())?
|
||||||
.map(|size|to.render_in(match *self {
|
.map(|size|to.render_in(match *self {
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@ use crate::*;
|
||||||
struct TestEngine([u16;4], Vec<Vec<char>>);
|
struct TestEngine([u16;4], Vec<Vec<char>>);
|
||||||
|
|
||||||
impl Engine for TestEngine {
|
impl Engine for TestEngine {
|
||||||
type Unit = u16;
|
type Unit = u16;
|
||||||
type Size = [Self::Unit;2];
|
type Size = [Self::Unit;2];
|
||||||
type Area = [Self::Unit;4];
|
type Area = [Self::Unit;4];
|
||||||
type HandleInput = Self;
|
type Input = Self;
|
||||||
type Handled = bool;
|
type Handled = bool;
|
||||||
fn exited (&self) -> bool {
|
fn exited (&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,12 @@ pub struct Tui {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Engine for Tui {
|
impl Engine for Tui {
|
||||||
type Unit = u16;
|
type Unit = u16;
|
||||||
type Size = [Self::Unit;2];
|
type Size = [Self::Unit;2];
|
||||||
type Area = [Self::Unit;4];
|
type Area = [Self::Unit;4];
|
||||||
type HandleInput = Self;
|
type Input = Self;
|
||||||
type Handled = bool;
|
type Handled = bool;
|
||||||
|
type Output = Self;
|
||||||
fn exited (&self) -> bool {
|
fn exited (&self) -> bool {
|
||||||
self.exited.fetch_and(true, Ordering::Relaxed)
|
self.exited.fetch_and(true, Ordering::Relaxed)
|
||||||
}
|
}
|
||||||
|
|
@ -46,13 +47,27 @@ impl Engine for Tui {
|
||||||
self.backend.show_cursor()?;
|
self.backend.show_cursor()?;
|
||||||
disable_raw_mode().map_err(Into::into)
|
disable_raw_mode().map_err(Into::into)
|
||||||
}
|
}
|
||||||
#[inline] fn area (&self) -> Self::Area {
|
}
|
||||||
|
impl RenderTarget<Tui> for Tui {
|
||||||
|
#[inline] fn area (&self) -> <Self as Engine>::Area {
|
||||||
self.area
|
self.area
|
||||||
}
|
}
|
||||||
#[inline] fn area_mut (&mut self) -> &mut Self::Area {
|
#[inline] fn area_mut (&mut self) -> &mut <Self as Engine>::Area {
|
||||||
&mut self.area
|
&mut self.area
|
||||||
}
|
}
|
||||||
|
#[inline] fn render_in (
|
||||||
|
&mut self,
|
||||||
|
area: <Self as Engine>::Area,
|
||||||
|
widget: &impl Widget<Engine = Self>
|
||||||
|
) -> Perhaps<<Self as Engine>::Area> {
|
||||||
|
let last = self.area();
|
||||||
|
*self.area_mut() = area;
|
||||||
|
let next = widget.render(self)?;
|
||||||
|
*self.area_mut() = last;
|
||||||
|
Ok(next)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tui {
|
impl Tui {
|
||||||
/// Run the main loop.
|
/// Run the main loop.
|
||||||
pub fn run <R: Component<Tui> + Sized + 'static> (
|
pub fn run <R: Component<Tui> + Sized + 'static> (
|
||||||
|
|
@ -90,7 +105,7 @@ impl Tui {
|
||||||
let event = TuiEvent::Input(::crossterm::event::read().unwrap());
|
let event = TuiEvent::Input(::crossterm::event::read().unwrap());
|
||||||
match event {
|
match event {
|
||||||
key!(Ctrl-KeyCode::Char('c')) => {
|
key!(Ctrl-KeyCode::Char('c')) => {
|
||||||
engine.write().unwrap().exited.store(true, Ordering::Relaxed);
|
exited.store(true, Ordering::Relaxed);
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
*engine.write().unwrap().event.write().unwrap() = Some(event);
|
*engine.write().unwrap().event.write().unwrap() = Some(event);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue