diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-09-24 21:40:07 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-09-24 21:40:07 (GMT) |
commit | 202e2b4510669128db1f8fc72b094456d5bef5d4 (patch) | |
tree | f14fef2a143fc452c5218b8fa9a571d4d060fe03 /library | |
parent | 1b4e22424f79b1e910cd4acb0352fd4ec8badbec (diff) | |
parent | c565a681f168cebaa8baa802a1e4db8768930a19 (diff) | |
download | tk-202e2b4510669128db1f8fc72b094456d5bef5d4.zip tk-202e2b4510669128db1f8fc72b094456d5bef5d4.tar.gz tk-202e2b4510669128db1f8fc72b094456d5bef5d4.tar.bz2 |
When using bindings for x|yview scroll ??? units, make sure that rounding up and down is done equally, moving away from zero.
This was already done for text widget, now it's done for all other bindings on Windows too.
Diffstat (limited to 'library')
-rw-r--r-- | library/demos/cscroll.tcl | 18 | ||||
-rw-r--r-- | library/iconlist.tcl | 6 | ||||
-rw-r--r-- | library/listbox.tcl | 18 | ||||
-rw-r--r-- | library/scrlbar.tcl | 18 | ||||
-rw-r--r-- | library/ttk/utils.tcl | 54 |
5 files changed, 95 insertions, 19 deletions
diff --git a/library/demos/cscroll.tcl b/library/demos/cscroll.tcl index 570a35b..efae5c7 100644 --- a/library/demos/cscroll.tcl +++ b/library/demos/cscroll.tcl @@ -72,11 +72,25 @@ if {[tk windowingsystem] eq "aqua"} { %W xview scroll [expr {-10 * (%D)}] units } } else { + # We must make sure that positive and negative movements are rounded + # equally to integers, avoiding the problem that + # (int)1/30 = 0, + # but + # (int)-1/30 = -1 + # The following code ensure equal +/- behaviour. bind $c <MouseWheel> { - %W yview scroll [expr {-(%D / 30)}] units + if {%D >= 0} { + %W yview scroll [expr {-%D/30}] units + } else { + %W yview scroll [expr {(29-%D)/30}] units + } } bind $c <Shift-MouseWheel> { - %W xview scroll [expr {-(%D / 30)}] units + if {%D >= 0} { + %W xview scroll [expr {-%D/30}] units + } else { + %W xview scroll [expr {(29-%D)/30}] units + } } } diff --git a/library/iconlist.tcl b/library/iconlist.tcl index 30352a1..2095ad6 100644 --- a/library/iconlist.tcl +++ b/library/iconlist.tcl @@ -509,6 +509,12 @@ package require Tk 8.6 if {$noScroll || $::tk_strictMotif} { return } + # We must make sure that positive and negative movements are rounded + # equally to integers, avoiding the problem that + # (int)1/120 = 0, + # but + # (int)-1/120 = -1 + # The following code ensure equal +/- behaviour. if {$amount > 0} { $canvas xview scroll [expr {(-119-$amount) / 120}] units } else { diff --git a/library/listbox.tcl b/library/listbox.tcl index dc2296c..f057151 100644 --- a/library/listbox.tcl +++ b/library/listbox.tcl @@ -194,11 +194,25 @@ if {[tk windowingsystem] eq "aqua"} { %W xview scroll [expr {-10 * (%D)}] units } } else { + # We must make sure that positive and negative movements are rounded + # equally to integers, avoiding the problem that + # (int)1/30 = 0, + # but + # (int)-1/30 = -1 + # The following code ensure equal +/- behaviour. bind Listbox <MouseWheel> { - %W yview scroll [expr {-(%D/30)}] units + if {%D >= 0} { + %W yview scroll [expr {-%D/30}] units + } else { + %W yview scroll [expr {29-%D/30}] units + } } bind Listbox <Shift-MouseWheel> { - %W xview scroll [expr {-(%D/30)}] units + if {%D >= 0} { + %W xview scroll [expr {-%D/30}] units + } else { + %W xview scroll [expr {29-%D/30}] units + } } } diff --git a/library/scrlbar.tcl b/library/scrlbar.tcl index 0cbbc66..df4b8ab 100644 --- a/library/scrlbar.tcl +++ b/library/scrlbar.tcl @@ -143,11 +143,25 @@ if {[tk windowingsystem] eq "aqua"} { tk::ScrollByUnits %W h [expr {-10 * (%D)}] } } else { + # We must make sure that positive and negative movements are rounded + # equally to integers, avoiding the problem that + # (int)1/30 = 0, + # but + # (int)-1/30 = -1 + # The following code ensure equal +/- behaviour. bind Scrollbar <MouseWheel> { - tk::ScrollByUnits %W v [expr {-(%D / 30)}] + if {%D >= 0} { + tk::ScrollByUnits %W v [expr {-%D/30}] + } else { + tk::ScrollByUnits %W v [expr {(29-%D)/30}] + } } bind Scrollbar <Shift-MouseWheel> { - tk::ScrollByUnits %W h [expr {-(%D / 30)}] + if {%D >= 0} { + tk::ScrollByUnits %W h [expr {-%D/30}] + } else { + tk::ScrollByUnits %W h [expr {(29-%D)/30}] + } } } diff --git a/library/ttk/utils.tcl b/library/ttk/utils.tcl index 857f4cd..05f0a0c 100644 --- a/library/ttk/utils.tcl +++ b/library/ttk/utils.tcl @@ -308,7 +308,15 @@ proc ttk::bindMouseWheel {bindtag callback} { bind $bindtag <MouseWheel> [append callback { [expr {-(%D)}]} ] bind $bindtag <Option-MouseWheel> [append callback { [expr {-10 *(%D)}]} ] } else { - bind $bindtag <MouseWheel> [append callback { [expr {-(%D / 120)}]}] + # We must make sure that positive and negative movements are rounded + # equally to integers, avoiding the problem that + # (int)1/120 = 0, + # but + # (int)-1/120 = -1 + # The following code ensure equal +/- behaviour. + bind $bindtag <MouseWheel> [append callback { [ + expr {%D>=0 ? (-%D/120) : ((119-%D)/120)} + ]}] } } @@ -327,19 +335,39 @@ if {[tk windowingsystem] eq "x11"} { bind TtkScrollable <Shift-ButtonPress-5> { %W xview scroll 5 units } } if {[tk windowingsystem] eq "aqua"} { - bind TtkScrollable <MouseWheel> \ - { %W yview scroll [expr {-(%D)}] units } - bind TtkScrollable <Shift-MouseWheel> \ - { %W xview scroll [expr {-(%D)}] units } - bind TtkScrollable <Option-MouseWheel> \ - { %W yview scroll [expr {-10 * (%D)}] units } - bind TtkScrollable <Shift-Option-MouseWheel> \ - { %W xview scroll [expr {-10 * (%D)}] units } + bind TtkScrollable <MouseWheel> { + %W yview scroll [expr {-(%D)}] units + } + bind TtkScrollable <Shift-MouseWheel> { + %W xview scroll [expr {-(%D)}] units + } + bind TtkScrollable <Option-MouseWheel> { + %W yview scroll [expr {-10 * (%D)}] units + } + bind TtkScrollable <Shift-Option-MouseWheel> { + %W xview scroll [expr {-10 * (%D)}] units + } } else { - bind TtkScrollable <MouseWheel> \ - { %W yview scroll [expr {-(%D / 120)}] units } - bind TtkScrollable <Shift-MouseWheel> \ - { %W xview scroll [expr {-(%D / 120)}] units } + # We must make sure that positive and negative movements are rounded + # equally to integers, avoiding the problem that + # (int)1/120 = 0, + # but + # (int)-1/120 = -1 + # The following code ensure equal +/- behaviour. + bind TtkScrollable <MouseWheel> { + if {%D >= 0} { + %W yview scroll [expr {-%D/120}] units + } else { + %W yview scroll [expr {(119-%D)/120}] units + } + } + bind TtkScrollable <Shift-MouseWheel> { + if {%D >= 0} { + %W xview scroll [expr {-%D/120}] units + } else { + %W xview scroll [expr {(119-%D)/120}] units + } + } } #*EOF* |