diff --git a/crates/egui/src/containers/scroll_area.rs b/crates/egui/src/containers/scroll_area.rs index 6fd5b1dd52a4..7518009812b9 100644 --- a/crates/egui/src/containers/scroll_area.rs +++ b/crates/egui/src/containers/scroll_area.rs @@ -777,17 +777,33 @@ impl Prepared { let max_offset = content_size - inner_rect.size(); let is_hovering_outer_rect = ui.rect_contains_pointer(outer_rect); if scrolling_enabled && is_hovering_outer_rect { + let always_scroll_enabled_direction = ui.style().always_scroll_the_only_direction + && scroll_enabled[0] != scroll_enabled[1]; for d in 0..2 { if scroll_enabled[d] { - let scroll_delta = ui.ctx().frame_state(|fs| fs.scroll_delta); + let scroll_delta = ui.ctx().frame_state(|fs| { + if always_scroll_enabled_direction { + // no bidirectional scrolling; allow horizontal scrolling without pressing shift + fs.scroll_delta[0] + fs.scroll_delta[1] + } else { + fs.scroll_delta[d] + } + }); - let scrolling_up = state.offset[d] > 0.0 && scroll_delta[d] > 0.0; - let scrolling_down = state.offset[d] < max_offset[d] && scroll_delta[d] < 0.0; + let scrolling_up = state.offset[d] > 0.0 && scroll_delta > 0.0; + let scrolling_down = state.offset[d] < max_offset[d] && scroll_delta < 0.0; if scrolling_up || scrolling_down { - state.offset[d] -= scroll_delta[d]; + state.offset[d] -= scroll_delta; // Clear scroll delta so no parent scroll will use it. - ui.ctx().frame_state_mut(|fs| fs.scroll_delta[d] = 0.0); + ui.ctx().frame_state_mut(|fs| { + if always_scroll_enabled_direction { + fs.scroll_delta[0] = 0.0; + fs.scroll_delta[1] = 0.0; + } else { + fs.scroll_delta[d] = 0.0; + } + }); state.scroll_stuck_to_end[d] = false; } } diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index fb03bcfd805a..9bb29ab566a5 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -212,6 +212,9 @@ pub struct Style { /// /// This only affects a few egui widgets. pub explanation_tooltips: bool, + + /// If true and scrolling is enabled for only one direction, allow horizontal scrolling without pressing shift + pub always_scroll_the_only_direction: bool, } impl Style { @@ -1070,6 +1073,7 @@ impl Default for Style { #[cfg(debug_assertions)] debug: Default::default(), explanation_tooltips: false, + always_scroll_the_only_direction: false, } } } @@ -1323,6 +1327,7 @@ impl Style { #[cfg(debug_assertions)] debug, explanation_tooltips, + always_scroll_the_only_direction, } = self; visuals.light_dark_radio_buttons(ui); @@ -1392,6 +1397,11 @@ impl Style { "Show explanatory text when hovering DragValue:s and other egui widgets", ); + ui.checkbox(always_scroll_the_only_direction, "Always scroll the only enabled direction") + .on_hover_text( + "If scrolling is enabled for only one direction, allow horizontal scrolling without pressing shift", + ); + ui.vertical_centered(|ui| reset_button(ui, self)); } }