list: Fix List scroll_to_item position. (#1158)
This commit is contained in:
parent
35ba09a561
commit
e29418e9e4
2 changed files with 20 additions and 6 deletions
|
|
@ -478,14 +478,25 @@ impl Render for ListStory {
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
Button::new("scroll-center")
|
Button::new("scroll-selected")
|
||||||
.outline()
|
.outline()
|
||||||
.child("Scroll to section 2")
|
.child("Scroll to selected")
|
||||||
|
.small()
|
||||||
|
.on_click(cx.listener(|this, _, window, cx| {
|
||||||
|
this.company_list.update(cx, |list, cx| {
|
||||||
|
list.scroll_to_selected_item(window, cx);
|
||||||
|
})
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("scroll-to-item")
|
||||||
|
.outline()
|
||||||
|
.child("Scroll to (5, 1)")
|
||||||
.small()
|
.small()
|
||||||
.on_click(cx.listener(|this, _, window, cx| {
|
.on_click(cx.listener(|this, _, window, cx| {
|
||||||
this.company_list.update(cx, |list, cx| {
|
this.company_list.update(cx, |list, cx| {
|
||||||
list.scroll_to_item(
|
list.scroll_to_item(
|
||||||
IndexPath::default().section(1).row(0),
|
IndexPath::new(1).section(5),
|
||||||
ScrollStrategy::Center,
|
ScrollStrategy::Center,
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,9 @@ where
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.scroll_handle.scroll_to_item(ix.row, strategy);
|
if let Some(item_ix) = self.rows_cache.position_of(&ix) {
|
||||||
|
self.scroll_handle.scroll_to_item(item_ix, strategy);
|
||||||
|
}
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -226,8 +228,9 @@ where
|
||||||
|
|
||||||
pub fn scroll_to_selected_item(&mut self, _: &mut Window, cx: &mut Context<Self>) {
|
pub fn scroll_to_selected_item(&mut self, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
if let Some(ix) = self.selected_index {
|
if let Some(ix) = self.selected_index {
|
||||||
if let Some(ix) = self.rows_cache.position_of(&ix) {
|
if let Some(item_ix) = self.rows_cache.position_of(&ix) {
|
||||||
self.scroll_handle.scroll_to_item(ix, ScrollStrategy::Top);
|
self.scroll_handle
|
||||||
|
.scroll_to_item(item_ix, ScrollStrategy::Top);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue