summaryrefslogtreecommitdiffstats
path: root/library/tk.tcl
diff options
context:
space:
mode:
authormarc_culler <marc.culler@gmail.com>2023-11-23 20:25:06 (GMT)
committermarc_culler <marc.culler@gmail.com>2023-11-23 20:25:06 (GMT)
commit014459077ba67c7477c4392ceb0f3525311b79d8 (patch)
tree94735c29e8fb7fb6364d70205e2b03d6f75a25f8 /library/tk.tcl
parent35f3b55d406eb50ce5da2d70ff50cba959f1f139 (diff)
downloadtk-014459077ba67c7477c4392ceb0f3525311b79d8.zip
tk-014459077ba67c7477c4392ceb0f3525311b79d8.tar.gz
tk-014459077ba67c7477c4392ceb0f3525311b79d8.tar.bz2
Support smooth scrolling of Canvas widgets and demonstrate it in the simple scrollable canvas demo.
Diffstat (limited to 'library/tk.tcl')
-rw-r--r--library/tk.tcl13
1 files changed, 13 insertions, 0 deletions
diff --git a/library/tk.tcl b/library/tk.tcl
index 0bb49eb..1345fbf 100644
--- a/library/tk.tcl
+++ b/library/tk.tcl
@@ -844,6 +844,19 @@ if {[tk windowingsystem] eq "x11"} {
if {$::ttk::library ne ""} {
uplevel \#0 [list source -encoding utf-8 $::ttk::library/ttk.tcl]
}
+
+# Helper for smooth scrolling of Canvas widgets
+proc ::tk::CanvasScrollByPixels {canvas deltaX deltaY} {
+ set width [expr {1.0 * [$canvas cget -width]}]
+ set height [expr {1.0 * [$canvas cget -height]}]
+ set X [lindex [$canvas xview] 0]
+ set Y [lindex [$canvas yview] 0]
+ set x [expr {$X - $deltaX / $width}]
+ set y [expr {$Y - $deltaY / $height}]
+ $canvas xview moveto $x
+ $canvas yview moveto $y
+}
+
# Local Variables:
# mode: tcl