From 9b36d712e25fb1d209df848281b9913b61a6ec45 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sat, 21 Jun 2025 13:32:55 +0800 Subject: init commit A basic window is available. Now we shall try to render texts and some auxiliary functionalities. --- src/renderer/text.rs | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/renderer/text.rs (limited to 'src/renderer/text.rs') diff --git a/src/renderer/text.rs b/src/renderer/text.rs new file mode 100644 index 0000000..ec913b8 --- /dev/null +++ b/src/renderer/text.rs @@ -0,0 +1,72 @@ +#![allow(unused)] +/// This file handles text-related settings. + +#[derive(Debug, Clone, Copy)] +pub struct Color { + r: u8, + g: u8, + b: u8, + a: u8, +} + +impl Color { + pub fn new(r: u8, g: u8, b: u8, a: u8) -> Self { + Self { r, g, b, a } + } + pub fn new_noa(r: u8, g: u8, b: u8) -> Self { + Self { r, g, b, a: 1u8 } + } +} + +#[derive(Debug, Clone, Copy)] +pub struct TextStyle { + bold: bool, + italic: bool, + font_size: u16, +} + +impl TextStyle { + pub fn default() -> Self { + Self { + bold: false, + italic: false, + font_size: 20, + } + } + + pub fn default_bold() -> Self { + Self { + bold: true, + ..Self::default() + } + } + pub fn default_italic() -> Self { + Self { + italic: true, + ..Self::default() + } + } +} + +#[derive(Debug, Clone)] +pub struct TextSpan<'a> { + pub text: &'a str, + x: i32, + y: i32, + fg: Color, + bg: Color, + pub style: TextStyle, +} + +impl<'a> TextSpan<'a> { + pub fn new(text: &'a str, style: TextStyle) -> Self { + Self { + text, + style, + x: 0, + y: 0, + fg: Color::new_noa(255, 0, 0), + bg: Color::new_noa(0, 0, 0), + } + } +} -- cgit v1.2.3-18-g5258