Initial upper limit. However we also need a lower limit..

pull/1/head
Benedikt Terhechte 3 years ago
parent 19fd7a89d2
commit 33fb716c6e

@ -1,3 +1,5 @@
use std::ops::RangeInclusive;
use eframe::egui::Rect;
use eyre::Result;
@ -74,8 +76,43 @@ impl Engine {
}
pub fn items_with_size(&mut self, rect: Rect) -> Option<&[Partition]> {
self.partitions.last_mut()?.update_layout(rect);
Some(self.partitions.last().as_ref()?.items.as_slice())
let partition = self.partitions.last_mut()?;
partition.update_layout(rect);
Some(partition.items())
}
/// Retrieve the min and max amount of items. The range that should be displayed.
/// Per default, it is the whole range of the partition
pub fn current_range(&self) -> Option<(RangeInclusive<usize>, usize)> {
let partition = self.partitions.last()?;
let len = partition.len();
let r = match &partition.range {
Some(n) => (0..=len, *n.end()),
None => (0..=len, len),
};
Some(r)
}
pub fn set_current_range(&mut self, range: Option<RangeInclusive<usize>>) -> Option<()> {
match self.partitions.last_mut() {
Some(n) => {
if let Some(r) = range {
let len = n.len();
dbg!(&len, r.start(), r.end());
if len > *r.start() && *r.end() < len {
dbg!(&r);
n.range = Some(r.clone());
Some(())
} else {
None
}
} else {
n.range = None;
Some(())
}
}
None => None,
}
}
/// Returns (index in the `group_by_stack`, index of the chosen group, value of the group if selected)

@ -32,8 +32,9 @@ impl Partition {
/// have to do the layout calculation in a widget.
#[derive(Debug)]
pub struct Partitions {
pub items: Vec<Partition>,
items: Vec<Partition>,
pub selected: Option<Partition>,
pub range: Option<std::ops::RangeInclusive<usize>>,
}
impl Partitions {
@ -41,9 +42,14 @@ impl Partitions {
Self {
items,
selected: None,
range: None,
}
}
pub fn len(&self) -> usize {
self.items.len()
}
/// Update the layout information in the partitions
/// based on the current size
pub fn update_layout(&mut self, rect: EguiRect) {
@ -54,7 +60,19 @@ impl Partitions {
rect.width() as f64,
rect.height() as f64,
);
layout.layout_items(&mut self.items, bounds);
layout.layout_items(&mut self.items(), bounds);
}
/// The items in this partition, with range applied
pub fn items(&mut self) -> &mut [Partition] {
match &self.range {
Some(n) => {
// we reverse the range
let reversed_range = (self.len() - n.end())..=(self.len() - 1);
&mut self.items[reversed_range]
}
None => self.items.as_mut_slice(),
}
}
}

@ -63,7 +63,20 @@ impl epi::App for GmailDBApp {
ui.add(Spinner::new(egui::vec2(50.0, 50.0)));
});
} else {
ui.vertical(|ui| {
ui.horizontal(|ui| {
if let Some((range, total)) = engine.current_range() {
ui.label("Limit");
let mut selected = total;
let response = ui.add(egui::Slider::new(&mut selected, range));
if response.changed() {
dbg!(&selected);
engine.set_current_range(Some(0..=selected));
}
}
});
ui.add(super::widgets::Rectangles::new(engine, error));
});
}
});
}
@ -72,7 +85,6 @@ impl epi::App for GmailDBApp {
frame.set_window_size(ctx.used_size());
// If we're waiting for a computation to succeed, we re-render again.
// The initial plan of calling `ctx.request_repaint()` from a thread didn't work.
if engine.is_busy() {
ctx.request_repaint();
}

Loading…
Cancel
Save