Compare commits

...

2 commits

Author SHA1 Message Date
same mf who else
bea88ac58d fix(draw): mismatches
Some checks failed
/ build (push) Has been cancelled
2026-03-25 22:39:39 +02:00
same mf who else
30d378a6ee fix(play): def_command 2026-03-25 22:27:31 +02:00
6 changed files with 30 additions and 18 deletions

View file

@ -6,7 +6,10 @@ pub(crate) use ::palette::{
}; };
use rand::distributions::uniform::UniformSampler; use rand::distributions::uniform::UniformSampler;
pub fn rgb (r: u8, g: u8, b: u8) -> ItemColor { todo!(); } pub fn rgb (r: u8, g: u8, b: u8) -> ItemColor {
let term = Color::Rgb(r, g, b);
ItemColor { okhsl: rgb_to_okhsl(term), term }
}
pub fn okhsl_to_rgb (color: Okhsl<f32>) -> Color { pub fn okhsl_to_rgb (color: Okhsl<f32>) -> Color {
let Srgb { red, green, blue, .. }: Srgb<f32> = Srgb::from_color_unclamped(color); let Srgb { red, green, blue, .. }: Srgb<f32> = Srgb::from_color_unclamped(color);
@ -30,10 +33,10 @@ pub trait HasColor { fn color (&self) -> ItemColor; }
} }
} }
#[derive(Copy, Clone, Debug, Default)] #[derive(Copy, Clone, Debug, Default, PartialEq)]
pub struct ItemColor { pub struct ItemColor {
term: Color, pub term: Color,
okhsl: Okhsl<f32> pub okhsl: Okhsl<f32>
} }
impl_from!(ItemColor: |term: Color| Self { term, okhsl: rgb_to_okhsl(term) }); impl_from!(ItemColor: |term: Color| Self { term, okhsl: rgb_to_okhsl(term) });
impl_from!(ItemColor: |okhsl: Okhsl<f32>| Self { okhsl, term: okhsl_to_rgb(okhsl) }); impl_from!(ItemColor: |okhsl: Okhsl<f32>| Self { okhsl, term: okhsl_to_rgb(okhsl) });
@ -63,6 +66,7 @@ impl ItemColor {
} }
} }
#[derive(Copy, Clone, Debug, Default, PartialEq)]
pub struct ItemTheme { pub struct ItemTheme {
pub base: ItemColor, pub base: ItemColor,
pub light: ItemColor, pub light: ItemColor,

View file

@ -90,11 +90,14 @@ pub const fn either <T: Screen> (condition: bool, a: impl Draw<T>, b: impl Draw<
/// ``` /// ```
pub trait Screen: Space<Self::Unit> + Send + Sync + Sized { pub trait Screen: Space<Self::Unit> + Send + Sync + Sized {
type Unit: Coord; type Unit: Coord;
/// Render drawable in area specified by `area` /// Render drawable in area.
fn place <'t, T: Draw<Self> + ?Sized> ( fn place <'t, T: Draw<Self> + ?Sized> (&mut self, content: &'t T) {
&mut self, content: &'t T, area: Option<XYWH<Self::Unit>> self.place_at(self.xywh(), content)
}
/// Render drawable in subarea specified by `area`
fn place_at <'t, T: Draw<Self> + ?Sized> (
&mut self, area: XYWH<Self::Unit>, content: &'t T
) { ) {
let area = area.unwrap_or_else(||self.xywh());
unimplemented!() unimplemented!()
} }
} }

View file

@ -71,11 +71,11 @@ impl Thread {
// FIXME: support attrs (docstrings) // FIXME: support attrs (docstrings)
$($Variant $({ $($arg: $Arg),* })?),* $($Variant $({ $($arg: $Arg),* })?),*
} }
impl ::tengri::Command<$State> for $Command { impl ::tengri::dizzle::Act<$State> for $Command {
fn execute (&self, $state: &mut $State) -> Perhaps<Self> { fn act (&self, $state: &mut $State) -> Perhaps<Self> {
match self { match self {
$(Self::$Variant $({ $($arg),* })? => $body,)* $(Self::$Variant $({ $($arg),* })? => $body,)*
_ => unimplemented!("Command<{}>: {self:?}", stringify!($State)), _ => unimplemented!("Act<{}>: {self:?}", stringify!($State)),
} }
} }
} }

View file

@ -201,12 +201,12 @@ impl Split {
let b = origin_b.align(b); let b = origin_b.align(b);
match self { match self {
Self::Below => { Self::Below => {
to.place(&b, Some(area_b)); to.place_at(area_b, &b);
to.place(&a, Some(area_b)); to.place_at(area_b, &a);
}, },
_ => { _ => {
to.place(&a, Some(area_a)); to.place_at(area_a, &a);
to.place(&b, Some(area_a)); to.place_at(area_a, &b);
} }
} }
Ok(to.xywh()) // FIXME: compute and return actually used area Ok(to.xywh()) // FIXME: compute and return actually used area

View file

@ -35,7 +35,7 @@ impl Y<u16> for Tui {
fn h (&self) -> u16 { self.1.3 } fn h (&self) -> u16 { self.1.3 }
} }
impl Tui { impl Tui {
fn update (&mut self, callback: &impl Fn(&mut Cell, u16, u16)) -> XYWH<u16> { pub fn update (&mut self, callback: &impl Fn(&mut Cell, u16, u16)) -> XYWH<u16> {
for row in 0..self.h() { for row in 0..self.h() {
let y = self.y() + row; let y = self.y() + row;
for col in 0..self.w() { for col in 0..self.w() {
@ -49,14 +49,14 @@ impl Tui {
} }
self.xywh() self.xywh()
} }
fn tint_all (&mut self, fg: Color, bg: Color, modifier: Modifier) { pub fn tint_all (&mut self, fg: Color, bg: Color, modifier: Modifier) {
for cell in self.0.content.iter_mut() { for cell in self.0.content.iter_mut() {
cell.fg = fg; cell.fg = fg;
cell.bg = bg; cell.bg = bg;
cell.modifier = modifier; cell.modifier = modifier;
} }
} }
fn blit (&mut self, text: &impl AsRef<str>, x: u16, y: u16, style: Option<Style>) { pub fn blit (&mut self, text: &impl AsRef<str>, x: u16, y: u16, style: Option<Style>) {
let text = text.as_ref(); let text = text.as_ref();
let style = style.unwrap_or(Style::default()); let style = style.unwrap_or(Style::default());
if x < self.0.area.width && y < self.0.area.height { if x < self.0.area.width && y < self.0.area.height {

View file

@ -17,6 +17,11 @@ pub(crate) use ::unicode_width::*;
self.as_str().draw(to) self.as_str().draw(to)
} }
} }
impl Draw<Tui> for &std::sync::Arc<str> {
fn draw (self, to: &mut Tui) -> Usually<XYWH<u16>> {
self.as_ref().draw(to)
}
}
impl Draw<Tui> for std::sync::Arc<str> { impl Draw<Tui> for std::sync::Arc<str> {
fn draw (self, to: &mut Tui) -> Usually<XYWH<u16>> { fn draw (self, to: &mut Tui) -> Usually<XYWH<u16>> {
self.as_ref().draw(to) self.as_ref().draw(to)