diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-12-12 15:55:03 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-12-12 15:55:03 (GMT) |
commit | d72326e2c7dfda17f989a465004d7b94266747b0 (patch) | |
tree | 680608e6a3f2731a66799fb67b6dc2ae50f2a3f9 | |
parent | 8587ab4815ee46a0bd52b89ac7200899fe484348 (diff) | |
download | tk-d72326e2c7dfda17f989a465004d7b94266747b0.zip tk-d72326e2c7dfda17f989a465004d7b94266747b0.tar.gz tk-d72326e2c7dfda17f989a465004d7b94266747b0.tar.bz2 |
(cherry-pick): Made the scrolling by units via <TouchpadScroll> smoother.
-rw-r--r-- | library/listbox.tcl | 2 | ||||
-rw-r--r-- | library/tk.tcl | 29 | ||||
-rw-r--r-- | library/ttk/combobox.tcl | 2 | ||||
-rw-r--r-- | library/ttk/notebook.tcl | 2 | ||||
-rw-r--r-- | library/ttk/spinbox.tcl | 2 | ||||
-rw-r--r-- | library/ttk/utils.tcl | 2 |
6 files changed, 20 insertions, 19 deletions
diff --git a/library/listbox.tcl b/library/listbox.tcl index 3beeaa4..d611801 100644 --- a/library/listbox.tcl +++ b/library/listbox.tcl @@ -188,7 +188,7 @@ bind Listbox <Shift-Option-MouseWheel> { tk::MouseWheel %W x %D -12.0 units } bind Listbox <TouchpadScroll> { - if {[expr {%# %% 15}] != 0} { + if {%# %% 5 != 0} { return } lassign [tk::PreciseScrollDeltas %D] deltaX deltaY diff --git a/library/tk.tcl b/library/tk.tcl index 12e0232..6c37a2b 100644 --- a/library/tk.tcl +++ b/library/tk.tcl @@ -550,6 +550,7 @@ proc ::tk::MouseWheel {w dir amount {factor -120.0} {units units}} { } ## ::tk::PreciseScrollDeltas $dxdy + proc ::tk::PreciseScrollDeltas {dxdy} { set deltaX [expr {$dxdy >> 16}] set low [expr {$dxdy & 0xffff}] @@ -557,6 +558,20 @@ proc ::tk::PreciseScrollDeltas {dxdy} { return [list $deltaX $deltaY] } +# Helper for smooth scrolling of widgets that support xview moveto, +# yview moveto, height and width. + +proc ::tk::ScrollByPixels {w deltaX deltaY} { + set width [expr {1.0 * [$w cget -width]}] + set height [expr {1.0 * [$w cget -height]}] + set X [lindex [$w xview] 0] + set Y [lindex [$w yview] 0] + set x [expr {$X - $deltaX / $width}] + set y [expr {$Y - $deltaY / $height}] + $w xview moveto $x + $w yview moveto $y +} + # ::tk::TabToWindow -- # This procedure moves the focus to the given widget. # It sends a <<TraverseOut>> virtual event to the previous focus window, @@ -845,20 +860,6 @@ if {$::ttk::library ne ""} { uplevel \#0 [list source -encoding utf-8 $::ttk::library/ttk.tcl] } -# Helper for smooth scrolling of widgets that support xview moveto, -# yview moveto, height and width. - -proc ::tk::ScrollByPixels {w deltaX deltaY} { - set width [expr {1.0 * [$w cget -width]}] - set height [expr {1.0 * [$w cget -height]}] - set X [lindex [$w xview] 0] - set Y [lindex [$w yview] 0] - set x [expr {$X - $deltaX / $width}] - set y [expr {$Y - $deltaY / $height}] - $w xview moveto $x - $w yview moveto $y -} - # Local Variables: # mode: tcl diff --git a/library/ttk/combobox.tcl b/library/ttk/combobox.tcl index c253eb0..1b9d4cb 100644 --- a/library/ttk/combobox.tcl +++ b/library/ttk/combobox.tcl @@ -59,7 +59,7 @@ bind TCombobox <Shift-MouseWheel> { bind TCombobox <TouchpadScroll> { lassign [tk::PreciseScrollDeltas %D] deltaX deltaY # TouchpadScroll events fire about 60 times per second. - if {$deltaY != 0 && [expr {%# %% 15}] == 0} { + if {$deltaY != 0 && %# %% 15 == 0} { ttk::combobox::Scroll %W [expr {$deltaY > 0 ? -1 : 1}] } } diff --git a/library/ttk/notebook.tcl b/library/ttk/notebook.tcl index 55aaa03..1d59d1e 100644 --- a/library/ttk/notebook.tcl +++ b/library/ttk/notebook.tcl @@ -33,7 +33,7 @@ bind TNotebook <Shift-Option-MouseWheel> { } bind TNotebook <TouchpadScroll> { # TouchpadScroll events fire about 60 times per second. - if {[expr {%# %% 30}] == 0} { + if {%# %% 15 == 0} { ttk::notebook::CondCycleTab2 %W %D } } diff --git a/library/ttk/spinbox.tcl b/library/ttk/spinbox.tcl index 0160d35..96d8acf 100644 --- a/library/ttk/spinbox.tcl +++ b/library/ttk/spinbox.tcl @@ -30,7 +30,7 @@ bind TSpinbox <Shift-MouseWheel> { bind TSpinbox <TouchpadScroll> { lassign [tk::PreciseScrollDeltas %D] deltaX deltaY # TouchpadScroll events fire about 60 times per second. - if {$deltaY != 0 && [expr {%# %% 12}] == 0} { + if {$deltaY != 0 && %# %% 12 == 0} { ttk::spinbox::Spin %W [expr {$deltaY > 0 ? -1 : 1}] } } diff --git a/library/ttk/utils.tcl b/library/ttk/utils.tcl index 9b15eb6..3f6446d 100644 --- a/library/ttk/utils.tcl +++ b/library/ttk/utils.tcl @@ -304,7 +304,7 @@ bind TtkScrollable <Shift-Option-MouseWheel> \ ## Touchpad scrolling # bind TtkScrollable <TouchpadScroll> { - if {[expr {%# %% 15}] != 0} { + if {%# %% 5 != 0} { return } lassign [tk::PreciseScrollDeltas %D] deltaX deltaY |