From 8e466113c4c545a19a619394b2a48cb6005e7813 Mon Sep 17 00:00:00 2001 From: ecpost <16603401+ecpost@users.noreply.github.com> Date: Tue, 24 Sep 2024 13:41:21 -0700 Subject: [PATCH] Add `animated` method/option to TableBuilder for TableScrollOptions and internal ScrollArea. --- crates/egui_extras/src/table.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/egui_extras/src/table.rs b/crates/egui_extras/src/table.rs index c8b8c5006a6..14650e25c39 100644 --- a/crates/egui_extras/src/table.rs +++ b/crates/egui_extras/src/table.rs @@ -188,6 +188,7 @@ struct TableScrollOptions { max_scroll_height: f32, auto_shrink: Vec2b, scroll_bar_visibility: ScrollBarVisibility, + animated: bool, } impl Default for TableScrollOptions { @@ -202,6 +203,7 @@ impl Default for TableScrollOptions { max_scroll_height: f32::INFINITY, auto_shrink: Vec2b::TRUE, scroll_bar_visibility: ScrollBarVisibility::VisibleWhenNeeded, + animated: true, } } } @@ -409,6 +411,15 @@ impl<'a> TableBuilder<'a> { self } + /// Should the scroll area animate `scroll_to_*` functions? + /// + /// Default: `true`. + #[inline] + pub fn animated(mut self, animated: bool) -> Self { + self.scroll_options.animated = animated; + self + } + /// What layout should we use for the individual cells? #[inline] pub fn cell_layout(mut self, cell_layout: egui::Layout) -> Self { @@ -726,6 +737,7 @@ impl<'a> Table<'a> { max_scroll_height, auto_shrink, scroll_bar_visibility, + animated, } = scroll_options; let cursor_position = ui.cursor().min; @@ -736,7 +748,8 @@ impl<'a> Table<'a> { .min_scrolled_height(min_scrolled_height) .max_height(max_scroll_height) .auto_shrink(auto_shrink) - .scroll_bar_visibility(scroll_bar_visibility); + .scroll_bar_visibility(scroll_bar_visibility) + .animated(animated); if let Some(scroll_offset_y) = scroll_offset_y { scroll_area = scroll_area.vertical_scroll_offset(scroll_offset_y);