diff options
author | Ethan Post <16603401+ecpost@users.noreply.github.com> | 2024-09-26 02:36:20 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-26 11:36:20 +0200 |
commit | 25abb74465a17d24a61501caa54dac67cd1aa86b (patch) | |
tree | d8db13729c53b817189697a0ca5b3bbdcba50c9e | |
parent | a72ebbeafcfc0364407dc5a94151ebf10152408b (diff) |
egui_extras: Add `TableBuilder::animate_scrolling` (#5159)
This will allow disabling the animation that occurs during
`scroll_to_row` calls. Follows the same coding style as the other scroll
options in `TableBuilder`.
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
-rw-r--r-- | crates/egui_extras/src/table.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/crates/egui_extras/src/table.rs b/crates/egui_extras/src/table.rs index c8b8c500..7f9c8110 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 animate_scrolling(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); |