mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-04-03 13:30:44 +02:00
This commit is contained in:
parent
cdc513060d
commit
cf57f44933
2 changed files with 115 additions and 20 deletions
2
dizzle
2
dizzle
|
|
@ -1 +1 @@
|
|||
Subproject commit 44b2be57ca8d1f69a95f2eb02f4b5474ec77ac0a
|
||||
Subproject commit 192a1d8257a9f2ad43ebceacb7b5ca348c601471
|
||||
133
src/space.rs
133
src/space.rs
|
|
@ -57,11 +57,47 @@ impl<N: Coord> XYWH<N> {
|
|||
}
|
||||
|
||||
/// Something that has `[0, 0]` at a particular point.
|
||||
pub trait HasOrigin {
|
||||
fn origin (&self) -> Origin;
|
||||
pub trait HasOrigin { fn origin (&self) -> Origin;
|
||||
}
|
||||
impl<T: AsRef<Origin>> HasOrigin for T {
|
||||
fn origin (&self) -> Origin { *self.as_ref() }
|
||||
impl<T: AsRef<Origin>> HasOrigin for T { fn origin (&self) -> Origin { *self.as_ref() } }
|
||||
pub struct Anchor<T>(Origin, T);
|
||||
impl<T> AsRef<Origin> for Anchor<T> {
|
||||
fn as_ref (&self) -> &Origin {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
impl<T: Screen, U: Draw<T>> Draw<T> for Anchor<U> {
|
||||
fn draw (self, to: &mut T) -> Usually<XYWH<T::Unit>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn origin_nw <T: Screen> (a: impl Draw<T>) -> impl Draw<T> {
|
||||
Anchor(Origin::NW, a)
|
||||
}
|
||||
pub const fn origin_n <T: Screen> (a: impl Draw<T>) -> impl Draw<T> {
|
||||
Anchor(Origin::N, a)
|
||||
}
|
||||
pub const fn origin_ne <T: Screen> (a: impl Draw<T>) -> impl Draw<T> {
|
||||
Anchor(Origin::NE, a)
|
||||
}
|
||||
pub const fn origin_w <T: Screen> (a: impl Draw<T>) -> impl Draw<T> {
|
||||
Anchor(Origin::W, a)
|
||||
}
|
||||
pub const fn origin_c <T: Screen> (a: impl Draw<T>) -> impl Draw<T> {
|
||||
Anchor(Origin::C, a)
|
||||
}
|
||||
pub const fn origin_e <T: Screen> (a: impl Draw<T>) -> impl Draw<T> {
|
||||
Anchor(Origin::E, a)
|
||||
}
|
||||
pub const fn origin_sw <T: Screen> (a: impl Draw<T>) -> impl Draw<T> {
|
||||
Anchor(Origin::SW, a)
|
||||
}
|
||||
pub const fn origin_s <T: Screen> (a: impl Draw<T>) -> impl Draw<T> {
|
||||
Anchor(Origin::S, a)
|
||||
}
|
||||
pub const fn origin_se <T: Screen> (a: impl Draw<T>) -> impl Draw<T> {
|
||||
Anchor(Origin::SE, a)
|
||||
}
|
||||
|
||||
/// Where is [0, 0] located?
|
||||
|
|
@ -203,21 +239,6 @@ impl Split {
|
|||
Self::Below => (C, C),
|
||||
}
|
||||
}
|
||||
/// Iterate over a collection of renderables:
|
||||
///
|
||||
/// ```
|
||||
/// use tengri::draw::{Origin::*, Split::*};
|
||||
/// let _ = Below.iter([
|
||||
/// NW.align(W(15).max(W(10).min("Leftbar"))),
|
||||
/// NE.align(W(12).max(W(10).min("Rightbar"))),
|
||||
/// Center.align(W(40).max(H(20.max("Center"))))
|
||||
/// ].iter(), |x|x);
|
||||
/// ```
|
||||
pub fn iter <T: Screen, U: Draw<T>, F: Fn(U)->dyn Draw<T>> (
|
||||
_items: impl Iterator<Item = U>, _cb: F
|
||||
) -> impl Draw<T> {
|
||||
thunk(move|_to: &mut T|{ todo!() })
|
||||
}
|
||||
}
|
||||
|
||||
/// Horizontal axis.
|
||||
|
|
@ -385,3 +406,77 @@ pub const fn wh_clip <T: Screen> (
|
|||
) -> impl Draw<T> {
|
||||
thunk(move|to: &mut T|draw.draw(todo!()))
|
||||
}
|
||||
|
||||
pub const fn wh_full <T: Screen> (a: impl Draw<T>) -> impl Draw<T> { a }
|
||||
pub const fn w_full <T: Screen> (a: impl Draw<T>) -> impl Draw<T> { a }
|
||||
pub const fn h_full <T: Screen> (a: impl Draw<T>) -> impl Draw<T> { a }
|
||||
|
||||
#[macro_export] macro_rules! north {
|
||||
($($tt:tt)*) => { unimplemented!() };
|
||||
}
|
||||
#[macro_export] macro_rules! south {
|
||||
($($tt:tt)*) => { unimplemented!() };
|
||||
}
|
||||
#[macro_export] macro_rules! east {
|
||||
($($tt:tt)*) => { unimplemented!() };
|
||||
}
|
||||
#[macro_export] macro_rules! west {
|
||||
($($tt:tt)*) => { unimplemented!() };
|
||||
}
|
||||
#[macro_export] macro_rules! above {
|
||||
($($tt:tt)*) => { unimplemented!() };
|
||||
}
|
||||
#[macro_export] macro_rules! below {
|
||||
($($tt:tt)*) => { unimplemented!() };
|
||||
}
|
||||
|
||||
/// Iterate over a collection of renderables:
|
||||
///
|
||||
/// ```
|
||||
/// use tengri::draw::{Origin::*, Split::*};
|
||||
/// let _ = Below.iter([
|
||||
/// NW.align(W(15).max(W(10).min("Leftbar"))),
|
||||
/// NE.align(W(12).max(W(10).min("Rightbar"))),
|
||||
/// Center.align(W(40).max(H(20.max("Center"))))
|
||||
/// ].iter(), |x|x);
|
||||
/// ```
|
||||
pub fn iter <
|
||||
T: Screen,
|
||||
V: Fn()->I,
|
||||
I: Iterator<Item = dyn Draw<T>>,
|
||||
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
|
||||
> (_items: V, _cb: F) -> impl Draw<T> {
|
||||
thunk(move|_to: &mut T|{ todo!() })
|
||||
}
|
||||
pub fn iter_north <
|
||||
T: Screen,
|
||||
V: Fn()->I,
|
||||
I: Iterator<Item = dyn Draw<T>>,
|
||||
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
|
||||
> (_items: V, _cb: F) -> impl Draw<T> {
|
||||
thunk(move|_to: &mut T|{ todo!() })
|
||||
}
|
||||
pub fn iter_east <
|
||||
T: Screen,
|
||||
V: Fn()->I,
|
||||
I: Iterator<Item = dyn Draw<T>>,
|
||||
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
|
||||
> (_items: V, _cb: F) -> impl Draw<T> {
|
||||
thunk(move|_to: &mut T|{ todo!() })
|
||||
}
|
||||
pub fn iter_south <
|
||||
T: Screen,
|
||||
V: Fn()->I,
|
||||
I: Iterator<Item = dyn Draw<T>>,
|
||||
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
|
||||
> (_items: V, _cb: F) -> impl Draw<T> {
|
||||
thunk(move|_to: &mut T|{ todo!() })
|
||||
}
|
||||
pub fn iter_west <
|
||||
T: Screen,
|
||||
V: Fn()->I,
|
||||
I: Iterator<Item = dyn Draw<T>>,
|
||||
F: Fn(&dyn Draw<T>)->dyn Draw<T>,
|
||||
> (_items: V, _cb: F) -> impl Draw<T> {
|
||||
thunk(move|_to: &mut T|{ todo!() })
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue