Ensure horizontal scrollbars show as needed (#30964)
This PR fixes an issue where the horizontal scrollbar was sometimes not rendered despite being needed for the outline and project panels. The issue occured since `self.width` does not neccessarily have to be set when the scrollbar is rendered (it is only set on panel resize). However, the check for a `width` is not needed at all since the scrollbar constructor determines whether a scrollbar has to be rendered or not. Hence, this does not need to be special-cased. Furthermore, since `Scrollbar::horizontal()` returns `Some(...)` when a scrollbar needs to be rendered, we do not have to check for this seperately on the scroll handle and can just map on the option. This simplifies the code a bit. | `main` | This PR | | --- | --- | |  |  | Release Notes: - Fixed an issue where the horizontal scrollbar would not render in the project and outline panels.
This commit is contained in:
parent
ef0e1cb2ba
commit
a47fd1d723
2 changed files with 6 additions and 38 deletions
|
@ -4335,19 +4335,7 @@ impl OutlinePanel {
|
|||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let scroll_handle = self.scroll_handle.0.borrow();
|
||||
let longest_item_width = scroll_handle
|
||||
.last_item_size
|
||||
.filter(|size| size.contents.width > size.item.width)?
|
||||
.contents
|
||||
.width
|
||||
.0 as f64;
|
||||
if longest_item_width < scroll_handle.base_handle.bounds().size.width.0 as f64 {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(
|
||||
Scrollbar::horizontal(self.horizontal_scrollbar_state.clone()).map(|scrollbar| {
|
||||
div()
|
||||
.occlude()
|
||||
.id("project-panel-horizontal-scroll")
|
||||
|
@ -4384,12 +4372,8 @@ impl OutlinePanel {
|
|||
.bottom_0()
|
||||
.h(px(12.))
|
||||
.cursor_default()
|
||||
.when(self.width.is_some(), |this| {
|
||||
this.children(Scrollbar::horizontal(
|
||||
self.horizontal_scrollbar_state.clone(),
|
||||
))
|
||||
}),
|
||||
)
|
||||
.child(scrollbar)
|
||||
})
|
||||
}
|
||||
|
||||
fn should_show_scrollbar(cx: &App) -> bool {
|
||||
|
|
|
@ -4340,19 +4340,7 @@ impl ProjectPanel {
|
|||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let scroll_handle = self.scroll_handle.0.borrow();
|
||||
let longest_item_width = scroll_handle
|
||||
.last_item_size
|
||||
.filter(|size| size.contents.width > size.item.width)?
|
||||
.contents
|
||||
.width
|
||||
.0 as f64;
|
||||
if longest_item_width < scroll_handle.base_handle.bounds().size.width.0 as f64 {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(
|
||||
Scrollbar::horizontal(self.horizontal_scrollbar_state.clone()).map(|scrollbar| {
|
||||
div()
|
||||
.occlude()
|
||||
.id("project-panel-horizontal-scroll")
|
||||
|
@ -4389,12 +4377,8 @@ impl ProjectPanel {
|
|||
.bottom_1()
|
||||
.h(px(12.))
|
||||
.cursor_default()
|
||||
.when(self.width.is_some(), |this| {
|
||||
this.children(Scrollbar::horizontal(
|
||||
self.horizontal_scrollbar_state.clone(),
|
||||
))
|
||||
}),
|
||||
)
|
||||
.child(scrollbar)
|
||||
})
|
||||
}
|
||||
|
||||
fn dispatch_context(&self, window: &Window, cx: &Context<Self>) -> KeyContext {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue