Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ScrollComponent not handling LifeCycle::HotChanged. #2343

Merged
merged 2 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ You can find its changes [documented below](#070---2021-01-01).
- X11: window focus events ([#1938] by [@Maan2003]
- Preserve the aspect ratio of a clipped region in an Image ([#2195] by [@barsae])
- GTK: Hot state now properly resets when the mouse leaves the window via an occluded part. ([#2324] by [@xStrom])
- Scrollbars no longer remain permanently visible when the mouse leaves the window. ([#2343] by [@xStrom])

### Visual

Expand Down Expand Up @@ -892,6 +893,7 @@ Last release without a changelog :(
[#2331]: https://github.com/linebender/druid/pull/2331
[#2335]: https://github.com/linebender/druid/pull/2335
[#2340]: https://github.com/linebender/druid/pull/2340
[#2343]: https://github.com/linebender/druid/pull/2343

[Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master
[0.7.0]: https://github.com/linebender/druid/compare/v0.6.0...v0.7.0
Expand Down
11 changes: 7 additions & 4 deletions druid/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,19 @@ pub enum Event {
/// Called when the mouse is moved.
///
/// The `MouseMove` event is propagated to the active widget, if
/// there is one, otherwise to hot widgets (see `HotChanged`).
/// there is one, otherwise to hot widgets (see [`HotChanged`]).
/// If a widget loses its hot status due to `MouseMove` then that specific
/// `MouseMove` event is also still sent to that widget.
/// `MouseMove` event is also still sent to that widget. However a widget
/// can lose its hot status even without a `MouseMove` event, so make
/// sure to also handle [`HotChanged`] if you care about the hot status.
///
/// The `MouseMove` event is also the primary mechanism for widgets
/// to set a cursor, for example to an I-bar inside a text widget. A
/// simple tactic is for the widget to unconditionally call
/// [`set_cursor`] in the MouseMove handler, as `MouseMove` is only
/// propagated to active or hot widgets.
///
/// [`HotChanged`]: LifeCycle::HotChanged
/// [`set_cursor`]: struct.EventCtx.html#method.set_cursor
MouseMove(MouseEvent),
/// Called when the mouse wheel or trackpad is scrolled.
Expand Down Expand Up @@ -242,8 +245,8 @@ pub enum InternalEvent {
///
/// Similarly the [`LifeCycle::Size`] method occurs during [`layout`], and
/// [`LifeCycle::HotChanged`] can occur both during [`event`] (if the mouse
/// moves over a widget) or during [`layout`], if a widget is resized and
/// that moves it under the mouse.
/// moves over a widget) or in response to [`LifeCycle::ViewContextChanged`],
/// if a widget is moved away from under the mouse.
///
/// [`event`]: crate::Widget::event
/// [`update`]: crate::Widget::update
Expand Down
15 changes: 12 additions & 3 deletions druid/src/scroll_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,18 @@ impl ScrollComponent {
///
/// Make sure to call on every lifecycle event
pub fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle, env: &Env) {
if let LifeCycle::Size(_) = event {
// Show the scrollbars any time our size changes
self.reset_scrollbar_fade(|d| ctx.request_timer(d), env);
match event {
LifeCycle::Size(_) => {
// Show the scrollbars any time our size changes
self.reset_scrollbar_fade(|d| ctx.request_timer(d), env);
}
LifeCycle::HotChanged(false) => {
if self.hovered.is_hovered() {
self.hovered = BarHoveredState::None;
self.reset_scrollbar_fade(|d| ctx.request_timer(d), env);
}
}
_ => (),
}
}
}
Expand Down