Implement styling for Scrollable
This commit is contained in:
parent
f7dfd65374
commit
d0dc7cebf9
9 changed files with 193 additions and 39 deletions
|
|
@ -7,6 +7,8 @@ const SCROLLBAR_WIDTH: u16 = 10;
|
|||
const SCROLLBAR_MARGIN: u16 = 2;
|
||||
|
||||
impl scrollable::Renderer for Renderer {
|
||||
type Style = Box<dyn iced_style::scrollable::StyleSheet>;
|
||||
|
||||
fn scrollbar(
|
||||
&self,
|
||||
bounds: Rectangle,
|
||||
|
|
@ -53,6 +55,7 @@ impl scrollable::Renderer for Renderer {
|
|||
is_mouse_over_scrollbar: bool,
|
||||
scrollbar: Option<scrollable::Scrollbar>,
|
||||
offset: u32,
|
||||
style_sheet: &Self::Style,
|
||||
(content, mouse_cursor): Self::Output,
|
||||
) -> Self::Output {
|
||||
let clip = Primitive::Clip {
|
||||
|
|
@ -64,17 +67,23 @@ impl scrollable::Renderer for Renderer {
|
|||
(
|
||||
if let Some(scrollbar) = scrollbar {
|
||||
if is_mouse_over || state.is_scroller_grabbed() {
|
||||
let scroller = Primitive::Quad {
|
||||
bounds: scrollbar.scroller.bounds,
|
||||
background: Background::Color(
|
||||
[0.0, 0.0, 0.0, 0.7].into(),
|
||||
),
|
||||
border_radius: 5,
|
||||
border_width: 0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
let style = if state.is_scroller_grabbed() {
|
||||
style_sheet.dragging()
|
||||
} else if is_mouse_over_scrollbar {
|
||||
style_sheet.hovered()
|
||||
} else {
|
||||
style_sheet.active()
|
||||
};
|
||||
|
||||
if is_mouse_over_scrollbar || state.is_scroller_grabbed() {
|
||||
let scroller = Primitive::Quad {
|
||||
bounds: scrollbar.scroller.bounds,
|
||||
background: Background::Color(style.scroller.color),
|
||||
border_radius: style.scroller.border_radius,
|
||||
border_width: style.scroller.border_width,
|
||||
border_color: style.scroller.border_color,
|
||||
};
|
||||
|
||||
if style.background.is_some() || style.border_width > 0 {
|
||||
let scrollbar = Primitive::Quad {
|
||||
bounds: Rectangle {
|
||||
x: scrollbar.bounds.x
|
||||
|
|
@ -83,12 +92,12 @@ impl scrollable::Renderer for Renderer {
|
|||
- f32::from(2 * SCROLLBAR_MARGIN),
|
||||
..scrollbar.bounds
|
||||
},
|
||||
background: Background::Color(
|
||||
[0.0, 0.0, 0.0, 0.3].into(),
|
||||
background: style.background.unwrap_or(
|
||||
Background::Color(Color::TRANSPARENT),
|
||||
),
|
||||
border_radius: 5,
|
||||
border_width: 0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
border_radius: style.border_radius,
|
||||
border_width: style.border_width,
|
||||
border_color: style.border_color,
|
||||
};
|
||||
|
||||
Primitive::Group {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue