From 0d0f7cb82e6d4b70a98de21bfa940c62e2e13a26 Mon Sep 17 00:00:00 2001 From: Eduardo Flores Date: Wed, 24 Nov 2021 18:19:29 -0700 Subject: [PATCH] Better way to clear GtkListBox --- examples/launcher/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/launcher/main.rs b/examples/launcher/main.rs index 8e530b04..2bd9cca4 100644 --- a/examples/launcher/main.rs +++ b/examples/launcher/main.rs @@ -21,7 +21,6 @@ fn icon_source(icon: >k::Image, source: &Option) { } } - enum Event { Response(pop_launcher::Response), Search(String), @@ -70,7 +69,7 @@ fn main() { search.set_placeholder_text(Some(" Type to search apps, or type '?' for more options.")); vbox.append(&search); - let listbox = gtk::ListBox::new(); + let mut listbox = gtk::ListBox::new(); vbox.append(&listbox); { @@ -109,10 +108,11 @@ fn main() { while let Some(event) = rx.recv().await { match event { Event::Search(search) => { - //TODO: is this the best way to clear a listbox? - while let Some(child) = listbox.last_child() { - listbox.remove(&child); + if let Some(child) = vbox.last_child() { + vbox.remove(&child); } + listbox = gtk::ListBox::new(); + vbox.append(&listbox); let _ = launcher.send(pop_launcher::Request::Search(search)).await; }