Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egui_extras: Add TableBuilder::animate_scrolling #5159

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion crates/egui_extras/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ struct TableScrollOptions {
max_scroll_height: f32,
auto_shrink: Vec2b,
scroll_bar_visibility: ScrollBarVisibility,
animated: bool,
}

impl Default for TableScrollOptions {
Expand All @@ -202,6 +203,7 @@ impl Default for TableScrollOptions {
max_scroll_height: f32::INFINITY,
auto_shrink: Vec2b::TRUE,
scroll_bar_visibility: ScrollBarVisibility::VisibleWhenNeeded,
animated: true,
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Loading