Skip to content

Commit

Permalink
infinite_scroll: Only set loading state to loading when a loader exists
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Feb 9, 2024
1 parent d440b32 commit 94636fa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions crates/egui_infinite_scroll/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# egui_infinite_scroll changelog

## 0.2.1
- fix loading() returning true when the list is completely empty

## 0.2.0
- update egui to 0.26

Expand Down
4 changes: 4 additions & 0 deletions crates/egui_infinite_scroll/examples/infinite_scroll_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ pub async fn main() -> eframe::Result<()> {
infinite_scroll.ui(ui, 10, |ui, _index, item| {
ui.label(format!("Item {}", item));
});

if infinite_scroll.bottom_loading_state().loading() {
ui.spinner();
}
});
});
},
Expand Down
10 changes: 4 additions & 6 deletions crates/egui_infinite_scroll/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,9 @@ impl<T: Debug + Send + Sync + 'static, Cursor: Clone + Debug + Send + 'static>
if item_range.end + end_prefetch >= items.len()
&& matches!(self.bottom_loading_state, LoadingState::Idle { .. })
{
self.bottom_loading_state = LoadingState::Loading;
let sender = self.bottom_inbox.sender();

if let Some(end_loader) = &mut self.end_loader {
self.bottom_loading_state = LoadingState::Loading;
let sender = self.bottom_inbox.sender();
end_loader(
self.end_cursor.clone(),
Box::new(move |result| match result {
Expand All @@ -334,10 +333,9 @@ impl<T: Debug + Send + Sync + 'static, Cursor: Clone + Debug + Send + 'static>
if item_range.start < end_prefetch
&& matches!(self.top_loading_state, LoadingState::Idle { .. })
{
self.top_loading_state = LoadingState::Loading;
let sender = self.top_inbox.sender();

if let Some(start_loader) = &mut self.start_loader {
self.top_loading_state = LoadingState::Loading;
let sender = self.top_inbox.sender();
start_loader(
self.start_cursor.clone(),
Box::new(move |result| match result {
Expand Down

0 comments on commit 94636fa

Please sign in to comment.