Tk Source Code

View Ticket
Login
Ticket UUID: 6178610b1b20e0554854f60128576d9530e7de5a
Title: Ttk uses TK_OPTION_NULL_OK in -justify/-anchor, which is not supported
Type: Bug Version: 8.6
Submitter: jan.nijtmans Created on: 2021-12-17 09:33:35
Subsystem: 88. Themed Tk Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2021-12-20 08:57:16
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2021-12-20 08:57:16
Description:

Example

$ wish8.6
% ttk::label .l -text ttk::label
.l
% pack .l
% .l configure -justify
-justify justify Justify {} {}
% .l configure -anchor
-anchor anchor Anchor {} {}
% .l configure -justify {}
ambiguous justification "": must be left, right, or center
% .l configure -anchor {}
ambiguous anchor "": must be n, ne, e, se, s, sw, w, nw, or center

So, the defaults for -justify and -anchor are {}, but you cannot even configure the option back to be {} after you set it to another value.

The reason for this is here. The options TK_OPTION_ANCHOR/TK_OPTION_JUSTIFY don't support the flag TK_OPTION_NULL_OK.

After the suggested fix:

$ wish8.6
% ttk::label .l -text ttk::label
.l
% pack .l
% .l configure -justify
-justify justify Justify left left
% .l configure -anchor 
-anchor anchor Anchor center center
% .l configure -justify {}
ambiguous justification "": must be left, right, or center
% .l configure -anchor {}
ambiguous anchor "": must be n, ne, e, se, s, sw, w, nw, or center

The same problem is present in ttkSquare.c and ttkTreeview.c.

This bug was found as part of a follow-up investigation to [be8f5b9fc2]. The proposed solution is the same: no longer use the TK_OPTION_NULL_OK flag, but make sure that the value is initialized properly.

User Comments: jan.nijtmans added on 2021-12-20 08:40:18:

Thank you François! Changed default to "w" now.

> Don't we have the same issue with TK_OPTION_ANCHOR not supporting TK_CONFIG_NULL_OK in test cases as well? There is still such an occurrence in tkTest.c:630.

Yes, we have, but I wanted to handle that separately. In 8.7 I would like to implement TK_CONFIG_NULL_OK (as part of TIP #613), then those tests are still useful there. But they - indeed - could be cleaned-up in 8.6. Not high prio.


fvogel added on 2021-12-18 14:37:24:

One thing I wanted to add.

I agree with the change [f4ac30a0] removing TK_CONFIG_NULL_OK from TK_OPTION_JUSTIFY options in test cases.

Don't we have the same issue with TK_OPTION_ANCHOR not supporting TK_CONFIG_NULL_OK in test cases as well? There is still such an occurrence in tkTest.c:630.


fvogel added on 2021-12-18 14:30:20:

Your fix seems correct to me, Jan. Well, almost.

1. Ttk labels

Let's test! Before the fix, when creating a label without specifying -justify and -anchor (that is they are {}) the label is rendered left-justified and anchored west (*not center*). Example:

package require Tk
ttk::label .l -text label\nanotherline -background yellow
pack .l -expand true -fill both

Now try:

.l configure -justify center  ; # now justified center --> default really was "left"

and:

.l configure -anchor e ; # now anchored east --> default really was "w", not "center"
.l configure -anchor center

So your proposed fix actually changes the default for -anchor. It should be "west", not "center" for labels.

2. Ttk treeview

Regarding the change for the treeview: it is actually a change in the options of tags that may be applied to treeview items. I tried the following:

package require Tk
ttk::treeview .t -columns [list "Col 1" "Col 2" "Col 3"]
set colors {red green blue yellow orange black}
for {set i 1} {$i <= 6} {incr i} {
    set val [list]
    for {set j 1} {$j <=3} {incr j} {
        lappend val "Value $j\nof item $i"
    }
    set color [lindex $colors $i-1]
    set img [image create photo $color]
    $img put $color -to 0 0 20 15
    .t insert {} end -text "Item # $i" -values $val -image $img
}
.t insert I003 end -text "Here a subitem"
pack .t -expand true -fill both
ttk::style configure Treeview -rowheight 50
# now look at the result
.t column #2 -anchor e  ; # works
# now look at the result
.t tag add tt {I003 I005}
.t tag configure tt -background yellow  ; # works
# now look at the result
.t tag configure tt -anchor e  ; # undocumented and does not seem to work

I could not make the -anchor tag option have an effect, I'm not sure it's implemented. And it's undocumented. Conclusion: your change here is fine (this tag option des not have any effect and is undocumented, therefore changing its default, if this is the case with your fix, should not be an issue!)

3. Ttk::square

This seems to be a demo widget, if I refer to square.tcl. I didn't test this.


jan.nijtmans added on 2021-12-17 15:09:50:

Proposed fix [8fca9ae5|here]. @fvogel, is it right to use "center" as default for -anchor and "left" as default for -justify???? Looking in the code, I think it is, but better be sure first....