Tk Source Code

View Ticket
Login
Ticket UUID: ce470f20fd84439a125f75f085a4bcd1f9b16a36
Title: ttk::treeview allows dragging the right edge of the rightmost heading
Type: Bug Version: 8.6
Submitter: ulfalizer Created on: 2019-04-07 10:41:25
Subsystem: 88. Themed Tk Assigned To: fvogel
Priority: 5 Medium Severity: Cosmetic
Status: Closed Last Modified: 2019-10-28 11:52:17
Resolution: Fixed Closed By: fvogel
    Closed on: 2019-10-28 11:52:17
Description:

Here's a program that illustrates the issue. Try dragging the right edge of the rightmost heading.

pack [ttk::treeview .tree -columns foo -padding 50]
.tree heading foo -text "Drag my right edge -->"
.tree insert "" end -values xxxxxxxxxxxxxxxxxxxxxxxxxx
The same issue is there with just the tree column too:
pack [ttk::treeview .tree -padding 50]
.tree heading #0 -text "Drag my right edge -->"
.tree insert "" end -text xxxxxxxxxxxxxxxxxxxxxxxxxx

User Comments: fvogel added on 2019-10-28 11:52:17:

Changes triggered by [caacf1f082] now merged into core-8-6-branch and trunk. Dragging the right edge of the rightmost heading IS possible (and now restored).

This new status doesn't however make the present ticket a won't fix: Some commits are kept and are pertinent I think. Mainly, we are still keeping the changed behavior when at least one column is stretchable (in this case there is no slack anymore). I believe it's best like this, we're mimicking Tablelist to the best of my knowledge, be it with or without stretchable columns, and with or without hidden columns, and whatever the width of the containing geometry manager window is.


fvogel added on 2019-10-27 11:12:15:

I need to reopen this ticket since I got report that the fix breaks a user application, see [caacf1f082].


fvogel added on 2019-05-26 19:13:28:
Merged to core-8-6-branch and trunk.

ulfalizer added on 2019-05-19 07:53:35:
Sorry for the hiatus. Back again!

> Could you please do a last testing round on your side?

Tried it out in my application, and it works the way I expected. Didn't spot any issues.

Thanks for the fixes!

ulfalizer added on 2019-05-09 22:18:12:
> There is still a remaining case when the widget will leak at the right outside
> of its width, but those cases are OK with me: they happen when the widget is
> resized small enough that the stretchable columns already shrank to their
> minwidths and the sum of those minwidths and the specified widths of the
> non-stretchable columns is larger than the widget width.

Seems reasonable to me.

> Could you please do a last testing round on your side?

Will do a bit later. Thanks!

Didn't disappear, just been busy with stuff.

fvogel added on 2019-05-09 09:27:42:

I have corrected yet another buglet that happened when the user resized a column whereas there are non-stretchable columns at the right of the dragged column separator, see [dad03527b7].

There is still a remaining case when the widget will leak at the right outside of its width, but those cases are OK with me: they happen when the widget is resized small enough that the stretchable columns already shrank to their minwidths and the sum of those minwidths and the specified widths of the non-stretchable columns is larger than the widget width.

Since I was here I have also improved a bit the documentation for the column options of the ttk::treeview, see [fc1fba61ab].

I think I'm done with this ticket, the treeview behavior is now quite better and more understandable I think, both when columns are resized and when the widget is resized, with or without stretchable columns, and with or without hidden (i.e. not listed in -displaycolumns) columns.

Could you please do a last testing round on your side?


fvogel added on 2019-05-08 12:24:27:
I have added new tests for ttk::treeview, checking for columns resizing (non-regression) and widget resizing (this one is the last added test and it already passed in core-8-6-branch).

fvogel added on 2019-05-08 10:18:31:

I have now dealt with:

>    - automatically redraw the widget when there is a change in a -stretch column option 

This was done in [f2ef1f87].

Also I have checked that this all sleeps correctly with -displaycolumns. See the following enhanced test script:

package require Tk
pack [ttk::treeview .tree -columns {bar colA colB colC foo} -padding 50]
.tree heading bar -text "-bar-"
.tree heading colA -text "-colA-"
.tree heading colB -text "-colB-"
.tree heading colC -text "-colC-"
.tree heading foo -text "Drag my right edge -->"
.tree insert "" end -values xxxxxxxxxxxxxxxxxxxxxxxxxx
pack conf .tree -expand 1 -fill x

proc nostretch {} {
foreach col [.tree cget -columns] {
    .tree column $col -stretch 0
}
.tree column #0 -stretch 0
}

proc allstretch {} {
foreach col [.tree cget -columns] {
    .tree column $col -stretch 1
}
.tree column #0 -stretch 1
}

# 1. when no column is stretchable and one of them becomes stretchable
#    the stretchable column takes the slack and the widget is redisplayed
#    automatically
nostretch
.tree column colA -width 50 ; .tree column colB -width 50 ; # slack created
.tree column colA -stretch 1  ; # no slack anymore

# 2. only some columns are visible (and in a different order than declared in -columns)
#    and a visible column becomes stretchable  --> the stretchable column expands
nostretch
.tree configure -displaycolumns {colB colA colC}
.tree column colA -width 50 ; .tree column colB -width 50
.tree column colA -stretch 1

# 3. only some columns are visible (and in a different order than declared in -columns)
#    and an invisible column becomes stretchable  --> nothing happens
nostretch
.tree configure -displaycolumns {colB colA colC}
.tree column colA -width 50 ; .tree column colB -width 50
.tree column bar -stretch 1  ; # nothing changes since no stretchable column is displayed
.tree configure -displaycolumns {bar colB colA colC} ; # a stretchable colun became visible -> no slack


fvogel added on 2019-05-04 13:29:38:

I have now implemented the behavior we discussed: when there is at least one stretchable column then there is no slack anymore at the right (slack is distributed among the stretchable columns). When no column is stretchable, then column resizing can create slack. Note that the rightmost column is not special in any respect in this changed design, and that I have therefore reverted what I originally did to prevent it from being dragged.

Could you please try the tip of the bugfix branch and report your thoughts?

On my side I played with the following script:

package require Tk
pack [ttk::treeview .tree -columns {bar colA colB colC foo} -padding 50]
.tree heading bar -text "-bar-"
.tree heading colA -text "-colA-"
.tree heading colB -text "-colB-"
.tree heading colC -text "-colC-"
.tree heading foo -text "Drag my right edge -->"
.tree insert "" end -values xxxxxxxxxxxxxxxxxxxxxxxxxx
pack conf .tree -expand 1 -fill x
# now play resizing with the mouse
.tree column foo -stretch 0
.tree column colB -stretch 0
# now play resizing with the mouse
foreach col [.tree cget -columns] {
    .tree column $col -stretch 0
}
.tree column #0 -stretch 0
# now play resizing with the mouse
foreach col [.tree cget -columns] {
    .tree column $col -stretch 1
}
.tree column #0 -stretch 1
# now play resizing with the mouse

Still to do:

- check that this all sleeps correctly with -displaycolumns
- automatically redraw the widget when there is a change in a -stretch column option
- (when no column is stretchable) should the treeview be able to expand farther than the right limit of the treeview area?


ulfalizer added on 2019-04-22 08:23:34:
> What would perhaps be expected in ttk::treeview is that when there is at
> least one stretchable column then there should be no slack at the right
> (slack should be distributed among the stretchable columns).
>
> ...
>
> What do you think?

Makes sense to me. When there is at least one stretchable column, I guess the
right-most separator could be made non-draggable as well, since dragging it
would immediately snap it back to the right edge, which might look confusing.

fvogel added on 2019-04-19 09:09:44:

I had a look at what another tree widget does: the much respected and praised tablelist. Try this:

package require Tk
package require tablelist 
tablelist::tablelist .t -columns {0 "First Column" 0 "Another column"} -background red
pack .t -fill both -expand 1 -side top
.t insert end [list "first row" "another value"]
.t insert end [list "another row" "bla bla"]

.t configure -stretch all   ; # play a bit with columns resizing

.t configure -stretch {}    ; # play a further bit

The rightmost column can be resized in any case.

I think I'll backout [fa9b6483] to make ttk::treeview closer to the behaviour of tablelist. What would perhaps be expected in ttk::treeview is that when there is at least one stretchable column then there should be no slack at the right (slack should be distributed among the stretchable columns).

That would make ttk::treeview and tablelist behave identically I think (when they have the same -stretch column configuration), although tablelist definitely allows dragging separators further than the rightmost limit of the window.

What do you think?


fvogel added on 2019-04-13 20:53:21:

Thanks for your testing time, I appreciate that.

I have added test treeview-ce470f20fde checking for non-regression regarding this bug.

