Skip to content

Commit

Permalink
Fix ScrollComponent not handling LifeCycle::HotChanged. (#2343)
Browse files Browse the repository at this point in the history
  • Loading branch information
xStrom committed Jan 26, 2023
1 parent 96d8a1c commit 9050ac3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
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

0 comments on commit 9050ac3

Please sign in to comment.