mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-08-07 14:16:56 +02:00
remove Screen::show
This commit is contained in:
parent
4c25dcc702
commit
083ce8ba76
3 changed files with 24 additions and 30 deletions
|
|
@ -40,3 +40,6 @@ fn align <S: Screen> (
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_align () {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ pub enum Full<T: Screen, I: Draw<T>> {
|
|||
H(I),
|
||||
WH(I),
|
||||
}
|
||||
|
||||
impl_draw!(<T: Screen, I: Draw<T>,>|self: Full<T, I>, to: T|{
|
||||
let XYWH(x0, y0, w0, h0) = to.area();
|
||||
match self {
|
||||
|
|
|
|||
50
src/lib.rs
50
src/lib.rs
|
|
@ -1359,10 +1359,6 @@ macro_rules! eval_xy (
|
|||
/// }
|
||||
/// impl Screen for TestOut {
|
||||
/// type Unit = u16;
|
||||
/// fn show (&mut self, _: impl Draw<Self>) -> Perhaps<XYWH<u16>> {
|
||||
/// println!("placed");
|
||||
/// Ok(None)
|
||||
/// }
|
||||
/// fn area (&self) -> XYWH<Self::Unit> {
|
||||
/// Default::default()
|
||||
/// }
|
||||
|
|
@ -1382,8 +1378,6 @@ macro_rules! eval_xy (
|
|||
/// ```
|
||||
pub trait Screen: Xy<Self::Unit> + Wh<Self::Unit> + Send + Sync + Sized {
|
||||
type Unit: Coord;
|
||||
/// Render drawable in subarea specified by `area`
|
||||
fn show (&mut self, content: impl Draw<Self>) -> Perhaps<XYWH<Self::Unit>>;
|
||||
/// Get current clipping area
|
||||
fn area (&self) -> XYWH<Self::Unit>;
|
||||
/// Set clipping area
|
||||
|
|
@ -2612,37 +2606,15 @@ macro_rules! eval_xy (
|
|||
|
||||
/// Get mutable reference to current clipping area
|
||||
fn area_mut (&mut self) -> &mut XYWH<u16> {
|
||||
match self {
|
||||
Self::Draw(_, area) => area,
|
||||
Self::Layout(area) => area,
|
||||
}
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Screen for Tui {
|
||||
type Unit = u16;
|
||||
/// Render drawable in subarea specified by `area`
|
||||
fn show (&mut self, content: impl Draw<Self>) -> Perhaps<XYWH<u16>> {
|
||||
let previous_area = self.area();
|
||||
Ok(if let Some(area) = content.layout(self.area())? {
|
||||
*self.area_mut() = area;
|
||||
if let Some(result_area) = content.draw(self)? {
|
||||
*self.area_mut() = previous_area;
|
||||
Some(result_area)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
})
|
||||
}
|
||||
|
||||
/// Get current clipping area
|
||||
fn area (&self) -> XYWH<Self::Unit> {
|
||||
match self {
|
||||
Self::Draw(_, area) => *area,
|
||||
Self::Layout(area) => *area,
|
||||
}
|
||||
self.into()
|
||||
}
|
||||
|
||||
fn clip (
|
||||
|
|
@ -2660,6 +2632,24 @@ macro_rules! eval_xy (
|
|||
}
|
||||
}
|
||||
|
||||
impl From<&Tui> for XYWH<u16> {
|
||||
fn from (screen: &Tui) -> XYWH<u16> {
|
||||
match screen {
|
||||
Tui::Draw(_, area) => *area,
|
||||
Tui::Layout(area) => *area,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a: 'b, 'b> From<&'a mut Tui> for &'b mut XYWH<u16> {
|
||||
fn from (screen: &'a mut Tui) -> &'b mut XYWH<u16> {
|
||||
match screen {
|
||||
Tui::Draw(_, area) => area,
|
||||
Tui::Layout(area) => area,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn fill_char (c: char) -> impl Draw<Tui> {
|
||||
draw(move|to: &mut Tui|Ok(Some(to.update(&|cell,_,_|{
|
||||
cell.set_char(c);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue