diff options
| author | pml68 <contact@pml68.dev> | 2025-04-13 00:27:57 +0200 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2025-04-15 23:51:47 +0200 |
| commit | b6c5f3e25d4590e347236f481e6a00bdf98ac030 (patch) | |
| tree | 811ea989e9da0c1eb465ca8f5ba9853dd284b7df /material_theme/src/scrollable.rs | |
| parent | feat(material_theme): implement `theme::Base` for theme (`None` for now) (diff) | |
| download | iced-builder-b6c5f3e25d4590e347236f481e6a00bdf98ac030.tar.gz | |
feat(material_theme): add disabled scrollable `Style`s
Diffstat (limited to 'material_theme/src/scrollable.rs')
| -rw-r--r-- | material_theme/src/scrollable.rs | 98 |
1 files changed, 76 insertions, 22 deletions
diff --git a/material_theme/src/scrollable.rs b/material_theme/src/scrollable.rs index c2dde67..8a22e56 100644 --- a/material_theme/src/scrollable.rs +++ b/material_theme/src/scrollable.rs @@ -1,4 +1,4 @@ -use iced_widget::core::{Border, border}; +use iced_widget::core::{Border, Color, border}; use iced_widget::scrollable::{ Catalog, Rail, Scroller, Status, Style, StyleFn, }; @@ -6,7 +6,10 @@ use iced_widget::scrollable::{ use super::Theme; use super::container::surface_container; use super::utils::mix; -use crate::utils::{HOVERED_LAYER_OPACITY, PRESSED_LAYER_OPACITY}; +use crate::utils::{ + DISABLED_CONTAINER_OPACITY, DISABLED_TEXT_OPACITY, HOVERED_LAYER_OPACITY, + PRESSED_LAYER_OPACITY, +}; impl Catalog for Theme { type Class<'a> = StyleFn<'a, Self>; @@ -23,7 +26,7 @@ impl Catalog for Theme { pub fn default(theme: &Theme, status: Status) -> Style { let colors = theme.colorscheme.surface; - let rail = Rail { + let active = Rail { background: None, scroller: Scroller { color: colors.on_surface, @@ -32,19 +35,53 @@ pub fn default(theme: &Theme, status: Status) -> Style { border: Border::default(), }; + let disabled = Rail { + background: Some( + Color { + a: DISABLED_CONTAINER_OPACITY, + ..colors.on_surface + } + .into(), + ), + scroller: Scroller { + color: Color { + a: DISABLED_TEXT_OPACITY, + ..colors.on_surface + }, + border: border::rounded(400), + }, + ..active + }; + let style = Style { container: surface_container(theme), - vertical_rail: rail, - horizontal_rail: rail, + vertical_rail: active, + horizontal_rail: active, gap: None, }; match status { - Status::Active { .. } => style, + Status::Active { + is_horizontal_scrollbar_disabled, + is_vertical_scrollbar_disabled, + } => Style { + horizontal_rail: if is_horizontal_scrollbar_disabled { + disabled + } else { + active + }, + vertical_rail: if is_vertical_scrollbar_disabled { + disabled + } else { + active + }, + ..style + }, Status::Hovered { is_horizontal_scrollbar_hovered, is_vertical_scrollbar_hovered, - .. + is_horizontal_scrollbar_disabled, + is_vertical_scrollbar_disabled, } => { let hovered_rail = Rail { scroller: Scroller { @@ -55,19 +92,27 @@ pub fn default(theme: &Theme, status: Status) -> Style { ), border: border::rounded(400), }, - ..rail + ..active }; Style { - horizontal_rail: if is_horizontal_scrollbar_hovered { - hovered_rail + horizontal_rail: if is_horizontal_scrollbar_disabled { + disabled } else { - rail + if is_horizontal_scrollbar_hovered { + hovered_rail + } else { + active + } }, - vertical_rail: if is_vertical_scrollbar_hovered { - hovered_rail + vertical_rail: if is_vertical_scrollbar_disabled { + disabled } else { - rail + if is_vertical_scrollbar_hovered { + hovered_rail + } else { + active + } }, ..style } @@ -75,7 +120,8 @@ pub fn default(theme: &Theme, status: Status) -> Style { Status::Dragged { is_horizontal_scrollbar_dragged, is_vertical_scrollbar_dragged, - .. + is_horizontal_scrollbar_disabled, + is_vertical_scrollbar_disabled, } => { let dragged_rail = Rail { scroller: Scroller { @@ -86,19 +132,27 @@ pub fn default(theme: &Theme, status: Status) -> Style { ), border: border::rounded(400), }, - ..rail + ..active }; Style { - horizontal_rail: if is_horizontal_scrollbar_dragged { - dragged_rail + horizontal_rail: if is_horizontal_scrollbar_disabled { + disabled } else { - rail + if is_horizontal_scrollbar_dragged { + dragged_rail + } else { + active + } }, - vertical_rail: if is_vertical_scrollbar_dragged { - dragged_rail + vertical_rail: if is_vertical_scrollbar_disabled { + disabled } else { - rail + if is_vertical_scrollbar_dragged { + dragged_rail + } else { + active + } }, ..style } |
