From 03947bc22243a1e3add3f7372a07aebf6386d729 Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Tue, 24 Jan 2023 02:04:07 +0200 Subject: [PATCH 1/2] Fix `ScrollComponent` not handling `LifeCycle::HotChanged`. --- druid/src/event.rs | 11 +++++++---- druid/src/scroll_component.rs | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/druid/src/event.rs b/druid/src/event.rs index 0b6ec1be1..0a450513a 100644 --- a/druid/src/event.rs +++ b/druid/src/event.rs @@ -95,9 +95,11 @@ 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 @@ -105,6 +107,7 @@ pub enum Event { /// [`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. @@ -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 diff --git a/druid/src/scroll_component.rs b/druid/src/scroll_component.rs index 9dd3c171b..b0886881e 100644 --- a/druid/src/scroll_component.rs +++ b/druid/src/scroll_component.rs @@ -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); + } + } + _ => (), } } } From 720e467702e6b72b396be7efcba8ae1da4e503a1 Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Tue, 24 Jan 2023 02:58:07 +0200 Subject: [PATCH 2/2] Add changelog entry. --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdad28f98..150406bfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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