#2889 Image and font problems on Tk Cocoa Buttons

obsolete: 8.6b1.1
closed
Kevin Walzer
5
2014-08-20
2011-03-22
Adrian Robert
No

Last-CVS Tk.

Image button displays the image off-center and if border width 0 will obscure one pixel around the image.
Text buttons, if the font is set, seem to be setting their size based on the point size rather than querying the font's metrics.
These problems are specific to Tk Cocoa and do not occur under Tk Carbon.
The following script reproduces, and the attached zip contains the image and screenshots of the results.

#!/usr/bin/wish

# Reproduce Tk-Cocoa button issues
# Last-CVS version as of 2011-03-22

set searchButtonImg [image create photo -file "searchButton.gif"]

toplevel .l
wm title .l [expr { $tcl_platform(pointerSize) == 8 ? "Cocoa" : "Carbon" }]

frame .l.i
frame .l.t

button .l.i.b1 -image $searchButtonImg -borderwidth 0
button .l.i.b2 -image $searchButtonImg -borderwidth 1

set cfont [font create -family 华文楷体 -size 24]
set tfont [font create -family Courier -size 24]
button .l.t.b1 -font $cfont -text "华文楷体"
button .l.t.b2 -font $tfont -text "Courier"

pack .l.i.b1 -padx 10
pack .l.i.b2 -padx 10

pack .l.t.b1 -padx 10
pack .l.t.b2 -padx 10

pack .l.i -pady 10
pack .l.t -pady 10

Discussion

  • Adrian Robert
    Adrian Robert
    2011-03-22

    image and script to reproduce, plus results

     
    Attachments
  • Kevin Walzer
    Kevin Walzer
    2011-06-23

    I can see the differences in rendering, but I am not persuaded this is a bug. The layout of the text in the Cocoa version is better than the Carbon, where (for some reason) the button is rendered as a flat toolbutton rather than a rounded pushbutton. (Some quirk in how Carbon renders button geometry.) As for the image, I see that the included image is slightly off-center, but I am not able to reproduce the issue with other, random images--they appear to render just fine and with correct centering. As a result, I do not see anything that can be done here. If you find otherwise, patches are welcome.

     
  • Kevin Walzer
    Kevin Walzer
    2011-06-23

    • assigned_to: das --> wordtech
     
  • Adrian Robert
    Adrian Robert
    2011-07-26

    Could you post an example of an image that gets centered correctly in Cocoa? At the very least, it might help me learn how to work around the issue.

    As for the text, the Cocoa version is rendering the button edges overlapping the text in some cases. This is a bug. I don't know if the solution is simply to add padding, or if the metrics determination is off, or if Cocoa needs to take the Carbon approach and use a different button shape for larger fonts.

     
  • Kevin Walzer
    Kevin Walzer
    2011-07-26

    See attached file. Looks fine to me. code: button .b -text Foo -image foo -compound top; pack .b

     
  • Adrian Robert
    Adrian Robert
    2011-07-26

    No attachment added?

     
  • Kevin Walzer
    Kevin Walzer
    2011-07-26

     
    Attachments
  • Kevin Walzer
    Kevin Walzer
    2011-07-26

    Whoops, thought the upload went through before. It's there now.

     
  • Adrian Robert
    Adrian Robert
    2012-01-26

    fix the problem for text buttons

     
  • Adrian Robert
    Adrian Robert
    2012-01-26

    Attached a patch for the text cutoff issue. Autoselects a different, non-fixed-height bezel style if text is too tall. (The API used in the Carbon version must have done this internally.)

     
  • Kevin Walzer
    Kevin Walzer
    2012-01-29

    • status: open --> closed