added heading #19

This commit is contained in:
2025-08-02 12:58:45 -05:00
parent d9d107bd80
commit 2d8755b13c
4 changed files with 60 additions and 1 deletions
+1
View File
@@ -25,6 +25,7 @@ cc = "1.0"
[dependencies] [dependencies]
crossterm = "0.28.1" crossterm = "0.28.1"
figlet-rs = "0.1.5"
[profile.dev] [profile.dev]
opt-level = 1 opt-level = 1
+2 -1
View File
@@ -20,7 +20,8 @@ pub fn app(screen: Arc<Screen>) -> Rsx {
screen.close(); screen.close();
}}); }});
FlexRow, gap: 1, { FlexRow, gap: 1, {
FlexCol { FlexCol, gap: 3, {
Heading, smooth: false, { "OSUI" }
@Transform::new().padding(2, 2); @Transform::new().padding(2, 2);
@Style { foreground: None, background: Background::RoundedOutline(0x00ff00) }; @Style { foreground: None, background: Background::RoundedOutline(0x00ff00) };
Div { Div {
+55
View File
@@ -0,0 +1,55 @@
use std::sync::{Arc, Mutex};
use figlet_rs::FIGfont;
use crate::{
widget::{Element, Widget},
NoRender,
};
pub struct Heading {
pub font: FIGfont,
pub smooth: bool,
children: Mutex<Vec<Arc<Widget>>>,
}
impl Heading {
pub fn new() -> Heading {
Heading {
font: FIGfont::standard().unwrap(),
smooth: false,
children: Mutex::new(Vec::new()),
}
}
}
impl Element for Heading {
fn render(&mut self, scope: &mut crate::prelude::RenderScope) {
let mut s = String::new();
for element in self.children.lock().unwrap().iter() {
if let Some(e) = element.get_elem().as_any().downcast_ref::<String>() {
s += e;
}
}
if let Some(t) = self.font.convert(&s) {
scope.draw_text(&if self.smooth {
format!("{t}").replace("-", "─").replace("|", "│")
} else {
format!("{t}")
});
}
}
fn draw_child(&self, element: &Arc<Widget>) {
element.inject(|w| w.component(NoRender));
self.children.lock().unwrap().push(element.clone());
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}
}
+2
View File
@@ -1,8 +1,10 @@
pub mod div; pub mod div;
pub mod flex; pub mod flex;
pub mod heading;
pub use div::*; pub use div::*;
pub use flex::*; pub use flex::*;
pub use heading::*;
use crate::Element; use crate::Element;