@@ -5,8 +5,6 @@ use egui::{Key, Modifiers, PointerButton, Vec2b};
55/// A reset operation.
66#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
77pub enum ResetBehavior {
8- /// Reset by auto-fitting bounds to visible content.
9- AutoFit ,
108 /// Restore the original bounds from the first frame the plot was shown.
119 OriginalBounds ,
1210}
@@ -108,8 +106,7 @@ pub struct NavigationConfig {
108106 pub pinning_enabled : bool ,
109107 /// Shortcut: fit to view (e.g., `Key::F`). `None` disables shortcut.
110108 pub fit_to_view_key : Option < Key > ,
111- /// Shortcut: restore original bounds (e.g., `Key::R`). `None` disables shortcut.
112- pub restore_original_key : Option < Key > ,
109+
113110 /// Pin shortcuts.
114111 pub pin_add_key : Option < Key > ,
115112 pub pin_remove_key : Option < Key > ,
@@ -126,11 +123,11 @@ impl Default for NavigationConfig {
126123 . zoom_to_mouse ( true )
127124 . wheel_factor_exp ( 1.0 ) ,
128125 box_zoom : BoxZoomConfig :: new ( false , PointerButton :: Secondary , Modifiers :: NONE ) ,
129- reset_behavior : ResetBehavior :: AutoFit ,
126+ reset_behavior : ResetBehavior :: OriginalBounds ,
130127 double_click_reset : true ,
131128 pinning_enabled : true ,
132129 fit_to_view_key : Some ( Key :: F ) ,
133- restore_original_key : Some ( Key :: R ) ,
130+
134131 pin_add_key : Some ( Key :: P ) ,
135132 pin_remove_key : Some ( Key :: U ) ,
136133 pins_clear_key : Some ( Key :: Delete ) ,
@@ -139,7 +136,7 @@ impl Default for NavigationConfig {
139136}
140137impl NavigationConfig {
141138 #[ allow( clippy:: fn_params_excessive_bools) ]
142- /// Helper used to migrate legacy per-field flags into a `NavigationConfig`.
139+ /// Build a `NavigationConfig`.
143140 pub fn from_legacy_flags (
144141 allow_drag : Vec2b ,
145142 allow_zoom : Vec2b ,
@@ -157,68 +154,130 @@ impl NavigationConfig {
157154 . zoom_to_mouse ( true )
158155 . wheel_factor_exp ( 1.0 ) ,
159156 box_zoom : BoxZoomConfig :: new ( allow_boxed_zoom, boxed_zoom_button, Modifiers :: NONE ) ,
160- reset_behavior : ResetBehavior :: AutoFit ,
161- double_click_reset : allow_double_click_reset,
162- ..Default :: default ( )
157+
158+ ..Self :: default ( ) . reset_controls (
159+ ResetBehavior :: OriginalBounds ,
160+ allow_double_click_reset,
161+ Some ( Key :: R ) ,
162+ )
163163 }
164164 }
165165
166- /// Builders for convenience.
166+ /// Configure drag behavior for the given axes.
167+ ///
168+ /// The `axes` parameter uses `(x, y)` ordering:
169+ /// - `Some(Vec2b::new(true, true))` → drag on both X and Y
170+ /// - `Some(Vec2b::new(true, false))` → drag on X only
171+ /// - `Some(Vec2b::new(false, true))` → drag on Y only
172+ /// - `None` → dragging completely disabled
167173 #[ inline]
168- pub fn drag ( mut self , axis : Vec2b , enabled : bool ) -> Self {
169- self . drag = AxisToggle :: new ( enabled, axis) ;
174+ pub fn drag ( mut self , axes : Option < Vec2b > ) -> Self {
175+ match axes {
176+ Some ( axis) => {
177+ self . drag = AxisToggle :: new ( true , axis) ;
178+ }
179+ None => {
180+ self . drag = AxisToggle :: new ( false , Vec2b :: new ( false , false ) ) ;
181+ }
182+ }
170183 self
171184 }
172185
186+ /// Configure scrolling/panning with the mouse wheel or touchpad.
187+ ///
188+ /// Same `(x, y)` ordering as `drag`:
189+ /// - `Some(Vec2b::new(true, false))` → scroll horizontally only
190+ /// - `None` → disable scroll-based navigation
173191 #[ inline]
174- pub fn scroll ( mut self , axis : Vec2b , enabled : bool ) -> Self {
175- self . scroll = AxisToggle :: new ( enabled, axis) ;
192+ pub fn scroll ( mut self , axes : Option < Vec2b > ) -> Self {
193+ match axes {
194+ Some ( axis) => {
195+ self . scroll = AxisToggle :: new ( true , axis) ;
196+ }
197+ None => {
198+ self . scroll = AxisToggle :: new ( false , Vec2b :: new ( false , false ) ) ;
199+ }
200+ }
176201 self
177202 }
178203
204+ /// Configure zoom-drag on the axis strips.
205+ ///
206+ /// `axis` selects which axes can be zoomed by dragging on their axis strips.
179207 #[ inline]
180- pub fn axis_zoom_drag ( mut self , axis : Vec2b ) -> Self {
208+ pub fn axis_zoom ( mut self , axis : Vec2b ) -> Self {
181209 self . axis_zoom_drag = axis;
182210 self
183211 }
184212
213+ /// Set the full zoom configuration.
185214 #[ inline]
186- pub fn zoom ( mut self , cfg : ZoomConfig ) -> Self {
215+ pub fn scroll_zoom ( mut self , cfg : ZoomConfig ) -> Self {
187216 self . zoom = cfg;
188217 self
189218 }
190219
220+ /// Set the box-zoom configuration.
191221 #[ inline]
192222 pub fn box_zoom ( mut self , cfg : BoxZoomConfig ) -> Self {
193223 self . box_zoom = cfg;
194224 self
195225 }
196226
227+ /// Configure all reset-related controls in a single place.
228+ ///
229+ /// `behavior` defines how reset behaves, `double_click` toggles double-click
230+ /// reset, and `fit_key` / `restore_key` configure keyboard shortcuts.
197231 #[ inline]
198- pub fn reset_behavior ( mut self , behavior : ResetBehavior ) -> Self {
232+ pub fn reset_controls (
233+ mut self ,
234+ behavior : ResetBehavior ,
235+ double_click : bool ,
236+ fit_key : Option < Key > ,
237+ ) -> Self {
199238 self . reset_behavior = behavior;
239+ self . double_click_reset = double_click;
240+ self . fit_to_view_key = fit_key;
241+
200242 self
201243 }
202244
245+ /// Set the reset behavior
246+ ///
247+ /// This keeps other reset-related fields (double click, shortcuts) unchanged.
203248 #[ inline]
204- pub fn double_click_reset ( mut self , on : bool ) -> Self {
205- self . double_click_reset = on;
206- self
249+ pub fn reset_behavior ( self , behavior : ResetBehavior ) -> Self {
250+ self . reset_controls ( behavior, self . double_click_reset , self . fit_to_view_key )
207251 }
208252
253+ /// Enable or disable double-click reset.
254+ ///
255+ /// This keeps the reset behavior and shortcuts unchanged.
209256 #[ inline]
210- pub fn pinning ( mut self , on : bool ) -> Self {
211- self . pinning_enabled = on;
212- self
257+ pub fn double_click_reset ( self , on : bool ) -> Self {
258+ self . reset_controls ( self . reset_behavior , on, self . fit_to_view_key )
259+ }
260+
261+ /// Configure keyboard shortcuts for "fit to view" and "restore original".
262+ ///
263+ /// Pass `None` to disable a shortcut.
264+ #[ inline]
265+ pub fn shortcuts_fit_restore ( self , fit : Option < Key > ) -> Self {
266+ self . reset_controls ( self . reset_behavior , self . double_click_reset , fit)
213267 }
214268
269+ /// Enable or disable pinning (tooltip pin add/remove/clear).
270+ ///
271+ /// This affects keyboard shortcuts for pins and any pin-related UI.
215272 #[ inline]
216- pub fn shortcuts_fit_restore ( mut self , fit : Option < Key > , restore : Option < Key > ) -> Self {
217- self . fit_to_view_key = fit;
218- self . restore_original_key = restore;
273+ pub fn pinning ( mut self , on : bool ) -> Self {
274+ self . pinning_enabled = on;
219275 self
220276 }
221277
278+ /// Configure keyboard shortcuts for pin management.
279+ ///
280+ /// `add`, `remove`, and `clear` control pin creation and deletion.
222281 #[ inline]
223282 pub fn shortcuts_pin (
224283 mut self ,
0 commit comments