mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-07-17 15:56:57 +02:00
add origin and align methods to Layout trait
This commit is contained in:
parent
09463649c6
commit
13c886d9e0
18 changed files with 333 additions and 248 deletions
36
src/draw.rs
36
src/draw.rs
|
|
@ -3,32 +3,34 @@ use crate::*;
|
|||
/// Output target.
|
||||
///
|
||||
/// ```
|
||||
/// use tengri::{*, draw::*};
|
||||
///
|
||||
/// struct TestOut<T: Screen<Unit = u16>>(T);
|
||||
///
|
||||
/// impl<T: Screen<Unit = u16>> Screen for TestOut {
|
||||
/// use tengri::*;
|
||||
/// struct TestOut { w: u16, h: u16 };
|
||||
/// impl Wide<u16> for TestOut {}
|
||||
/// impl Tall<u16> for TestOut {}
|
||||
/// impl Xy<u16> for TestOut { fn x (&self) -> u16 { 0 } fn y (&self) -> u16 { 0 } }
|
||||
/// impl Screen for TestOut {
|
||||
/// type Unit = u16;
|
||||
/// fn show <D: Draw<Self> + ?Sized> (&mut self, _: D) {
|
||||
/// fn show <D: Draw<Self>> (&mut self, _: D) -> Drawn<u16> {
|
||||
/// println!("placed");
|
||||
/// ()
|
||||
/// Ok(None)
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// impl_draw!(|self: String, to: TestOut<u16>|{
|
||||
/// to.area_mut().set_w(self.len() as u16);
|
||||
/// impl_draw!(|self: String, to: TestOut|{
|
||||
/// to.w = self.len() as u16;
|
||||
/// Ok(None)
|
||||
/// });
|
||||
/// ```
|
||||
pub trait Screen: Xy<Self::Unit> + Wh<Self::Unit> + Send + Sync + Sized {
|
||||
type Unit: Coord;
|
||||
/// Render drawable in subarea specified by `area`
|
||||
fn show <'t, T: Draw<Self>> (&mut self, content: T) -> Perhaps<XYWH<Self::Unit>>;
|
||||
fn show <T: Draw<Self>> (&mut self, content: T) -> Perhaps<XYWH<Self::Unit>>;
|
||||
}
|
||||
|
||||
/// Implement the [Draw] trait for a particular drawable and [Screen].
|
||||
///
|
||||
/// ```
|
||||
/// use tengri::{*, draw::*, term::*};
|
||||
/// use tengri::*;
|
||||
/// struct MyDrawable;
|
||||
/// impl_draw!(|self: MyDrawable, to: Tui|{
|
||||
/// todo!("your draw logic")
|
||||
|
|
@ -60,7 +62,7 @@ pub trait Screen: Xy<Self::Unit> + Wh<Self::Unit> + Send + Sync + Sized {
|
|||
/// a [Draw]able.
|
||||
///
|
||||
/// ```
|
||||
/// use tengri::{*, draw::*, term::*};
|
||||
/// use tengri::*;
|
||||
/// struct MyWidget(bool);
|
||||
/// impl Draw<Tui> for MyWidget {
|
||||
/// fn draw (self, to: &mut Tui) -> Perhaps<XYWH<u16>> {
|
||||
|
|
@ -106,6 +108,12 @@ pub trait View<T: Screen> {
|
|||
fn view (&self) -> impl Draw<T>;
|
||||
}
|
||||
|
||||
impl<T: Screen> View<T> for () {
|
||||
fn view (&self) -> impl Draw<T> {
|
||||
()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Screen, V: View<T>> Draw<T> for &V {
|
||||
fn draw (self, to: &mut T) -> Perhaps<XYWH<T::Unit>> {
|
||||
self.view().draw(to)
|
||||
|
|
@ -114,15 +122,11 @@ impl<T: Screen, V: View<T>> Draw<T> for &V {
|
|||
|
||||
features! {
|
||||
"draw": [
|
||||
align,
|
||||
area,
|
||||
azimuth,
|
||||
color,
|
||||
coord,
|
||||
iter,
|
||||
layout,
|
||||
lrtb,
|
||||
origin,
|
||||
sizer,
|
||||
space,
|
||||
split,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue