gpui: Round scroll_max to two decimal places (#34832)

Follow up to #31836 

After enabling rounding in the Taffy layout engine, we frequently run
into cases where the bounds produced by Taffy and ours slightly differ
after 5 or more decimal places. This leads to cases where containers
become scrollable for less than 0.0000x Pixels. In case this happens for
e.g. hover popovers, we render a scrollbar due to the container being
technically scrollable, even though the scroll amount here will in
practice never be visible.

This change fixes this by rounding the `scroll_max` by which we clamp
the current scroll position to two decimal places. We don't benefit from
the additional floating point precision here at all and it stops such
containers from becoming scrollable altogether. Furthermore, we now
store the `scroll_max` instead of the `padded_content_size` as the
former gives a much better idea on whether the corresponding container
is scrollable or not.

| `main` | After these changes |
| -- | -- |
| <img width="610" height="316" alt="main"
src="https://github.com/user-attachments/assets/ffcc0322-6d6e-4f79-a916-bd3c57fe4211"
/> | <img width="610" height="316" alt="scroll_max_rounded"
src="https://github.com/user-attachments/assets/5fe530f5-2e21-4aaa-81f4-e5c53ab73e4f"
/> |

Release Notes:

- Fixed an issue where scrollbars would appear in containers where no
scrolling was possible.
This commit is contained in:
Finn Evers 2025-07-21 22:24:33 +02:00 committed by GitHub
parent 8eca7f32e2
commit 5b3e371812
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 55 additions and 33 deletions

View file

@ -18,7 +18,7 @@ use futures::{StreamExt, stream::FuturesUnordered};
use gpui::{
Action, AnyElement, App, AsyncWindowContext, ClickEvent, ClipboardItem, Context, Corner, Div,
DragMoveEvent, Entity, EntityId, EventEmitter, ExternalPaths, FocusHandle, FocusOutEvent,
Focusable, KeyContext, MouseButton, MouseDownEvent, NavigationDirection, Pixels, Point,
Focusable, IsZero, KeyContext, MouseButton, MouseDownEvent, NavigationDirection, Pixels, Point,
PromptLevel, Render, ScrollHandle, Subscription, Task, WeakEntity, WeakFocusHandle, Window,
actions, anchored, deferred, prelude::*,
};
@ -46,8 +46,8 @@ use theme::ThemeSettings;
use ui::{
ButtonSize, Color, ContextMenu, ContextMenuEntry, ContextMenuItem, DecoratedIcon, IconButton,
IconButtonShape, IconDecoration, IconDecorationKind, IconName, IconSize, Indicator, Label,
PopoverMenu, PopoverMenuHandle, ScrollableHandle, Tab, TabBar, TabPosition, Tooltip,
prelude::*, right_click_menu,
PopoverMenu, PopoverMenuHandle, Tab, TabBar, TabPosition, Tooltip, prelude::*,
right_click_menu,
};
use util::{ResultExt, debug_panic, maybe, truncate_and_remove_front};
@ -2865,10 +2865,9 @@ impl Pane {
}
})
.children(pinned_tabs.len().ne(&0).then(|| {
let content_width = self.tab_bar_scroll_handle.content_size().width;
let viewport_width = self.tab_bar_scroll_handle.viewport().size.width;
let max_scroll = self.tab_bar_scroll_handle.max_offset().width;
// We need to check both because offset returns delta values even when the scroll handle is not scrollable
let is_scrollable = content_width > viewport_width;
let is_scrollable = !max_scroll.is_zero();
let is_scrolled = self.tab_bar_scroll_handle.offset().x < px(0.);
let has_active_unpinned_tab = self.active_item_index >= self.pinned_tab_count;
h_flex()