From bf3291a48bfe3b0a9d9f8a08d6b44d931eb71a2b Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 30 Nov 2024 09:41:10 +0100 Subject: [PATCH] list: set yew keys on all list items to keep item state And remove unused code. Signed-off-by: Dietmar Maurer --- src/widget/list.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/widget/list.rs b/src/widget/list.rs index af266d0..814ebec 100644 --- a/src/widget/list.rs +++ b/src/widget/list.rs @@ -100,7 +100,6 @@ pub struct PwtList { viewport_size_observer: Option, viewport_scrollbar_size: Option, viewport_scroll_top: usize, - set_viewport_scroll_top: Option, table_ref: NodeRef, table_size_observer: Option, @@ -175,12 +174,14 @@ impl PwtList { let separator = separator.emit(pos); content.add_child( Container::new() + .key(format!("sep-{pos}")) .class("pwt-list-separator") .with_child(separator), ); } } - let row = props.renderer.emit(pos); + let mut row = props.renderer.emit(pos); + row.set_key(format!("row-{pos}")); content.add_child(row); } @@ -205,7 +206,6 @@ impl Component for PwtList { viewport_scrollbar_size: None, viewport_ref: NodeRef::default(), viewport_scroll_top: 0, - set_viewport_scroll_top: None, table_ref: NodeRef::default(), table_size_observer: None, @@ -292,13 +292,5 @@ impl Component for PwtList { self.table_size_observer = Some(size_observer); } } - if let Some(top) = self.set_viewport_scroll_top.take() { - // Note: we delay setting ScrollTop until we rendered the - // viewport with correct height. Else, set_viewport_scroll_top can - // fail because the viewport is smaller. - if let Some(el) = self.viewport_ref.cast::() { - el.set_scroll_top(top as i32); - } - } } } -- 2.39.5