diff options
| author | Joe Carstairs <me@joeac.net> | 2026-02-07 11:52:08 +0000 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-02-07 12:02:27 +0000 |
| commit | 1664e741ad35ce52a01788c34029f0b2ea477e32 (patch) | |
| tree | dd6bd7c83a7e834c75815a786d67b5188cdd1f48 /schist_desktop_gui/src/gui/components/button.rs | |
| parent | 179878d12ba10ac242da2044f4c6dfe4d4829e59 (diff) | |
task-001: can navigate file screen options with keyboard
Diffstat (limited to 'schist_desktop_gui/src/gui/components/button.rs')
| -rw-r--r-- | schist_desktop_gui/src/gui/components/button.rs | 59 |
1 files changed, 44 insertions, 15 deletions
diff --git a/schist_desktop_gui/src/gui/components/button.rs b/schist_desktop_gui/src/gui/components/button.rs index 6882273..8a33e39 100644 --- a/schist_desktop_gui/src/gui/components/button.rs +++ b/schist_desktop_gui/src/gui/components/button.rs @@ -1,29 +1,58 @@ -use iced::{widget::Button, Element}; +use iced::{widget::Button, Element, Theme}; use crate::style::*; -pub fn active_button<'a, Content, Message>(content: &'a Content) -> Button<'a, Message> +pub fn button<'a, Content, Message>( + content: &'a Content, + message: Message, + focus: bool, +) -> Button<'a, Message> where Element<'a, Message>: From<&'a Content>, { iced::widget::button(content) - .style(|theme: &iced::Theme, _status| iced::widget::button::Style { - background: Some(iced::Background::Color( - theme.extended_palette().primary.base.text, - )), - text_color: theme.extended_palette().primary.base.color, - ..Default::default() + .on_press(message) + .style(move |theme, status| match (status, focus) { + (iced::widget::button::Status::Hovered, _) => hovered_button_style(theme), + (iced::widget::button::Status::Pressed, _) | (_, true) => focused_button_style(theme), + (iced::widget::button::Status::Active, false) => base_button_style(theme), + (iced::widget::button::Status::Disabled, false) => todo!(), }) .width(iced::Length::Fill) } -pub fn inactive_button<'a, Content: Into<Element<'a, Message>>, Message>( - content: Content, - on_press: Message, -) -> Button<'a, Message> { - iced::widget::button(content) - .on_press(on_press) - .width(iced::Length::Fill) +fn hovered_button_style(theme: &Theme) -> iced::widget::button::Style { + iced::widget::button::Style { + background: Some(iced::Background::Color( + theme.extended_palette().background.weak.color, + )), + text_color: theme.extended_palette().primary.base.text, + ..base_button_style(theme) + } +} + +fn focused_button_style(theme: &Theme) -> iced::widget::button::Style { + iced::widget::button::Style { + background: Some(iced::Background::Color( + theme.extended_palette().primary.base.text, + )), + text_color: theme.extended_palette().primary.base.color, + ..base_button_style(theme) + } +} + +fn base_button_style(theme: &Theme) -> iced::widget::button::Style { + iced::widget::button::Style { + background: Some(iced::Background::Color( + theme.extended_palette().primary.base.color, + )), + border: iced::Border { + color: theme.extended_palette().primary.base.text, + ..Default::default() + }, + text_color: theme.extended_palette().primary.base.text, + ..Default::default() + } } pub fn panel_button<'a, Content: Into<Element<'a, Message>>, Message>( |
