virtual_list: Avoid scroll when list contents not overflow. (#1125)

- Fix scrollbar position in popup menu.
This commit is contained in:
Jason Lee 2025-08-08 19:13:18 +08:00 committed by GitHub
parent b1f4a4f642
commit 7f64f8798e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 20 deletions

View file

@ -217,24 +217,43 @@ impl Render for MenuStory {
}), }),
) )
.child( .child(
section("Menu with scrollbar").child( section("Menu with scrollbar")
Button::new("popup-menu-11112") .child(
.outline() Button::new("popup-menu-scrollable-1")
.label("Scrollable Menu") .outline()
.popup_menu_with_anchor(Corner::TopRight, move |this, _, _| { .label("Scrollable Menu (100 items)")
let mut this = this .popup_menu_with_anchor(Corner::TopRight, move |this, _, _| {
.scrollable() let mut this = this
.max_h(px(300.)) .scrollable()
.label(format!("Total {} items", 100)); .max_h(px(300.))
for i in 0..100 { .label(format!("Total {} items", 100));
this = this.menu( for i in 0..100 {
SharedString::from(format!("Item {}", i)), this = this.menu(
Box::new(Info(i)), SharedString::from(format!("Item {}", i)),
) Box::new(Info(i)),
} )
this.min_w(px(100.)) }
}), this.min_w(px(100.))
), }),
)
.child(
Button::new("popup-menu-scrollable-2")
.outline()
.label("Scrollable Menu (5 items)")
.popup_menu_with_anchor(Corner::TopRight, move |this, _, _| {
let mut this = this
.scrollable()
.max_h(px(300.))
.label(format!("Total {} items", 100));
for i in 0..5 {
this = this.menu(
SharedString::from(format!("Item {}", i)),
Box::new(Info(i)),
)
}
this.min_w(px(100.))
}),
),
) )
} }
} }

View file

@ -942,8 +942,8 @@ impl Render for PopupMenu {
.absolute() .absolute()
.top_0() .top_0()
.left_0() .left_0()
.right_0p5() .right_0()
.bottom_0p5() .bottom_0()
.child(Scrollbar::vertical(&self.scroll_state, &self.scroll_handle)), .child(Scrollbar::vertical(&self.scroll_state, &self.scroll_handle)),
) )
}) })

View file

@ -548,6 +548,7 @@ impl Element for VirtualList {
scroll_to_item, scroll_to_item,
); );
} }
scroll_offset = scroll_offset.min(&point(px(0.), px(0.)));
self.base.interactivity().prepaint( self.base.interactivity().prepaint(
global_id, global_id,