mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-02-21 18:49:04 +01:00
refactor: remove Out::{Area, Size}. 7 errors left...
This commit is contained in:
parent
997610f23e
commit
07a1206c2f
4 changed files with 253 additions and 215 deletions
|
|
@ -15,7 +15,7 @@ use crate::*;
|
|||
/// fn area_mut (&mut self) -> &mut [u16;4] {
|
||||
/// &mut self.0
|
||||
/// }
|
||||
/// fn place_at <T: Draw<Self> + ?Sized> (&mut self, area: [u16;4], _: &T) {
|
||||
/// fn place_at <T: Draw<Self> + ?Sized> (&mut self, area: XYWH<u16>, _: &T) {
|
||||
/// println!("place_at: {area:?}");
|
||||
/// ()
|
||||
/// }
|
||||
|
|
@ -29,20 +29,14 @@ use crate::*;
|
|||
pub trait Out: Send + Sync + Sized {
|
||||
/// Unit of length
|
||||
type Unit: Coord;
|
||||
/// Rectangle without offset
|
||||
type Size: HasWH<Self::Unit>;
|
||||
/// Rectangle with offset
|
||||
type Area: HasXYWH<Self::Unit>;
|
||||
/// Current output area
|
||||
fn area (&self) -> Self::Area;
|
||||
fn area (&self) -> XYWH<Self::Unit>;
|
||||
/// Mutable pointer to area.
|
||||
fn area_mut (&mut self) -> &mut Self::Area;
|
||||
fn area_mut (&mut self) -> &mut XYWH<Self::Unit>;
|
||||
/// Render drawable in area specified by `area`
|
||||
fn place_at <'t, T: Draw<Self> + ?Sized> (&mut self, area: Self::Area, content: &'t T);
|
||||
fn place_at <'t, T: Draw<Self> + ?Sized> (&mut self, area: XYWH<Self::Unit>, content: &'t T);
|
||||
/// Render drawable in area specified by `T::layout(self.area())`
|
||||
#[inline] fn place <'t, T: Content<Self> + ?Sized> (
|
||||
&mut self, content: &'t T
|
||||
) {
|
||||
#[inline] fn place <'t, T: Content<Self> + ?Sized> (&mut self, content: &'t T) {
|
||||
self.place_at(content.layout(self.area()), content)
|
||||
}
|
||||
}
|
||||
|
|
@ -79,15 +73,17 @@ pub trait Lay<O: Out>: Sized {}
|
|||
|
||||
/// Drawable area of display.
|
||||
pub trait Layout<O: Out> {
|
||||
fn x (&self, to: O::Area) -> O::Unit { to.x() }
|
||||
fn y (&self, to: O::Area) -> O::Unit { to.y() }
|
||||
fn w_min (&self, _t: O::Area) -> O::Unit { 0.into() }
|
||||
fn w_max (&self, to: O::Area) -> O::Unit { to.w() }
|
||||
fn w (&self, to: O::Area) -> O::Unit { to.w().max(self.w_min(to)).min(self.w_max(to)) }
|
||||
fn h_min (&self, _t: O::Area) -> O::Unit { 0.into() }
|
||||
fn h_max (&self, to: O::Area) -> O::Unit { to.h() }
|
||||
fn h (&self, to: O::Area) -> O::Unit { to.h().max(self.h_min(to)).min(self.h_max(to)) }
|
||||
fn layout (&self, to: O::Area) -> O::Area { [self.x(to), self.y(to), self.w(to), self.h(to)].into() }
|
||||
fn x (&self, to: XYWH<O::Unit>) -> O::Unit { to.x() }
|
||||
fn y (&self, to: XYWH<O::Unit>) -> O::Unit { to.y() }
|
||||
fn w_min (&self, _t: XYWH<O::Unit>) -> O::Unit { 0.into() }
|
||||
fn w_max (&self, to: XYWH<O::Unit>) -> O::Unit { to.w() }
|
||||
fn w (&self, to: XYWH<O::Unit>) -> O::Unit { to.w().max(self.w_min(to)).min(self.w_max(to)) }
|
||||
fn h_min (&self, _t: XYWH<O::Unit>) -> O::Unit { 0.into() }
|
||||
fn h_max (&self, to: XYWH<O::Unit>) -> O::Unit { to.h() }
|
||||
fn h (&self, to: XYWH<O::Unit>) -> O::Unit { to.h().max(self.h_min(to)).min(self.h_max(to)) }
|
||||
fn layout (&self, to: XYWH<O::Unit>) -> XYWH<O::Unit> {
|
||||
XYWH(self.x(to), self.y(to), self.w(to), self.h(to))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HasContent<O: Out> {
|
||||
|
|
@ -111,9 +107,16 @@ pub trait Coord: Send + Sync + Copy
|
|||
+ Into<usize>
|
||||
+ Into<f64>
|
||||
{
|
||||
fn zero () -> Self { 0.into() }
|
||||
fn plus (self, other: Self) -> Self;
|
||||
fn minus (self, other: Self) -> Self { if self >= other { self - other } else { 0.into() } }
|
||||
fn minus (self, other: Self) -> Self {
|
||||
if self >= other { self - other } else { 0.into() }
|
||||
}
|
||||
fn atomic (self) -> AtomicUsize {
|
||||
AtomicUsize::new(self.into())
|
||||
}
|
||||
fn zero () -> Self {
|
||||
0.into()
|
||||
}
|
||||
}
|
||||
|
||||
// Something that has an origin point (X, Y).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue