diff --git a/demo/src/split_scroll_demo.rs b/demo/src/split_scroll_demo.rs index e22fa19..c65c18a 100644 --- a/demo/src/split_scroll_demo.rs +++ b/demo/src/split_scroll_demo.rs @@ -12,6 +12,9 @@ impl SplitScrollDemo { SplitScroll { scroll_enabled: Vec2b::new(true, true), + animated: true, + drag_to_scroll: true, + scroll_bar_visibility: egui::scroll_area::ScrollBarVisibility::VisibleWhenNeeded, fixed_size: vec2(123.0, 37.0), scroll_outer_size: vec2(600.0, 400.0), scroll_content_size: vec2(10_000.0, 10_000.0), diff --git a/demo/src/table_demo.rs b/demo/src/table_demo.rs index 925f96c..5e136a9 100644 --- a/demo/src/table_demo.rs +++ b/demo/src/table_demo.rs @@ -9,6 +9,8 @@ pub struct TableDemo { num_sticky_cols: usize, default_column: egui_table::Column, auto_size_mode: egui_table::AutoSizeMode, + animated: bool, + scroll_bar_visibility: egui::scroll_area::ScrollBarVisibility, top_row_height: f32, row_height: f32, is_row_expanded: BTreeMap, @@ -25,6 +27,8 @@ impl Default for TableDemo { .range(10.0..=500.0) .resizable(true), auto_size_mode: egui_table::AutoSizeMode::default(), + animated: true, + scroll_bar_visibility: egui::scroll_area::ScrollBarVisibility::VisibleWhenNeeded, top_row_height: 24.0, row_height: 18.0, is_row_expanded: Default::default(), @@ -252,6 +256,26 @@ impl TableDemo { ); }); ui.end_row(); + + ui.label("Scroll bar visibility"); + ui.horizontal(|ui| { + ui.radio_value( + &mut self.scroll_bar_visibility, + egui::scroll_area::ScrollBarVisibility::AlwaysHidden, + "AlwaysHidden", + ); + ui.radio_value( + &mut self.scroll_bar_visibility, + egui::scroll_area::ScrollBarVisibility::AlwaysVisible, + "AlwaysVisible", + ); + ui.radio_value( + &mut self.scroll_bar_visibility, + egui::scroll_area::ScrollBarVisibility::VisibleWhenNeeded, + "VisibleWhenNeeded", + ); + }); + ui.end_row(); }); let id_salt = Id::new("table_demo"); @@ -317,6 +341,8 @@ impl TableDemo { } }); + ui.horizontal(|ui| ui.checkbox(&mut self.animated, "Animate scrolls")); + ui.separator(); let mut table = egui_table::Table::new() @@ -331,7 +357,9 @@ impl TableDemo { }, egui_table::HeaderRow::new(self.top_row_height), ]) - .auto_size_mode(self.auto_size_mode); + .auto_size_mode(self.auto_size_mode) + .animated(self.animated) + .scroll_bar_visibility(self.scroll_bar_visibility); if let Some(scroll_to_column) = scroll_to_column { table = table.scroll_to_column(scroll_to_column, None); diff --git a/egui_table/src/split_scroll.rs b/egui_table/src/split_scroll.rs index a474ea6..1639c5d 100644 --- a/egui_table/src/split_scroll.rs +++ b/egui_table/src/split_scroll.rs @@ -1,4 +1,4 @@ -use egui::{pos2, vec2, Rect, Ui, UiBuilder, Vec2, Vec2b}; +use egui::{pos2, scroll_area::ScrollBarVisibility, vec2, Rect, Ui, UiBuilder, Vec2, Vec2b}; /// A scroll area with some portion of its left and/or top side "stuck". /// /// This produces four quadrants: @@ -27,6 +27,17 @@ use egui::{pos2, vec2, Rect, Ui, UiBuilder, Vec2, Vec2b}; pub struct SplitScroll { pub scroll_enabled: Vec2b, + /// Should the scroll area animate `scroll_to_*` functions? + pub animated: bool, + + /// Can the user drag the scroll area to scroll? + /// + /// This is useful for touch screens. + pub drag_to_scroll: bool, + + /// Set the visibility of both horizontal and vertical scroll bars. + pub scroll_bar_visibility: ScrollBarVisibility, + /// Width of the fixed left side, and height of the fixed top. pub fixed_size: Vec2, @@ -61,6 +72,9 @@ impl SplitScroll { pub fn show(self, ui: &mut Ui, delegate: &mut dyn SplitScrollDelegate) { let Self { scroll_enabled, + animated, + drag_to_scroll, + scroll_bar_visibility, fixed_size, scroll_outer_size, scroll_content_size, @@ -85,6 +99,9 @@ impl SplitScroll { let mut scroll_ui = ui.new_child(UiBuilder::new().max_rect(rect)); egui::ScrollArea::new(scroll_enabled) + .animated(animated) + .drag_to_scroll(drag_to_scroll) + .scroll_bar_visibility(scroll_bar_visibility) .auto_shrink(false) .scroll_bar_rect(bottom_right_rect) .show_viewport(&mut scroll_ui, |ui, scroll_offset| { diff --git a/egui_table/src/table.rs b/egui_table/src/table.rs index be6edbd..930ddf9 100644 --- a/egui_table/src/table.rs +++ b/egui_table/src/table.rs @@ -4,7 +4,8 @@ use std::{ }; use egui::{ - vec2, Align, Context, Id, IdMap, NumExt as _, Rangef, Rect, Ui, UiBuilder, Vec2, Vec2b, + scroll_area::ScrollBarVisibility, vec2, Align, Context, Id, IdMap, NumExt as _, Rangef, Rect, + Ui, UiBuilder, Vec2, Vec2b, }; use vec1::Vec1; @@ -115,6 +116,17 @@ pub struct Table { /// How to do auto-sizing of columns, if at all. auto_size_mode: AutoSizeMode, + /// Should the scroll area animate `scroll_to_*` functions? + animated: bool, + + /// Can the user drag the scroll area to scroll? + /// + /// This is useful for touch screens. + drag_to_scroll: bool, + + /// Set the visibility of both horizontal and vertical scroll bars. + scroll_bar_visibility: ScrollBarVisibility, + scroll_to_columns: Option<(RangeInclusive, Option)>, scroll_to_rows: Option<(RangeInclusive, Option)>, } @@ -128,6 +140,9 @@ impl Default for Table { headers: vec![HeaderRow::new(16.0)], num_rows: 0, auto_size_mode: AutoSizeMode::default(), + animated: true, + drag_to_scroll: true, + scroll_bar_visibility: ScrollBarVisibility::default(), scroll_to_columns: None, scroll_to_rows: None, } @@ -268,6 +283,29 @@ impl Table { self } + /// Should the table animate `scroll_to_*` functions? + #[inline] + pub fn animated(mut self, animated: bool) -> Self { + self.animated = animated; + self + } + + /// Can the user drag the table to scroll? + /// + /// This is useful for touch screens. + #[inline] + pub fn drag_to_scroll(mut self, drag_to_scroll: bool) -> Self { + self.drag_to_scroll = drag_to_scroll; + self + } + + /// Set the visibility of both horizontal and vertical scroll bars. + #[inline] + pub fn scroll_bar_visibility(mut self, scroll_bar_visibility: ScrollBarVisibility) -> Self { + self.scroll_bar_visibility = scroll_bar_visibility; + self + } + /// Read the globally unique id, based on the current [`Self::id_salt`] /// and the parent id. #[inline] @@ -436,6 +474,9 @@ impl Table { SplitScroll { scroll_enabled: Vec2b::new(true, true), + animated: self.animated, + drag_to_scroll: self.drag_to_scroll, + scroll_bar_visibility: self.scroll_bar_visibility, fixed_size: sticky_size, scroll_outer_size: (ui.available_size() - sticky_size).at_least(Vec2::ZERO), scroll_content_size: Vec2::new(