From d72326e2c7dfda17f989a465004d7b94266747b0 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 12 Dec 2023 15:55:03 +0000 Subject: [PATCH] (cherry-pick): Made the scrolling by units via smoother. --- library/listbox.tcl | 2 +- library/tk.tcl | 29 +++++++++++++++-------------- library/ttk/combobox.tcl | 2 +- library/ttk/notebook.tcl | 2 +- library/ttk/spinbox.tcl | 2 +- library/ttk/utils.tcl | 2 +- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/library/listbox.tcl b/library/listbox.tcl index 3beeaa441..d6118011d 100644 --- a/library/listbox.tcl +++ b/library/listbox.tcl @@ -188,7 +188,7 @@ bind Listbox { tk::MouseWheel %W x %D -12.0 units } bind Listbox { - 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 12e02325f..6c37a2bd9 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 <> 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 c253eb077..1b9d4cbdc 100644 --- a/library/ttk/combobox.tcl +++ b/library/ttk/combobox.tcl @@ -59,7 +59,7 @@ bind TCombobox { bind TCombobox { 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 55aaa0316..1d59d1e38 100644 --- a/library/ttk/notebook.tcl +++ b/library/ttk/notebook.tcl @@ -33,7 +33,7 @@ bind TNotebook { } bind TNotebook { # 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 0160d35ea..96d8acfe3 100644 --- a/library/ttk/spinbox.tcl +++ b/library/ttk/spinbox.tcl @@ -30,7 +30,7 @@ bind TSpinbox { bind TSpinbox { 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 9b15eb62d..3f6446dc1 100644 --- a/library/ttk/utils.tcl +++ b/library/ttk/utils.tcl @@ -304,7 +304,7 @@ bind TtkScrollable \ ## Touchpad scrolling # bind TtkScrollable { - if {[expr {%# %% 15}] != 0} { + if {%# %% 5 != 0} { return } lassign [tk::PreciseScrollDeltas %D] deltaX deltaY