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

Add TableBuilder::drag_to_scroll #3100

Merged
merged 2 commits into from
Aug 14, 2023
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
12 changes: 12 additions & 0 deletions crates/egui_extras/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ fn to_sizing(columns: &[Column]) -> crate::sizing::Sizing {

struct TableScrollOptions {
vscroll: bool,
drag_to_scroll: bool,
stick_to_bottom: bool,
scroll_to_row: Option<(usize, Option<Align>)>,
scroll_offset_y: Option<f32>,
Expand All @@ -169,6 +170,7 @@ impl Default for TableScrollOptions {
fn default() -> Self {
Self {
vscroll: true,
drag_to_scroll: true,
stick_to_bottom: false,
scroll_to_row: None,
scroll_offset_y: None,
Expand Down Expand Up @@ -271,6 +273,14 @@ impl<'a> TableBuilder<'a> {
self.vscroll(vscroll)
}

/// Enables scrolling the table's contents using mouse drag (default: `true`).
///
/// See [`ScrollArea::drag_to_scroll`] for more.
pub fn drag_to_scroll(mut self, drag_to_scroll: bool) -> Self {
self.scroll_options.drag_to_scroll = drag_to_scroll;
self
}

/// 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
/// once again when repositioned to the bottom. Default: `false`.
Expand Down Expand Up @@ -551,6 +561,7 @@ impl<'a> Table<'a> {

let TableScrollOptions {
vscroll,
drag_to_scroll,
stick_to_bottom,
scroll_to_row,
scroll_offset_y,
Expand All @@ -563,6 +574,7 @@ impl<'a> Table<'a> {

let mut scroll_area = ScrollArea::new([false, vscroll])
.auto_shrink([true; 2])
.drag_to_scroll(drag_to_scroll)
.stick_to_bottom(stick_to_bottom)
.min_scrolled_height(min_scrolled_height)
.max_height(max_scroll_height)
Expand Down
Loading