mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-04-03 21:40:44 +02:00
This commit is contained in:
parent
30d378a6ee
commit
bea88ac58d
5 changed files with 27 additions and 15 deletions
12
src/color.rs
12
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<f32>) -> 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 {
|
||||
term: Color,
|
||||
okhsl: Okhsl<f32>
|
||||
pub term: Color,
|
||||
pub okhsl: Okhsl<f32>
|
||||
}
|
||||
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) });
|
||||
|
|
@ -63,6 +66,7 @@ impl ItemColor {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
pub struct ItemTheme {
|
||||
pub base: ItemColor,
|
||||
pub light: ItemColor,
|
||||
|
|
|
|||
11
src/draw.rs
11
src/draw.rs
|
|
@ -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 {
|
||||
type Unit: Coord;
|
||||
/// Render drawable in area specified by `area`
|
||||
fn place <'t, T: Draw<Self> + ?Sized> (
|
||||
&mut self, content: &'t T, area: Option<XYWH<Self::Unit>>
|
||||
/// Render drawable in area.
|
||||
fn place <'t, T: Draw<Self> + ?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<Self> + ?Sized> (
|
||||
&mut self, area: XYWH<Self::Unit>, content: &'t T
|
||||
) {
|
||||
let area = area.unwrap_or_else(||self.xywh());
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ impl Y<u16> for Tui {
|
|||
fn h (&self) -> u16 { self.1.3 }
|
||||
}
|
||||
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() {
|
||||
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<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 style = style.unwrap_or(Style::default());
|
||||
if x < self.0.area.width && y < self.0.area.height {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,11 @@ pub(crate) use ::unicode_width::*;
|
|||
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> {
|
||||
fn draw (self, to: &mut Tui) -> Usually<XYWH<u16>> {
|
||||
self.as_ref().draw(to)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue