summaryrefslogtreecommitdiff
path: root/src/renderer/text.rs
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2025-06-21 13:32:55 +0800
committerJSDurand <mmemmew@gmail.com>2025-06-21 13:32:55 +0800
commit9b36d712e25fb1d209df848281b9913b61a6ec45 (patch)
treee7a126af70f71a02b2e63292b07b8458effb7da5 /src/renderer/text.rs
init commit
A basic window is available. Now we shall try to render texts and some auxiliary functionalities.
Diffstat (limited to 'src/renderer/text.rs')
-rw-r--r--src/renderer/text.rs72
1 files changed, 72 insertions, 0 deletions
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),
+ }
+ }
+}