mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-07-17 15:56:57 +02:00
Compare commits
No commits in common. "aa0dd37d88166052eef706eae6be5b649dbcca4b" and "ddc53b23c2c435f3544b4c2203d576ec80ddc847" have entirely different histories.
aa0dd37d88
...
ddc53b23c2
7 changed files with 37 additions and 85 deletions
2
dizzle
2
dizzle
|
|
@ -1 +1 @@
|
||||||
Subproject commit 0050385e63ea5d3ab9be7c495dae5fc635396cf0
|
Subproject commit af2a10751f87caef8e5526d1f692c941b8de8357
|
||||||
10
src/draw.rs
10
src/draw.rs
|
|
@ -24,15 +24,7 @@ use crate::*;
|
||||||
pub trait Screen: Xy<Self::Unit> + Wh<Self::Unit> + Send + Sync + Sized {
|
pub trait Screen: Xy<Self::Unit> + Wh<Self::Unit> + Send + Sync + Sized {
|
||||||
type Unit: Coord;
|
type Unit: Coord;
|
||||||
/// Render drawable in subarea specified by `area`
|
/// Render drawable in subarea specified by `area`
|
||||||
fn show (&mut self, content: impl Draw<Self>) -> Perhaps<XYWH<Self::Unit>>;
|
fn show <T: Draw<Self>> (&mut self, content: T) -> Perhaps<XYWH<Self::Unit>>;
|
||||||
/// Get current clipping area
|
|
||||||
fn area (&self) -> XYWH<Self::Unit>;
|
|
||||||
/// Set clipping area
|
|
||||||
fn clip <T> (
|
|
||||||
&mut self,
|
|
||||||
area: impl Into<Option<XYWH<Self::Unit>>>,
|
|
||||||
draw: impl FnOnce(&mut Self)->T
|
|
||||||
) -> T;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implement the [Draw] trait for a particular drawable and [Screen].
|
/// Implement the [Draw] trait for a particular drawable and [Screen].
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,3 @@ pub trait Coord: Send + Sync + Copy
|
||||||
/// Convert to [AtomicUsize].
|
/// Convert to [AtomicUsize].
|
||||||
fn atomic (self) -> AtomicUsize { AtomicUsize::new(self.into()) }
|
fn atomic (self) -> AtomicUsize { AtomicUsize::new(self.into()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TUI works in u16 coordinates.
|
|
||||||
impl Coord for u16 {
|
|
||||||
fn plus (self, other: Self) -> Self { self.saturating_add(other) }
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -71,16 +71,16 @@ pub trait Layout<S: Screen>: Draw<S> + Sized {
|
||||||
Push::XY(self, x.into(), y.into())
|
Push::XY(self, x.into(), y.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn align (self, azimuth: impl Into<Option<Azimuth>>) -> Align<Self> {
|
fn align (self, azimuth: impl Into<Option<Azimuth>>) -> impl Draw<S> {
|
||||||
Align(azimuth.into(), self)
|
Align(azimuth.into(), self)
|
||||||
}
|
}
|
||||||
fn align_c (self) -> Align<Self> {
|
fn align_c (self) -> impl Draw<S> {
|
||||||
Align(Some(Azimuth::C), self)
|
Align(Some(Azimuth::C), self)
|
||||||
}
|
}
|
||||||
fn align_x (self) -> Align<Self> {
|
fn align_x (self) -> impl Draw<S> {
|
||||||
Align(Some(Azimuth::X), self)
|
Align(Some(Azimuth::X), self)
|
||||||
}
|
}
|
||||||
fn align_y (self) -> Align<Self> {
|
fn align_y (self) -> impl Draw<S> {
|
||||||
Align(Some(Azimuth::Y), self)
|
Align(Some(Azimuth::Y), self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -287,27 +287,8 @@ impl_draw!(<T: Screen, I: Draw<T>, X: Into<Option<T::Unit>>,>|self: Pad<T, I, X>
|
||||||
|
|
||||||
pub struct Align<T>(Option<Azimuth>, T);
|
pub struct Align<T>(Option<Azimuth>, T);
|
||||||
|
|
||||||
impl_draw!(<S: Screen, T: Draw<S>,>|self: Align<T>, to: S|{
|
impl_draw!(<S: Screen, T: Draw<S>,>|self: Align<T>, _to: S|{
|
||||||
use Azimuth::*;
|
todo!()
|
||||||
let XYWH(x0, y0, w0, h0) = to.area();
|
|
||||||
if let Some(XYWH(x, y, w, h)) = self.1.layout(to.area())? {
|
|
||||||
to.clip(match self.0 {
|
|
||||||
Some(NW) => XYWH(x0, y0, w, h),
|
|
||||||
Some(N) => XYWH(x0 + w0.sub(w) / 2.into(), y0, w, h),
|
|
||||||
Some(NE) => XYWH((x0 + w0).sub(w), y0, w, h),
|
|
||||||
Some(W) => XYWH(x0, y0 + h0.sub(h) / 2.into(), w, h),
|
|
||||||
Some(C) => XYWH(x0 + w0.sub(w) / 2.into(), y0 + h0.sub(h) / 2.into(), w, h),
|
|
||||||
Some(E) => XYWH((x0 + w0).sub(w), y0 + h0.sub(h) / 2.into(), w, h),
|
|
||||||
Some(SW) => XYWH(x0, (y0 + h0).sub(h), w, h),
|
|
||||||
Some(S) => XYWH(x0 + w0.sub(w) / 2.into(), (y0 + h0).sub(h), w, h),
|
|
||||||
Some(SE) => XYWH((x0 + w0).sub(w), (y0 + h0).sub(h), w, h),
|
|
||||||
Some(X) => XYWH(x0 + w0.sub(w) / 2.into(), y, w, h),
|
|
||||||
Some(Y) => XYWH(x, y0 + h0.sub(h) / 2.into(), w, h),
|
|
||||||
None => to.area()
|
|
||||||
}, |to|self.1.draw(to))
|
|
||||||
} else {
|
|
||||||
self.1.draw(to)
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Where is [0, 0] located?
|
/// Where is [0, 0] located?
|
||||||
|
|
@ -334,13 +315,10 @@ pub fn area <S: Screen, T: Draw<S>, U: Into<Option<XYWH<S::Unit>>>> (
|
||||||
Area(origin.into(), it)
|
Area(origin.into(), it)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Area<S: Screen, T: Draw<S>>(
|
pub struct Area<S: Screen, T: Draw<S>>(Option<XYWH<S::Unit>>, T);
|
||||||
pub Option<XYWH<S::Unit>>,
|
|
||||||
pub T
|
|
||||||
);
|
|
||||||
|
|
||||||
impl_draw!(<S: Screen, T: Draw<S>,>|self: Area<S, T>, to: S|{
|
impl_draw!(<S: Screen, T: Draw<S>,>|self: Area<S, T>, _to: S|{
|
||||||
to.clip(self.0, |to|self.1.draw(to))
|
todo!()
|
||||||
});
|
});
|
||||||
|
|
||||||
pub struct Origin<T>(Option<Azimuth>, T);
|
pub struct Origin<T>(Option<Azimuth>, T);
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,27 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use Azimuth::*;
|
||||||
|
|
||||||
pub const fn east <S: Screen, A: Draw<S>, B: Draw<S>> (a: A, b: B) -> impl Draw<S> {
|
pub const fn east <T: Screen> (a: impl Draw<T>, b: impl Draw<T>) -> impl Draw<T> {
|
||||||
Split::East.half(a, b)
|
Split::East.half(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn north <S: Screen, A: Draw<S>, B: Draw<S>> (a: A, b: B) -> impl Draw<S> {
|
pub const fn north <T: Screen> (a: impl Draw<T>, b: impl Draw<T>) -> impl Draw<T> {
|
||||||
Split::North.half(a, b)
|
Split::North.half(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn west <S: Screen, A: Draw<S>, B: Draw<S>> (a: A, b: B) -> impl Draw<S> {
|
pub const fn west <T: Screen> (a: impl Draw<T>, b: impl Draw<T>) -> impl Draw<T> {
|
||||||
Split::West.half(a, b)
|
Split::West.half(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn south <S: Screen, A: Draw<S>, B: Draw<S>> (a: A, b: B) -> impl Draw<S> {
|
pub const fn south <T: Screen> (a: impl Draw<T>, b: impl Draw<T>) -> impl Draw<T> {
|
||||||
Split::South.half(a, b)
|
Split::South.half(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn above <S: Screen, A: Draw<S>, B: Draw<S>> (a: A, b: B) -> impl Draw<S> {
|
pub const fn above <T: Screen> (a: impl Draw<T>, b: impl Draw<T>) -> impl Draw<T> {
|
||||||
Split::Above.half(a, b)
|
Split::Above.half(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn below <S: Screen, A: Draw<S>, B: Draw<S>> (a: A, b: B) -> impl Draw<S> {
|
pub const fn below <T: Screen> (a: impl Draw<T>, b: impl Draw<T>) -> impl Draw<T> {
|
||||||
Split::Below.half(a, b)
|
Split::Below.half(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,8 +47,8 @@ impl Split {
|
||||||
/// let _ = Split::East.half("", "");
|
/// let _ = Split::East.half("", "");
|
||||||
/// let _ = Split::West.half("", "");
|
/// let _ = Split::West.half("", "");
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn half <S: Screen, A: Draw<S>, B: Draw<S>> (&self, a: A, b: B) -> impl Draw<S> {
|
pub const fn half <T: Screen> (&self, a: impl Draw<T>, b: impl Draw<T>) -> impl Draw<T> {
|
||||||
thunk(move|to: &mut S|{
|
thunk(move|to: &mut T|{
|
||||||
let (area_a, area_b) = to.xywh().split_half(self);
|
let (area_a, area_b) = to.xywh().split_half(self);
|
||||||
let (origin_a, origin_b) = self.origins();
|
let (origin_a, origin_b) = self.origins();
|
||||||
let a = a.align(origin_a);
|
let a = a.align(origin_a);
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,8 @@ pub fn eval_view <'a, O: Screen + 'a, S> (
|
||||||
).draw(output),
|
).draw(output),
|
||||||
|
|
||||||
// Second `frags.next()` calls returns the namespace member.
|
// Second `frags.next()` calls returns the namespace member.
|
||||||
Some("bsp") => eval_enum!("bsp", output, state, frags.next(), arg0, Split {
|
Some("bsp") => {
|
||||||
|
eval_enum!("bsp", output, state, frags.next(), arg0, Split {
|
||||||
"n" => North,
|
"n" => North,
|
||||||
"s" => South,
|
"s" => South,
|
||||||
"e" => East,
|
"e" => East,
|
||||||
|
|
@ -129,7 +130,8 @@ pub fn eval_view <'a, O: Screen + 'a, S> (
|
||||||
}).half(
|
}).half(
|
||||||
thunk(move|output: &mut O|{state.interpret(output, &arg0)}),
|
thunk(move|output: &mut O|{state.interpret(output, &arg0)}),
|
||||||
thunk(move|output: &mut O|{state.interpret(output, &arg1)}),
|
thunk(move|output: &mut O|{state.interpret(output, &arg1)}),
|
||||||
).draw(output),
|
).draw(output)
|
||||||
|
},
|
||||||
|
|
||||||
Some("align") => {
|
Some("align") => {
|
||||||
let content = thunk(move|output: &mut O|{state.interpret(output, &arg0)});
|
let content = thunk(move|output: &mut O|{state.interpret(output, &arg0)});
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use ratatui::{prelude::{Style, Position, Backend, Color}};
|
use ratatui::{prelude::{Style, Position, Backend, Color}};
|
||||||
|
|
||||||
|
/// TUI works in u16 coordinates.
|
||||||
|
impl Coord for u16 { fn plus (self, other: Self) -> Self { self.saturating_add(other) } }
|
||||||
|
|
||||||
impl Screen for Tui {
|
impl Screen for Tui {
|
||||||
type Unit = u16;
|
type Unit = u16;
|
||||||
/// Render drawable in subarea specified by `area`
|
/// Render drawable in subarea specified by `area`
|
||||||
fn show (&mut self, content: impl Draw<Self>) -> Perhaps<XYWH<u16>> {
|
fn show <'t, T: Draw<Self>> (&mut self, content: T) -> Perhaps<XYWH<u16>> {
|
||||||
let previous_area = self.1;
|
let previous_area = self.1;
|
||||||
Ok(if let Some(area) = content.layout(self.1)? {
|
Ok(if let Some(area) = content.layout(self.1)? {
|
||||||
self.1 = area;
|
self.1 = area;
|
||||||
|
|
@ -18,25 +21,6 @@ impl Screen for Tui {
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get current clipping area
|
|
||||||
fn area (&self) -> XYWH<Self::Unit> {
|
|
||||||
self.1
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clip <T> (
|
|
||||||
&mut self,
|
|
||||||
area: impl Into<Option<XYWH<u16>>>,
|
|
||||||
draw: impl FnOnce(&mut Self)->T
|
|
||||||
) -> T {
|
|
||||||
let prev = self.1;
|
|
||||||
if let Some(area) = area.into() {
|
|
||||||
self.1 = area.into();
|
|
||||||
}
|
|
||||||
let result = draw(self);
|
|
||||||
self.1 = prev;
|
|
||||||
result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enable TUI output for state struct.
|
/// Enable TUI output for state struct.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue