diff --git a/imgui-examples/examples/test_window_impl.rs b/imgui-examples/examples/test_window_impl.rs index d2c35f6..46bc3fc 100644 --- a/imgui-examples/examples/test_window_impl.rs +++ b/imgui-examples/examples/test_window_impl.rs @@ -1277,12 +1277,12 @@ fn show_app_log(ui: &Ui, app_log: &mut Vec) { ChildWindow::new("logwindow") .flags(WindowFlags::HORIZONTAL_SCROLLBAR) .build(ui, || { - let mut clipper = ListClipper::new() - .items_count(app_log.len() as i32) - .begin(ui); - while clipper.step() { - for line in clipper.display_start()..clipper.display_end() { - ui.text(&app_log[line as usize]); + if !app_log.is_empty() { + let mut clipper = ListClipper::new(app_log.len() as i32).begin(ui); + while clipper.step() { + for line in clipper.display_start()..clipper.display_end() { + ui.text(&app_log[line as usize]); + } } } if ui.scroll_y() >= ui.scroll_max_y() { diff --git a/imgui/src/list_clipper.rs b/imgui/src/list_clipper.rs index 8582bd5..a595d26 100644 --- a/imgui/src/list_clipper.rs +++ b/imgui/src/list_clipper.rs @@ -10,18 +10,13 @@ pub struct ListClipper { } impl ListClipper { - pub fn new() -> Self { + pub fn new(items_count: i32) -> Self { ListClipper { - items_count: -1, + items_count, items_height: -1.0, } } - pub fn items_count(mut self, items_count: i32) -> Self { - self.items_count = items_count; - self - } - pub fn items_height(mut self, items_height: f32) -> Self { self.items_height = items_height; self @@ -76,7 +71,7 @@ impl<'ui> Drop for ListClipperToken<'ui> { sys::ImGuiListClipper_destroy(self.list_clipper); }; } else if !thread::panicking() { - panic!("step() was not called until it returned false"); + panic!("Forgot to call End(), or to Step() until false?"); } } }