remove last color conversion from render loop

This commit is contained in:
🪞👃🪞 2025-01-20 16:27:16 +01:00
parent a31de6e819
commit 7ad574cf2a
9 changed files with 122 additions and 47 deletions

View file

@ -50,17 +50,17 @@ try_from_expr!(<'a, E>: Align<RenderBox<'a, E>>: |state, iter|
}
});
impl<A> Align<A> {
pub fn c (a: A) -> Self { Self(Alignment::Center, a) }
pub fn x (a: A) -> Self { Self(Alignment::X, a) }
pub fn y (a: A) -> Self { Self(Alignment::Y, a) }
pub fn n (a: A) -> Self { Self(Alignment::N, a) }
pub fn s (a: A) -> Self { Self(Alignment::S, a) }
pub fn e (a: A) -> Self { Self(Alignment::E, a) }
pub fn w (a: A) -> Self { Self(Alignment::W, a) }
pub fn nw (a: A) -> Self { Self(Alignment::NW, a) }
pub fn sw (a: A) -> Self { Self(Alignment::SW, a) }
pub fn ne (a: A) -> Self { Self(Alignment::NE, a) }
pub fn se (a: A) -> Self { Self(Alignment::SE, a) }
#[inline] pub fn c (a: A) -> Self { Self(Alignment::Center, a) }
#[inline] pub fn x (a: A) -> Self { Self(Alignment::X, a) }
#[inline] pub fn y (a: A) -> Self { Self(Alignment::Y, a) }
#[inline] pub fn n (a: A) -> Self { Self(Alignment::N, a) }
#[inline] pub fn s (a: A) -> Self { Self(Alignment::S, a) }
#[inline] pub fn e (a: A) -> Self { Self(Alignment::E, a) }
#[inline] pub fn w (a: A) -> Self { Self(Alignment::W, a) }
#[inline] pub fn nw (a: A) -> Self { Self(Alignment::NW, a) }
#[inline] pub fn sw (a: A) -> Self { Self(Alignment::SW, a) }
#[inline] pub fn ne (a: A) -> Self { Self(Alignment::NE, a) }
#[inline] pub fn se (a: A) -> Self { Self(Alignment::SE, a) }
}
impl<E: Output, A: Content<E>> Content<E> for Align<A> {
fn content (&self) -> impl Render<E> {

View file

@ -55,12 +55,12 @@ try_from_expr!(<'a, E>: Bsp<RenderBox<'a, E>, RenderBox<'a, E>>: |state, iter| {
}
});
impl<A, B> Bsp<A, B> {
pub fn n (a: A, b: B) -> Self { Self(North, a, b) }
pub fn s (a: A, b: B) -> Self { Self(South, a, b) }
pub fn e (a: A, b: B) -> Self { Self(East, a, b) }
pub fn w (a: A, b: B) -> Self { Self(West, a, b) }
pub fn a (a: A, b: B) -> Self { Self(Above, a, b) }
pub fn b (a: A, b: B) -> Self { Self(Below, a, b) }
#[inline] pub fn n (a: A, b: B) -> Self { Self(North, a, b) }
#[inline] pub fn s (a: A, b: B) -> Self { Self(South, a, b) }
#[inline] pub fn e (a: A, b: B) -> Self { Self(East, a, b) }
#[inline] pub fn w (a: A, b: B) -> Self { Self(West, a, b) }
#[inline] pub fn a (a: A, b: B) -> Self { Self(Above, a, b) }
#[inline] pub fn b (a: A, b: B) -> Self { Self(Below, a, b) }
}
pub trait BspAreas<E: Output, A: Content<E>, B: Content<E>> {
fn direction (&self) -> Direction;

View file

@ -1,10 +1,10 @@
use crate::*;
/// Show an item only when a condition is true.
pub struct When<A>(pub bool, pub A);
impl<A> When<A> { pub fn new (c: bool, a: A) -> Self { Self(c, a) } }
impl<A> When<A> { #[inline] pub fn new (c: bool, a: A) -> Self { Self(c, a) } }
/// Show one item if a condition is true and another if the condition is false
pub struct Either<A, B>(pub bool, pub A, pub B);
impl<A, B> Either<A, B> { pub fn new (c: bool, a: A, b: B) -> Self { Self(c, a, b) } }
impl<A, B> Either<A, B> { #[inline] pub fn new (c: bool, a: A, b: B) -> Self { Self(c, a, b) } }
try_from_expr!(<'a, E>: When<RenderBox<'a, E>>: |state, iter| {
if let Some(Token { value: Value::Key("when"), .. }) = iter.peek() {
let _ = iter.next().unwrap();

View file

@ -1,5 +1,5 @@
use crate::*;
pub fn map_south<O: Output>(
#[inline] pub fn map_south<O: Output>(
item_offset: O::Unit,
item_height: O::Unit,
item: impl Content<O>
@ -7,7 +7,7 @@ pub fn map_south<O: Output>(
Push::y(item_offset, Fixed::y(item_height, Fill::x(item)))
}
pub fn map_south_west<O: Output>(
#[inline] pub fn map_south_west<O: Output>(
item_offset: O::Unit,
item_height: O::Unit,
item: impl Content<O>
@ -15,7 +15,7 @@ pub fn map_south_west<O: Output>(
Push::y(item_offset, Align::nw(Fixed::y(item_height, Fill::x(item))))
}
pub fn map_east<O: Output>(
#[inline] pub fn map_east<O: Output>(
item_offset: O::Unit,
item_width: O::Unit,
item: impl Content<O>

View file

@ -25,9 +25,9 @@ macro_rules! transform_xy {
($x:literal $y:literal $xy:literal |$self:ident : $Enum:ident, $to:ident|$area:expr) => {
pub enum $Enum<T> { X(T), Y(T), XY(T) }
impl<T> $Enum<T> {
pub fn x (item: T) -> Self { Self::X(item) }
pub fn y (item: T) -> Self { Self::Y(item) }
pub fn xy (item: T) -> Self { Self::XY(item) }
#[inline] pub fn x (item: T) -> Self { Self::X(item) }
#[inline] pub fn y (item: T) -> Self { Self::Y(item) }
#[inline] pub fn xy (item: T) -> Self { Self::XY(item) }
}
impl<'a, E: Output + 'a, T: ViewContext<'a, E>> TryFromAtom<'a, T>
for $Enum<RenderBox<'a, E>> {
@ -71,9 +71,9 @@ macro_rules! transform_xy_unit {
($x:literal $y:literal $xy:literal |$self:ident : $Enum:ident, $to:ident|$layout:expr) => {
pub enum $Enum<U, T> { X(U, T), Y(U, T), XY(U, U, T), }
impl<U, T> $Enum<U, T> {
pub fn x (x: U, item: T) -> Self { Self::X(x, item) }
pub fn y (y: U, item: T) -> Self { Self::Y(y, item) }
pub fn xy (x: U, y: U, item: T) -> Self { Self::XY(x, y, item) }
#[inline] pub fn x (x: U, item: T) -> Self { Self::X(x, item) }
#[inline] pub fn y (y: U, item: T) -> Self { Self::Y(y, item) }
#[inline] pub fn xy (x: U, y: U, item: T) -> Self { Self::XY(x, y, item) }
}
impl<'a, E: Output + 'a, T: ViewContext<'a, E>> TryFromAtom<'a, T>
for $Enum<E::Unit, RenderBox<'a, E>> {
@ -118,12 +118,12 @@ macro_rules! transform_xy_unit {
}
}
impl<U: Copy + Coordinate, T> $Enum<U, T> {
pub fn dx (&self) -> U {
#[inline] pub fn dx (&self) -> U {
match self {
Self::X(x, _) => *x, Self::Y(_, _) => 0.into(), Self::XY(x, _, _) => *x,
}
}
pub fn dy (&self) -> U {
#[inline] pub fn dy (&self) -> U {
match self {
Self::X(_, _) => 0.into(), Self::Y(y, _) => *y, Self::XY(_, y, _) => *y,
}