@@ -55,6 +55,27 @@ impl PreferencesDialogMessageHandler {
55
55
TextLabel :: new( "Zoom with Scroll" ) . table_align( true ) . tooltip( zoom_with_scroll_tooltip) . widget_holder( ) ,
56
56
] ;
57
57
58
+ let zoom_rate_tooltip = "Adjust how fast zooming occurs when using the scroll wheel" ;
59
+ let zoom_rate = vec ! [
60
+ Separator :: new( SeparatorType :: Unrelated ) . widget_holder( ) ,
61
+ TextLabel :: new( "Zoom Rate: " ) . table_align( true ) . tooltip( zoom_rate_tooltip) . widget_holder( ) ,
62
+ Separator :: new( SeparatorType :: Related ) . widget_holder( ) ,
63
+ NumberInput :: new( Some ( map_zoom_rate_to_display( preferences. viewport_zoom_wheel_rate) ) )
64
+ . tooltip( zoom_rate_tooltip)
65
+ . min( 1.0 )
66
+ . max( 100.0 )
67
+ . display_decimal_places( 0 ) // Display as whole numbers
68
+ . on_update( |number_input: & NumberInput | {
69
+ if let Some ( display_value) = number_input. value {
70
+ let actual_rate = map_display_to_zoom_rate( display_value) ;
71
+ PreferencesMessage :: ViewportZoomWheelRate { rate: actual_rate } . into( )
72
+ } else {
73
+ PreferencesMessage :: ViewportZoomWheelRate { rate: ( 1. / 600. ) * 3. } . into( )
74
+ }
75
+ } )
76
+ . widget_holder( ) ,
77
+ ] ;
78
+
58
79
// =======
59
80
// EDITING
60
81
// =======
@@ -184,6 +205,7 @@ impl PreferencesDialogMessageHandler {
184
205
185
206
Layout :: WidgetLayout ( WidgetLayout :: new ( vec ! [
186
207
LayoutGroup :: Row { widgets: navigation_header } ,
208
+ LayoutGroup :: Row { widgets: zoom_rate } ,
187
209
LayoutGroup :: Row { widgets: zoom_with_scroll } ,
188
210
LayoutGroup :: Row { widgets: editing_header } ,
189
211
LayoutGroup :: Row { widgets: selection_label } ,
@@ -250,3 +272,41 @@ impl PreferencesDialogMessageHandler {
250
272
} ) ;
251
273
}
252
274
}
275
+ // Map the actual rate value to display value (1-100)
276
+ fn map_zoom_rate_to_display ( rate : f64 ) -> f64 {
277
+ let value = if rate <= 0.0001 {
278
+ 1.0
279
+ } else if rate >= 0.05 {
280
+ 100.0
281
+ } else {
282
+ // Calculate the logarithmic position between 0.0001 and 0.05
283
+ let log_min = 0.0001_f64 . ln ( ) ;
284
+ let log_max = 0.05_f64 . ln ( ) ;
285
+ let log_val = rate. ln ( ) ;
286
+
287
+ // Map to 1-100 range
288
+ let normalized = ( log_val - log_min) / ( log_max - log_min) ;
289
+ 1.0 + 99.0 * normalized
290
+ } ;
291
+
292
+ value. round ( )
293
+ }
294
+
295
+ // Map the display value (1-100) back to the actual rate value
296
+ fn map_display_to_zoom_rate ( display : f64 ) -> f64 {
297
+ if display <= 1.0 {
298
+ 0.0001
299
+ } else if display >= 100.0 {
300
+ 0.05
301
+ } else {
302
+ // Normalize to 0-1 range
303
+ let normalized = ( display - 1.0 ) / 99.0 ;
304
+
305
+ let log_min = 0.0001_f64 . ln ( ) ;
306
+ let log_max = 0.05_f64 . ln ( ) ;
307
+ let log_val = log_min + normalized * ( log_max - log_min) ;
308
+
309
+ // Convert back to actual value
310
+ log_val. exp ( )
311
+ }
312
+ }
0 commit comments