I'll let this mature a bit in the background of my mind before merging, with or without reverting [fa9b648368] I don't know yet.


ulfalizer added on 2019-04-13 20:37:35:
> For the second problem you have reported, i.e. the fact separators are
> allowed to escape out of the treeview area, I have a fix as well, see
> [63193647]. Please check it out with your app.

Checked. Works fine!

> At this point and after further digging in the source code I'm wondering if I
> shouldn't revert [fa9b648368] that prevents the rightmost column from being
> resized (through the right separator). Actually, in the source code quite
> some attention is given to properly maintaining the value of the "slack",
> that is the available space that exists when the width of the treeview area
> is less than the sum of the widths of the displayed columns.
>
> ...
>
> In this situation, the user could want to resize the rightmost column using
> the rightmost separator, which is not possible without reverting
> [fa9b648368]. Of course resizing of the rightmost column can also be done by
> moving any other separator, and this is perhaps what is best after all.
>
> Before [fa9b648368] the application user could size the rightmost column and
> create such a slack. Now it's still possible to have a slack by setting
> -width, e.g.:

My feeling is that very few people would expect to be able to resize the
treeview by dragging the right edge of the rightmost heading, and that it comes
off as a bug to most people. If resizing treeviews separately was a common
idiom, then I'd also expect to be able to resize it by dragging anywhere along
the right border, and not just in the heading area.

I suspect no one has made an UI that depends on being able to resize a treeview
like that (that would make for a very confusing UI, at least to me), as opposed
to just resizing e.g. the toplevel to resize the treeview.

Anyway, just my two cents.

fvogel added on 2019-04-13 12:03:20:

For the second problem you have reported, i.e. the fact separators are allowed to escape out of the treeview area, I have a fix as well, see [63193647]. Please check it out with your app.

At this point and after further digging in the source code I'm wondering if I shouldn't revert [fa9b648368] that prevents the rightmost column from being resized (through the right separator). Actually, in the source code quite some attention is given to properly maintaining the value of the "slack", that is the available space that exists when the width of the treeview area is less than the sum of the widths of the displayed columns.

Before [fa9b648368] the application user could size the rightmost column and create such a slack. Now it's still possible to have a slack by setting -width, e.g.:

package require Tk
pack [ttk::treeview .tree -columns {bar colA colB colC foo} -padding 50]
.tree heading bar -text "-bar-"
.tree heading colA -text "-colA-"
.tree heading colB -text "-colB-"
.tree heading colC -text "-colC-"
.tree heading foo -text "Drag my right edge -->"
.tree insert "" end -values xxxxxxxxxxxxxxxxxxxxxxxxxx
.tree column colB -width 30
.tree column colC -width 40

In this situation, the user could want to resize the rightmost column using the rightmost separator, which is not possible without reverting [fa9b648368]. Of course resizing of the rightmost column can also be done by moving any other separator, and this is perhaps what is best after all.

Opinions?


fvogel added on 2019-04-11 20:58:30:

I have a fix, please see [fa9b648368] in the dedicated bugfix branch bug-ce470f20fd.

This fix prevents dragging the right edge of the rightmost display column of the treeview. Please test with your larger application.


ulfalizer added on 2019-04-07 12:21:34:
Piggybacking a semi-unrelated thing I found:

Try dragging any heading separator outside the widget and then letting go of the mouse button. It seems there's now no way to get the separator back. Maybe the separators ought to be restricted to the treeview area.

ulfalizer added on 2019-04-07 12:04:02:
> Please elaborate as it's unclear to me at least: why is the ability to drag the
> column edge (purpose is to resize this column) an issue? what other behavior
> would you expect?

I would expect the right edge of the rightmost heading to not be draggable, in the same way that the left edge of the leftmost heading isn't draggable.

The arguments for the leftmost edge not being draggable and the rightmost edge not being draggable are the same to me. It's hard to argue objectively, but both feel very weird to me. I haven't seen that behavior in any other treeviews.

I don't think it's behavior people expect, and if there are widgets near the right edge of the rightmost heading, then you could accidentally drag it. Once you stumble upon it, I suspect most people would assume it's a bug in the widget. Maybe someone else could chime in.

fvogel added on 2019-04-07 11:44:15:
Please elaborate as it's unclear to me at least: why is the ability to drag the column edge (purpose is to resize this column) an issue? what other behavior would you expect?