This commit is contained in:
JMARyA 2025-01-15 18:28:59 +01:00
parent 8208fa8899
commit ed739d792f
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
35 changed files with 1675 additions and 447 deletions

57
src/ui/wrapper/hover.rs Normal file
View file

@ -0,0 +1,57 @@
use maud::{Markup, Render, html};
use crate::ui::UIWidget;
#[allow(non_snake_case)]
pub fn Hover<T: UIWidget + 'static, I: UIWidget + 'static>(inherit: I, inner: T) -> HoverWrapper {
HoverWrapper(Box::new(inner), Box::new(inherit))
}
pub struct HoverWrapper(Box<dyn UIWidget>, Box<dyn UIWidget>);
impl HoverWrapper {
pub fn hovered_class(&self) -> String {
self.1
.extended_class()
.into_iter()
.filter(|x| !x.is_empty())
.map(|x| format!("hover:{x}"))
.collect::<Vec<_>>()
.join(" ")
}
}
impl Render for HoverWrapper {
fn render(&self) -> Markup {
self.render_with_class("")
}
}
impl UIWidget for HoverWrapper {
fn can_inherit(&self) -> bool {
true
}
fn base_class(&self) -> Vec<String> {
vec![]
}
fn extended_class(&self) -> Vec<String> {
self.base_class()
}
fn render_with_class(&self, class: &str) -> Markup {
// TODO : Replace lol
if self.0.as_ref().can_inherit() {
self.0
.as_ref()
.render_with_class(&format!("{} {class}", self.hovered_class()))
} else {
html! {
div class=(format!("{} {class}", self.hovered_class())) {
(self.0.as_ref())
}
}
}
}
}