From aa6a6e19d205f4e2d770c67fe0f114ceb477eba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Pakalns?= Date: Fri, 10 Jan 2025 01:04:33 +0200 Subject: [PATCH] Colored button using color tint --- src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7542d0b..dc1de48 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1415,7 +1415,7 @@ pub trait TuiBuilderLogic<'r>: AsTuiBuilder<'r> + Sized { #[must_use = "You should check if the user clicked this with `if ….clicked() { … } "] fn filled_button( self, - fill: Option, + target_tint_color: Option, f: impl FnOnce(&mut Tui) -> T, ) -> TuiInnerResponse { let tui = self.with_border_style_from_egui_style(); @@ -1429,12 +1429,12 @@ pub trait TuiBuilderLogic<'r>: AsTuiBuilder<'r> + Sized { let painter = ui.painter(); let stroke = visuals.bg_stroke; - painter.rect( - rect.shrink(stroke.width), - visuals.rounding, - fill.unwrap_or(visuals.weak_bg_fill), - stroke, - ); + + let mut bg_fill = visuals.weak_bg_fill; + if let Some(fill) = target_tint_color { + bg_fill = egui::ecolor::tint_color_towards(bg_fill, fill); + } + painter.rect(rect.shrink(stroke.width), visuals.rounding, bg_fill, stroke); response },