keys 2
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
use color::Rgba8;
|
||||
use kiln_core::cp437::tile_to_char;
|
||||
use kiln_core::glyph::Glyph;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::prelude::Color;
|
||||
use ratatui::style::Style;
|
||||
use ratatui::text::Span;
|
||||
|
||||
/// Converts a core [`Rgba8`] color into a ratatui truecolor [`Color`].
|
||||
///
|
||||
@@ -10,6 +14,17 @@ pub fn rgba8_to_color(c: Rgba8) -> Color {
|
||||
Color::Rgb(c.r, c.g, c.b)
|
||||
}
|
||||
|
||||
/// Converts a [`Glyph`] to a single-character styled [`Span`].
|
||||
///
|
||||
/// The tile index is mapped to a CP437 character; fg and bg are both applied.
|
||||
pub fn glyph_to_span(glyph: Glyph) -> Span<'static> {
|
||||
let ch = tile_to_char(glyph.tile).to_string();
|
||||
let style = Style::default()
|
||||
.fg(rgba8_to_color(glyph.fg))
|
||||
.bg(rgba8_to_color(glyph.bg));
|
||||
Span::styled(ch, style)
|
||||
}
|
||||
|
||||
/// Returns true if two `Rect`s share at least one cell.
|
||||
pub fn rects_overlap(a: Rect, b: Rect) -> bool {
|
||||
a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height
|
||||
|
||||
Reference in New Issue
Block a user