Tk Source Code

View Ticket
Bounty program for improvements to Tcl and certain Tcl packages.
Ticket UUID: 270b0aedd4448fde3b7f646fb10d276267fafad1
Title: pinch to zoom toplevel
Type: RFE Version:
Submitter: nab Created on: 2019-12-03 10:06:28
Subsystem: 66. Aqua Window Operations Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2020-03-21 21:56:56
Resolution: None Closed By: nobody
    Closed on:
would this be possible for Aqua theme?

another cool thing would be to zoom toplevels using the bottom right corner. 
some toplevels that does not need to grow to display more things could benefit of zooming

User Comments: chrstphrchvz added on 2020-03-21 21:56:56:
Harald Oehlmann has created TIP 570 for supporting gesture events. It is an initial draft; others are encouraging to add to it.

chrstphrchvz added on 2020-03-15 06:16:23:

I agree that support for pinch and possibly other touch gestures would be nice, but hope that any implementation to support them will be coordinated between platforms, so that support for all platforms appears in the same release (rather than multiple releases over time) and with consistent cross-platform behavior (i.e. no need for Tk programs to handle platform differences). As pointed out there was experimental implementation for Windows (ticket [9c2f8da6]), and gestures are also usable on X11 if the XInput 2.x extension can be used: [27fc8b7820]. AndroWish also already supports gestures (using virtual events e.g. <<PinchToZoom>>).

Would it be a good idea to designate a single ticket for this feature for all platforms?

fvogel added on 2019-12-04 20:55:57:

There was a try three years ago, see branch pspjuth-touch.

marc_culler (claiming to be Marc Culler) added on 2019-12-04 20:06:21:
I think that the appropriate proposal should not be to make the pinch gesture
do any specific thing, but to treat it in the same way that other events like
scrollwheel and mouse events are treated.  Namely, it should have a name and
it should be possible to bind the event to a procedure.

I don't know how it works.  Since you can continuously zoom and unzoom with
that gesture, I assume that many events are sent, as when the mouse is moved.
I would guess that the event provides some numerical value indicating how much
closer or further apart the fingers moved since the previous event.  And maybe
events are sent for the start and end of the gesture. But this is all guesswork.

I also don't know which platforms support the gesture nor how they support it
if they do.  So lots of research and experimentation would be needed.

nab added on 2019-12-04 15:18:54:
thank you so much for your example... it indeed works great !!

now the purpose of this ticket is only the gesture part (aka pinch)

best regards,

marc_culler (claiming to be Marc Culler) added on 2019-12-04 12:28:41:
A ttk::button -style Toolbutton (which has existed for a long time) can have
arbitrary width and height.  A plain ttk::button, which is realized as a macOS
Push Button, can have arbitrary width but fixed height.  (Actually the height of
the ttk::button does increase, but the white rounded rectangle is always drawn
with the same height, vertically centered in the bounding box of the

In the mac_styles branch there is a -style GradientButton which can have
arbitrary width and height, and the same is true of -style ImageButton.

This sort of thing is a job for the programmer, and the Tk geometry managers
provide lots of tools to allow the programmer to do it easily.  Tk does not know
enough about what the programmer is trying to do for any one-size-fits-all
automated scheme to work.  Possibly there could be a magnification operation
which changes the pixel size per window.  But I think that should be handled
by the window manager, not by Tk.

bll added on 2019-12-04 08:59:32:
I should have said that works on Linux.
Just tested on Mac OS with the aqua theme.
Buttons in the aqua theme don't scale.
May need one of the new button types that marc is working on.


bll added on 2019-12-04 08:22:04:
This works:

I got lazy and just used pack for the .f frame, as grid wasn't immediately working for it.

package require Tk

proc setup { } {
  variable vars

  set vars(origw) [winfo width .]
  set vars(origh) [winfo height .]
  set vars(origf) [font metrics TkDefaultFont -ascent]
  bind . <Configure> [list resizer %W]

proc resizer { w } {
  variable vars

  if { $w ne "." } {
  set vars(w) [winfo width .]
  set vars(h) [winfo height .]
  set ratio [expr {double($vars(h))/double($vars(origh))}]
  set sz [expr {round(double($vars(origf))*$ratio)}]
  font configure TkDefaultFont -size $sz

proc main { } {
  ttk::style theme use clam

  ttk::style configure Cyan.TFrame -background cyan
  set f [ttk::frame .f -style Cyan.TFrame]
  foreach n [list 1 2 3 4] {
      ttk::button .f.b$n -text $n
  foreach n [list 0 1] {
     grid rowconfigure .f $n -weight 1
     grid columnconfigure .f $n -weight 1
  grid .f.b1 -row 0 -column 0 -sticky nsew
  grid .f.b2 -row 0 -column 1 -sticky nsew
  grid .f.b3 -row 1 -column 0 -sticky nsew
  grid .f.b4 -row 1 -column 1 -sticky nsew

  pack .f -fill both -expand 1

  bind . <Map> [list setup]


bll added on 2019-12-04 07:52:16:
The row/column configure is needed for both the frame (coded)
 and the buttons if you want both to grow.  Add

foreach n [list 0 1] {
   grid rowconfigure .f $n -weight 1
   grid columnconfigure .f $n -weight 1

nab added on 2019-12-04 04:27:20:
yes, it works,
but when wrapped in a frame, it doesn't:

set f [ttk::frame .f]
foreach n [list 1 2 3 4] {
    ttk::button .f.b$n -style Toolbutton -text $n
foreach n [list 0 1] {
   grid rowconfigure . $n -weight 1
   grid columnconfigure . $n -weight 1
grid .f.b1 -row 0 -column 0 -sticky nsew
grid .f.b2 -row 0 -column 1 -sticky nsew
grid .f.b3 -row 1 -column 0 -sticky nsew
grid .f.b4 -row 1 -column 1 -sticky nsew
grid .f -sticky nsew -rowspan 2 -columnspan 2

in that case, if zooming were handle by the OS it would be easy.


marc_culler (claiming to be Marc Culler) added on 2019-12-04 01:45:43:
Doesn't that already happen if you configure the rows and columns of the
grid to have -weight 1 and make the buttons -sticky nsew ?

This worked for me:

foreach n [list 1 2 3 4] {
    ttk::button .b$n -style Toolbutton -text $n
foreach n [list 0 1] {
   grid rowconfigure . $n -weight 1
   grid columnconfigure . $n -weight 1
grid .b1 -row 0 -column 0 -sticky nsew
grid .b2 -row 0 -column 1 -sticky nsew
grid .b3 -row 1 -column 0 -sticky nsew
grid .b4 -row 1 -column 1 -sticky nsew

nab added on 2019-12-03 17:29:53:
here's what I mean by zoom.
let's say a toplevel filled with a grid of button, when user click on the bottom right corner of the toplevel and move, toplevel become bigger and I would like the grid of button and button themselves to be bigger.


marc_culler (claiming to be Marc Culler) added on 2019-12-03 17:19:00:
I don't know what you mean by "zoom".  Usually a pinch gesture changes a
magnification factor.  I am not aware that Tk has such a thing.  There are
NSEvents that get posted for gestures, however.