Make stick_to_bottom take a bool argument

This commit is contained in:
Emil Ernerfeldt 2022-08-02 20:34:50 +02:00
parent 263c9bd601
commit 06adb09fa3
4 changed files with 11 additions and 13 deletions

View file

@ -272,8 +272,8 @@ impl ScrollArea {
/// it will remain focused on whatever content viewport the user left it on. If the scroll /// it will remain focused on whatever content viewport the user left it on. If the scroll
/// handle is dragged all the way to the right it will again become stuck and remain there /// handle is dragged all the way to the right it will again become stuck and remain there
/// until manually pulled from the end position. /// until manually pulled from the end position.
pub fn stick_to_right(mut self) -> Self { pub fn stick_to_right(mut self, stick: bool) -> Self {
self.stick_to_end[0] = true; self.stick_to_end[0] = stick;
self self
} }
@ -283,8 +283,8 @@ impl ScrollArea {
/// it will remain focused on whatever content viewport the user left it on. If the scroll /// it will remain focused on whatever content viewport the user left it on. If the scroll
/// handle is dragged to the bottom it will again become stuck and remain there until manually /// handle is dragged to the bottom it will again become stuck and remain there until manually
/// pulled from the end position. /// pulled from the end position.
pub fn stick_to_bottom(mut self) -> Self { pub fn stick_to_bottom(mut self, stick: bool) -> Self {
self.stick_to_end[1] = true; self.stick_to_end[1] = stick;
self self
} }
} }

View file

@ -371,7 +371,7 @@ impl EguiWindows {
ui.separator(); ui.separator();
egui::ScrollArea::vertical() egui::ScrollArea::vertical()
.stick_to_bottom() .stick_to_bottom(true)
.show(ui, |ui| { .show(ui, |ui| {
for event in output_event_history { for event in output_event_history {
ui.label(format!("{:?}", event)); ui.label(format!("{:?}", event));

View file

@ -271,7 +271,7 @@ impl super::View for ScrollStickTo {
let text_style = TextStyle::Body; let text_style = TextStyle::Body;
let row_height = ui.text_style_height(&text_style); let row_height = ui.text_style_height(&text_style);
ScrollArea::vertical().stick_to_bottom().show_rows( ScrollArea::vertical().stick_to_bottom(true).show_rows(
ui, ui,
row_height, row_height,
self.n_items, self.n_items,

View file

@ -110,8 +110,8 @@ impl<'a> TableBuilder<'a> {
/// Should the scroll handle stick to the bottom position even as the content size changes /// Should the scroll handle stick to the bottom position even as the content size changes
/// dynamically? The scroll handle remains stuck until manually changed, and will become stuck /// dynamically? The scroll handle remains stuck until manually changed, and will become stuck
/// once again when repositioned to the bottom. Default: `false`. /// once again when repositioned to the bottom. Default: `false`.
pub fn stick_to_bottom(mut self) -> Self { pub fn stick_to_bottom(mut self, stick: bool) -> Self {
self.stick_to_bottom = true; self.stick_to_bottom = stick;
self self
} }
@ -295,11 +295,9 @@ impl<'a> Table<'a> {
let mut new_widths = widths.clone(); let mut new_widths = widths.clone();
let mut scroll_area = egui::ScrollArea::new([false, scroll]).auto_shrink([true; 2]); let scroll_area = egui::ScrollArea::new([false, scroll])
.auto_shrink([true; 2])
if stick_to_bottom { .stick_to_bottom(stick_to_bottom);
scroll_area = scroll_area.stick_to_bottom();
}
scroll_area.show(ui, move |ui| { scroll_area.show(ui, move |ui| {
let layout = StripLayout::new(ui, CellDirection::Horizontal, clip, cell_layout); let layout = StripLayout::new(ui, CellDirection::Horizontal, clip, cell_layout);