From 9247cddf983deeb625dc72e45d08f122835b77df Mon Sep 17 00:00:00 2001 From: Leo Date: Sun, 20 Oct 2024 22:00:09 +0200 Subject: [PATCH] styles --- src/components.rs | 6 ++++-- src/style.rs | 14 +++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/components.rs b/src/components.rs index be85507..d06a00e 100644 --- a/src/components.rs +++ b/src/components.rs @@ -106,6 +106,8 @@ pub fn text() -> Component { pub fn button() -> Component { let mut component = Component::new(); + component.style.hover_fg = crate::style::Color::Blue; + fn update(this: &mut Component, k: key::Key) -> UpdateResponse { if k.kind == KeyKind::Enter { if this.toggle { @@ -128,8 +130,8 @@ pub fn button() -> Component { } } - fn render(s: &mut Component) -> String { - s.expr.clone() + fn render(this: &mut Component) -> String { + this.style.clone().write(&this.expr) } component.update = update; diff --git a/src/style.rs b/src/style.rs index 63412b2..e5103f9 100644 --- a/src/style.rs +++ b/src/style.rs @@ -43,7 +43,19 @@ impl Style { } pub fn get_outline(self) -> String { - String::from(self.fg.ansi() + &self.bg.ansi_bg() + &self.font.ansi()) + if self.is_active { + self.outline.prioritize(self.hover_outline).ansi() + } else { + self.outline.ansi() + } + } + + pub fn write(self, s: &str) -> String { + format!("{}{}", self.get(), s) + } + + pub fn write_outline(self, s: &str) -> String { + format!("{}{}", self.get_outline(), s) } }