From bea88ac58d404f9af65286663bbbf18205bde14b Mon Sep 17 00:00:00 2001 From: same mf who else Date: Wed, 25 Mar 2026 22:39:39 +0200 Subject: [PATCH] fix(draw): mismatches --- src/color.rs | 12 ++++++++---- src/draw.rs | 11 +++++++---- src/space.rs | 8 ++++---- src/term.rs | 6 +++--- src/text.rs | 5 +++++ 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/color.rs b/src/color.rs index 50f1eed..13caf71 100644 --- a/src/color.rs +++ b/src/color.rs @@ -6,7 +6,10 @@ pub(crate) use ::palette::{ }; 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) -> Color { let Srgb { red, green, blue, .. }: Srgb = 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 { - term: Color, - okhsl: Okhsl + pub term: Color, + pub okhsl: Okhsl } impl_from!(ItemColor: |term: Color| Self { term, okhsl: rgb_to_okhsl(term) }); impl_from!(ItemColor: |okhsl: Okhsl| Self { okhsl, term: okhsl_to_rgb(okhsl) }); @@ -63,6 +66,7 @@ impl ItemColor { } } +#[derive(Copy, Clone, Debug, Default, PartialEq)] pub struct ItemTheme { pub base: ItemColor, pub light: ItemColor, diff --git a/src/draw.rs b/src/draw.rs index dd252db..b33a155 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -90,11 +90,14 @@ pub const fn either (condition: bool, a: impl Draw, b: impl Draw< /// ``` pub trait Screen: Space + Send + Sync + Sized { type Unit: Coord; - /// Render drawable in area specified by `area` - fn place <'t, T: Draw + ?Sized> ( - &mut self, content: &'t T, area: Option> + /// Render drawable in area. + fn place <'t, T: Draw + ?Sized> (&mut self, content: &'t T) { + self.place_at(self.xywh(), content) + } + /// Render drawable in subarea specified by `area` + fn place_at <'t, T: Draw + ?Sized> ( + &mut self, area: XYWH, content: &'t T ) { - let area = area.unwrap_or_else(||self.xywh()); unimplemented!() } } diff --git a/src/space.rs b/src/space.rs index b7c7e96..78b90fa 100644 --- a/src/space.rs +++ b/src/space.rs @@ -201,12 +201,12 @@ impl Split { let b = origin_b.align(b); match self { Self::Below => { - to.place(&b, Some(area_b)); - to.place(&a, Some(area_b)); + to.place_at(area_b, &b); + to.place_at(area_b, &a); }, _ => { - to.place(&a, Some(area_a)); - to.place(&b, Some(area_a)); + to.place_at(area_a, &a); + to.place_at(area_a, &b); } } Ok(to.xywh()) // FIXME: compute and return actually used area diff --git a/src/term.rs b/src/term.rs index b06c0b3..b59edbd 100644 --- a/src/term.rs +++ b/src/term.rs @@ -35,7 +35,7 @@ impl Y for Tui { fn h (&self) -> u16 { self.1.3 } } impl Tui { - fn update (&mut self, callback: &impl Fn(&mut Cell, u16, u16)) -> XYWH { + pub fn update (&mut self, callback: &impl Fn(&mut Cell, u16, u16)) -> XYWH { for row in 0..self.h() { let y = self.y() + row; for col in 0..self.w() { @@ -49,14 +49,14 @@ impl Tui { } 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() { cell.fg = fg; cell.bg = bg; cell.modifier = modifier; } } - fn blit (&mut self, text: &impl AsRef, x: u16, y: u16, style: Option