Migrate scrollbar disabled style status to iced 0.13.
Feel free to change the 'name' of it. I originally used 'disabled' to signal that it's not usable, but still visible. 'Overflowing' may be a better term.
This commit is contained in:
parent
f2c9b6b2ff
commit
8d9fe61d76
1 changed files with 65 additions and 14 deletions
|
|
@ -906,14 +906,21 @@ where
|
||||||
is_vertical_scrollbar_dragged: state
|
is_vertical_scrollbar_dragged: state
|
||||||
.y_scroller_grabbed_at
|
.y_scroller_grabbed_at
|
||||||
.is_some(),
|
.is_some(),
|
||||||
|
is_horizontal_scrollbar_disabled: scrollbars.x_disabled(),
|
||||||
|
is_vertical_scrollbar_disabled: scrollbars.y_disabled(),
|
||||||
}
|
}
|
||||||
} else if cursor_over_scrollable.is_some() {
|
} else if cursor_over_scrollable.is_some() {
|
||||||
Status::Hovered {
|
Status::Hovered {
|
||||||
is_horizontal_scrollbar_hovered: mouse_over_x_scrollbar,
|
is_horizontal_scrollbar_hovered: mouse_over_x_scrollbar,
|
||||||
is_vertical_scrollbar_hovered: mouse_over_y_scrollbar,
|
is_vertical_scrollbar_hovered: mouse_over_y_scrollbar,
|
||||||
|
is_horizontal_scrollbar_disabled: scrollbars.x_disabled(),
|
||||||
|
is_vertical_scrollbar_disabled: scrollbars.y_disabled(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Status::Active
|
Status::Active {
|
||||||
|
is_horizontal_scrollbar_disabled: scrollbars.x_disabled(),
|
||||||
|
is_vertical_scrollbar_disabled: scrollbars.y_disabled(),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Event::Window(window::Event::RedrawRequested(_now)) = event {
|
if let Event::Window(window::Event::RedrawRequested(_now)) = event {
|
||||||
|
|
@ -968,8 +975,13 @@ where
|
||||||
_ => mouse::Cursor::Unavailable,
|
_ => mouse::Cursor::Unavailable,
|
||||||
};
|
};
|
||||||
|
|
||||||
let style = theme
|
let style = theme.style(
|
||||||
.style(&self.class, self.last_status.unwrap_or(Status::Active));
|
&self.class,
|
||||||
|
self.last_status.unwrap_or(Status::Active {
|
||||||
|
is_horizontal_scrollbar_disabled: false,
|
||||||
|
is_vertical_scrollbar_disabled: false,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
container::draw_background(renderer, &style.container, layout.bounds());
|
container::draw_background(renderer, &style.container, layout.bounds());
|
||||||
|
|
||||||
|
|
@ -1588,15 +1600,27 @@ impl Scrollbars {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let translation = state.translation(direction, bounds, content_bounds);
|
let translation = state.translation(direction, bounds, content_bounds);
|
||||||
|
|
||||||
let show_scrollbar_x = direction.horizontal().filter(|scrollbar| {
|
let show_scrollbar_x = direction
|
||||||
scrollbar.spacing.is_some() || content_bounds.width > bounds.width
|
.horizontal()
|
||||||
});
|
.filter(|scrollbar| {
|
||||||
|
scrollbar.spacing.is_some()
|
||||||
|
|| content_bounds.width > bounds.width
|
||||||
|
})
|
||||||
|
.map(|properties| {
|
||||||
|
(properties, content_bounds.width <= bounds.width)
|
||||||
|
});
|
||||||
|
|
||||||
let show_scrollbar_y = direction.vertical().filter(|scrollbar| {
|
let show_scrollbar_y = direction
|
||||||
scrollbar.spacing.is_some() || content_bounds.height > bounds.height
|
.vertical()
|
||||||
});
|
.filter(|scrollbar| {
|
||||||
|
scrollbar.spacing.is_some()
|
||||||
|
|| content_bounds.height > bounds.height
|
||||||
|
})
|
||||||
|
.map(|properties| {
|
||||||
|
(properties, content_bounds.height <= bounds.height)
|
||||||
|
});
|
||||||
|
|
||||||
let y_scrollbar = if let Some(vertical) = show_scrollbar_y {
|
let y_scrollbar = if let Some((vertical, disabled)) = show_scrollbar_y {
|
||||||
let Scrollbar {
|
let Scrollbar {
|
||||||
width,
|
width,
|
||||||
margin,
|
margin,
|
||||||
|
|
@ -1607,7 +1631,7 @@ impl Scrollbars {
|
||||||
// Adjust the height of the vertical scrollbar if the horizontal scrollbar
|
// Adjust the height of the vertical scrollbar if the horizontal scrollbar
|
||||||
// is present
|
// is present
|
||||||
let x_scrollbar_height = show_scrollbar_x
|
let x_scrollbar_height = show_scrollbar_x
|
||||||
.map_or(0.0, |h| h.width.max(h.scroller_width) + h.margin);
|
.map_or(0.0, |(h, _)| h.width.max(h.scroller_width) + h.margin);
|
||||||
|
|
||||||
let total_scrollbar_width =
|
let total_scrollbar_width =
|
||||||
width.max(scroller_width) + 2.0 * margin;
|
width.max(scroller_width) + 2.0 * margin;
|
||||||
|
|
@ -1661,12 +1685,14 @@ impl Scrollbars {
|
||||||
bounds: scrollbar_bounds,
|
bounds: scrollbar_bounds,
|
||||||
scroller,
|
scroller,
|
||||||
alignment: vertical.alignment,
|
alignment: vertical.alignment,
|
||||||
|
disabled,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let x_scrollbar = if let Some(horizontal) = show_scrollbar_x {
|
let x_scrollbar = if let Some((horizontal, disabled)) = show_scrollbar_x
|
||||||
|
{
|
||||||
let Scrollbar {
|
let Scrollbar {
|
||||||
width,
|
width,
|
||||||
margin,
|
margin,
|
||||||
|
|
@ -1730,6 +1756,7 @@ impl Scrollbars {
|
||||||
bounds: scrollbar_bounds,
|
bounds: scrollbar_bounds,
|
||||||
scroller,
|
scroller,
|
||||||
alignment: horizontal.alignment,
|
alignment: horizontal.alignment,
|
||||||
|
disabled,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
@ -1758,6 +1785,14 @@ impl Scrollbars {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn y_disabled(&self) -> bool {
|
||||||
|
self.y.map(|y| y.disabled).unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn x_disabled(&self) -> bool {
|
||||||
|
self.x.map(|x| x.disabled).unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
fn grab_y_scroller(&self, cursor_position: Point) -> Option<f32> {
|
fn grab_y_scroller(&self, cursor_position: Point) -> Option<f32> {
|
||||||
let scrollbar = self.y?;
|
let scrollbar = self.y?;
|
||||||
let scroller = scrollbar.scroller?;
|
let scroller = scrollbar.scroller?;
|
||||||
|
|
@ -1804,6 +1839,7 @@ pub(super) mod internals {
|
||||||
pub bounds: Rectangle,
|
pub bounds: Rectangle,
|
||||||
pub scroller: Option<Scroller>,
|
pub scroller: Option<Scroller>,
|
||||||
pub alignment: Anchor,
|
pub alignment: Anchor,
|
||||||
|
pub disabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scrollbar {
|
impl Scrollbar {
|
||||||
|
|
@ -1867,13 +1903,22 @@ pub(super) mod internals {
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum Status {
|
pub enum Status {
|
||||||
/// The [`Scrollable`] can be interacted with.
|
/// The [`Scrollable`] can be interacted with.
|
||||||
Active,
|
Active {
|
||||||
|
/// Whether or not the horizontal scrollbar is disabled meaning the content isn't overflowing.
|
||||||
|
is_horizontal_scrollbar_disabled: bool,
|
||||||
|
/// Whether or not the vertical scrollbar is disabled meaning the content isn't overflowing.
|
||||||
|
is_vertical_scrollbar_disabled: bool,
|
||||||
|
},
|
||||||
/// The [`Scrollable`] is being hovered.
|
/// The [`Scrollable`] is being hovered.
|
||||||
Hovered {
|
Hovered {
|
||||||
/// Indicates if the horizontal scrollbar is being hovered.
|
/// Indicates if the horizontal scrollbar is being hovered.
|
||||||
is_horizontal_scrollbar_hovered: bool,
|
is_horizontal_scrollbar_hovered: bool,
|
||||||
/// Indicates if the vertical scrollbar is being hovered.
|
/// Indicates if the vertical scrollbar is being hovered.
|
||||||
is_vertical_scrollbar_hovered: bool,
|
is_vertical_scrollbar_hovered: bool,
|
||||||
|
/// Whether or not the horizontal scrollbar is disabled meaning the content isn't overflowing.
|
||||||
|
is_horizontal_scrollbar_disabled: bool,
|
||||||
|
/// Whether or not the vertical scrollbar is disabled meaning the content isn't overflowing.
|
||||||
|
is_vertical_scrollbar_disabled: bool,
|
||||||
},
|
},
|
||||||
/// The [`Scrollable`] is being dragged.
|
/// The [`Scrollable`] is being dragged.
|
||||||
Dragged {
|
Dragged {
|
||||||
|
|
@ -1881,6 +1926,10 @@ pub enum Status {
|
||||||
is_horizontal_scrollbar_dragged: bool,
|
is_horizontal_scrollbar_dragged: bool,
|
||||||
/// Indicates if the vertical scrollbar is being dragged.
|
/// Indicates if the vertical scrollbar is being dragged.
|
||||||
is_vertical_scrollbar_dragged: bool,
|
is_vertical_scrollbar_dragged: bool,
|
||||||
|
/// Whether or not the horizontal scrollbar is disabled meaning the content isn't overflowing.
|
||||||
|
is_horizontal_scrollbar_disabled: bool,
|
||||||
|
/// Whether or not the vertical scrollbar is disabled meaning the content isn't overflowing.
|
||||||
|
is_vertical_scrollbar_disabled: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1958,7 +2007,7 @@ pub fn default(theme: &Theme, status: Status) -> Style {
|
||||||
};
|
};
|
||||||
|
|
||||||
match status {
|
match status {
|
||||||
Status::Active => Style {
|
Status::Active { .. } => Style {
|
||||||
container: container::Style::default(),
|
container: container::Style::default(),
|
||||||
vertical_rail: scrollbar,
|
vertical_rail: scrollbar,
|
||||||
horizontal_rail: scrollbar,
|
horizontal_rail: scrollbar,
|
||||||
|
|
@ -1967,6 +2016,7 @@ pub fn default(theme: &Theme, status: Status) -> Style {
|
||||||
Status::Hovered {
|
Status::Hovered {
|
||||||
is_horizontal_scrollbar_hovered,
|
is_horizontal_scrollbar_hovered,
|
||||||
is_vertical_scrollbar_hovered,
|
is_vertical_scrollbar_hovered,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
let hovered_scrollbar = Rail {
|
let hovered_scrollbar = Rail {
|
||||||
scroller: Scroller {
|
scroller: Scroller {
|
||||||
|
|
@ -1994,6 +2044,7 @@ pub fn default(theme: &Theme, status: Status) -> Style {
|
||||||
Status::Dragged {
|
Status::Dragged {
|
||||||
is_horizontal_scrollbar_dragged,
|
is_horizontal_scrollbar_dragged,
|
||||||
is_vertical_scrollbar_dragged,
|
is_vertical_scrollbar_dragged,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
let dragged_scrollbar = Rail {
|
let dragged_scrollbar = Rail {
|
||||||
scroller: Scroller {
|
scroller: Scroller {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue