fix, make items_count non-optional

This commit is contained in:
henbr 2020-12-31 15:41:49 +01:00 committed by Thom Chiovoloni
parent 936e63bdfa
commit 1ea6073821
2 changed files with 9 additions and 14 deletions

View File

@ -1277,12 +1277,12 @@ fn show_app_log(ui: &Ui, app_log: &mut Vec<String>) {
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() {

View File

@ -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?");
}
}
}