diff options
author | 2024-02-12 19:24:09 +0100 | |
---|---|---|
committer | 2024-02-12 19:24:09 +0100 | |
commit | 0eaaeaa517a00765045de155bb1de01c2d8f553f (patch) | |
tree | bf6d2d909bb9d2b1c9aae623775573d6e7df8c8c /widget/src/scrollable.rs | |
parent | 0f920e0435932c0b6927c771424b2ba495ddb46e (diff) | |
download | iced-0eaaeaa517a00765045de155bb1de01c2d8f553f.tar.gz iced-0eaaeaa517a00765045de155bb1de01c2d8f553f.tar.bz2 iced-0eaaeaa517a00765045de155bb1de01c2d8f553f.zip |
Simplify `scrollable` styling API
Diffstat (limited to 'widget/src/scrollable.rs')
-rw-r--r-- | widget/src/scrollable.rs | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 5c986757..3814c590 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -1,4 +1,5 @@ //! Navigate an endless amount of content with a scrollbar. +use crate::container; use crate::core::event::{self, Event}; use crate::core::keyboard; use crate::core::layout; @@ -880,18 +881,23 @@ pub fn draw<Theme, Renderer>( _ => mouse::Cursor::Unavailable, }; - // Draw background. - let appearence = theme.appearance(style); + let appearance = if state.y_scroller_grabbed_at.is_some() + || state.x_scroller_grabbed_at.is_some() + { + theme.dragging(style) + } else if cursor_over_scrollable.is_some() { + theme.hovered(style, mouse_over_y_scrollbar || mouse_over_x_scrollbar) + } else { + theme.active(style) + }; - if let Some(background) = appearence.background { - renderer.fill_quad( - renderer::Quad { - bounds, - ..Default::default() - }, - background, - ); - } + let idle_scrollbar = theme.active(style).scrollbar; + + container::draw_background( + renderer, + &appearance.container, + layout.bounds(), + ); // Draw inner content if scrollbars.active() { @@ -917,7 +923,6 @@ pub fn draw<Theme, Renderer>( |renderer: &mut Renderer, style: Scrollbar, scrollbar: &internals::Scrollbar| { - //track if scrollbar.bounds.width > 0.0 && scrollbar.bounds.height > 0.0 && (style.background.is_some() @@ -936,7 +941,6 @@ pub fn draw<Theme, Renderer>( ); } - //thumb if scrollbar.scroller.bounds.width > 0.0 && scrollbar.scroller.bounds.height > 0.0 && (style.scroller.color != Color::TRANSPARENT @@ -961,35 +965,37 @@ pub fn draw<Theme, Renderer>( ..bounds }, |renderer| { - //draw y scrollbar if let Some(scrollbar) = scrollbars.y { - let style = if state.y_scroller_grabbed_at.is_some() { - theme.dragging(style) - } else if cursor_over_scrollable.is_some() { - theme.hovered(style, mouse_over_y_scrollbar) - } else { - theme.active(style) - }; - - draw_scrollbar(renderer, style, &scrollbar); + draw_scrollbar( + renderer, + if mouse_over_y_scrollbar + || state.y_scroller_grabbed_at.is_some() + { + appearance.scrollbar + } else { + idle_scrollbar + }, + &scrollbar, + ); } - //draw x scrollbar if let Some(scrollbar) = scrollbars.x { - let style = if state.x_scroller_grabbed_at.is_some() { - theme.dragging_horizontal(style) - } else if cursor_over_scrollable.is_some() { - theme.hovered_horizontal(style, mouse_over_x_scrollbar) - } else { - theme.active_horizontal(style) - }; - - draw_scrollbar(renderer, style, &scrollbar); + draw_scrollbar( + renderer, + if mouse_over_x_scrollbar + || state.x_scroller_grabbed_at.is_some() + { + appearance.scrollbar + } else { + idle_scrollbar + }, + &scrollbar, + ); } - //draw filler quad if let (Some(x), Some(y)) = (scrollbars.x, scrollbars.y) { - let background = appearence.gap.or(appearence.background); + let background = + appearance.gap.or(appearance.container.background); if let Some(background) = background { renderer.fill_quad( |