notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 16e2c9d5b0a49096ab109246360466b266466171
parent d2158a64823490b79ac52eb69c5ccab85a5f55d9
Author: kernelkind <kernelkind@gmail.com>
Date:   Mon, 12 May 2025 12:27:22 -0400

make styled button toggleable

Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
Mcrates/notedeck_columns/src/ui/widgets.rs | 31+++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/crates/notedeck_columns/src/ui/widgets.rs b/crates/notedeck_columns/src/ui/widgets.rs @@ -3,6 +3,14 @@ use notedeck::NotedeckTextStyle; /// Sized and styled to match the figma design pub fn styled_button(text: &str, fill_color: egui::Color32) -> impl Widget + '_ { + styled_button_toggleable(text, fill_color, true) +} + +pub fn styled_button_toggleable( + text: &str, + fill_color: egui::Color32, + enabled: bool, +) -> impl Widget + '_ { move |ui: &mut egui::Ui| -> egui::Response { let painter = ui.painter(); let text_color = if ui.visuals().dark_mode { @@ -18,9 +26,24 @@ pub fn styled_button(text: &str, fill_color: egui::Color32) -> impl Widget + '_ ui.available_width(), ); - ui.add_sized( - galley.rect.expand2(egui::vec2(16.0, 8.0)).size(), - Button::new(galley).corner_radius(8.0).fill(fill_color), - ) + let size = galley.rect.expand2(egui::vec2(16.0, 8.0)).size(); + let mut button = Button::new(galley).corner_radius(8.0); + + if !enabled { + button = button + .sense(egui::Sense::focusable_noninteractive()) + .fill(ui.visuals().noninteractive().bg_fill) + .stroke(ui.visuals().noninteractive().bg_stroke); + } else { + button = button.fill(fill_color); + } + + let mut resp = ui.add_sized(size, button); + + if !enabled { + resp = resp.on_hover_cursor(egui::CursorIcon::NotAllowed); + } + + resp } }