static text

This commit is contained in:
2024-12-17 11:40:46 +01:00
parent e1ad3a58b0
commit 8182e70ca4
3 changed files with 22 additions and 14 deletions
+3 -3
View File
@@ -1,10 +1,10 @@
use crate::prelude::*;
pub fn todo_app() -> Element {
let todo = vec!["Foo", "Bar"];
let todo = vec!["Todo", "Hovering", "Completed", "Foo", "Bar"];
rsx! {
text { class: "title", "Todo list app made with OSUI" }
text { class: "title", static "Todo list app made with OSUI" }
text { class: "title", "{}", "-".repeat(crossterm::terminal::size().unwrap().0 as usize) }
for (t in todo) {
ersx!( button{ class: "todo", on_click: fn(btn: &mut Button, _, _) {
@@ -26,7 +26,7 @@ pub fn todo_styling() -> Css {
color: Red,
}
"todo": "hover" {
color: Blue
color: Blue,
}
"complete" {
x: 0 px,
+11 -11
View File
@@ -104,17 +104,6 @@ pub enum Children {
Children(Vec<Element>, usize),
}
impl std::fmt::Debug for Children {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&match self {
Self::None => String::new(),
Self::Children(a, b) => format!("({b}, {a:?})"),
Self::Text(a) => format!("{:?}", a()),
Self::StaticText(a) => format!("{a:?}"),
})
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
/// Implementations
//////////////////////////////////////////////////////////////////////////////////////////////////
@@ -209,6 +198,17 @@ impl Default for Children {
}
}
impl std::fmt::Debug for Children {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&match self {
Self::None => String::new(),
Self::Children(a, b) => format!("({b}, {a:?})"),
Self::Text(a) => format!("{:?}", a()),
Self::StaticText(a) => format!("static({a:?})"),
})
}
}
impl Children {
pub fn is_none(&self) -> bool {
match self {
+8
View File
@@ -12,6 +12,14 @@ macro_rules! check_expr {
}
#[macro_export]
macro_rules! parse_rsx_param {
($elem:expr, static $text:expr) => {
$elem.children.set_static_force(format!($text))
};
($elem:expr, static $text:expr, $($inner:tt)*) => {
$elem.children.set_static_force(format!($text, $($inner)*))
};
($elem:expr, for ($($for:tt)*) $code:block $($rest:tt)*) => {
if $elem.children.is_none() {$elem.children = $crate::Children::Children(Vec::new(), 0)}
if let $crate::Children::Children(children, _) = &mut $elem.children {