Tk Source Code

View Ticket
Login
Ticket UUID: 011533811758269de23a3e874f3ca9f326bab1f3
Title: Flip ttk::notebook tab states "first" and "last" for "-tabplacement e*|s*"
Type: Bug Version: all
Submitter: nemethi Created on: 2026-04-08 14:30:29
Subsystem: 88. Themed Tk Assigned To: nemethi
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-04-14 16:41:36
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-04-14 16:41:36
Description:

The ttk::notebook implementation (function TabState() in the file generic/ttk/ttkNotebook.c) pretends to set the tab state to first for the leftmost/topmost visible tab and to last for the rightmost/bottommost visible tab. (Tk versions 8.6 and earlier use the states user1 and user2 rather than first and last, which were added in Tk 8.7/9.0.). These tab state flags are used in the implementation of the themes clam, vista, and aqua.

It turns out that currently the function TabState() fails to do what it pretends if the value of the -tabplacement styling option starts with e or s, i.e., if the tabs are placed from right to left or from bottom to top. In the case of the clam theme this leads to the effect shown in the attached screenshot nbtest_clam_BAD.png, as reported by Christian Werner.

The fix, proposed by Christian and implemented in the branch notebook-fix, swaps the tab state flags first and last if the value of the -tabplacement styling option starts with e or s. In the case of the clam theme this leads to the effect shown in the attached screenshot nbtest_clam_GOOD.png. Besides this bugfix, the branch contains further notebook-related improvements for most built-in themes and adds the description of the styling option -tabplacement to the ttk_notebook manual.

User Comments: chw added on 2026-04-14 15:57:46:
¡Csaba, muchas gracias por tu valioso apoyo!

nemethi (claiming to be Csaba Nemethi) added on 2026-04-14 15:46:01:

Fixed by commits [9a851511], [066c5134], and [d64f145a] to main, core-9-0-branch, and core-8-6-branch.


chw added on 2026-04-12 05:10:04:
Csaba, much better approach! Now it looks quite good on Windows.
What about beginning to merge it starting with ye goode olde 8.6
steam engine? A TIP is not needed, since all these changes are
fixes of longstanding visual glitches.

nemethi (claiming to be Csaba Nemethi) added on 2026-04-11 16:20:01:

Christian, many thanks for your valuable input! I have just committed updated versions of the files ttkWinTheme.c and ttkWinVistaTheme.c.

In ttkWinTheme.c I made a few necessary changes, taking into account that the data of the rectangle to be passed to the DrawEdge() function depend on the sticky bit of the tab placement. With your original code there were missing pixels in the edge drawn by this function.

In ttkWinVistaTheme.c I chose a different approach than you. Besides being simpler, my code also eliminates a gap created by your method below the rightmost tab of the first notebook in the 3rd row of your example script.


chw added on 2026-04-11 07:58:39:
And here is the third attempt:

  https://androwish.org/home/info/545391a7744a669e

chw added on 2026-04-10 18:20:21:
An update to my first attempt, the second source, so to speak:

  https://androwish.org/home/info/57350cc5ec6ac5d4

This was necessary due to testing with your nbtest.tcl times 2,
which I attach as nbtest8.tcl to this ticket. It basically permutes
the -tabposition/-tabplacement options further, BTW still without
using all combinations times more than one row/column. So most
likely we have many little visual deficiencies to discover.

chw added on 2026-04-10 10:43:43:
Csaba, thanks for your improvements. However, the 3D border effect
needs more polishing, see my first attempt in this check-in

  https://androwish.org/home/info/e19da7dd70b66ca7

Affected themes: alt, classic, default, winnative. Untested is the
behavior for tabs distributed upon more rows/columns.

oehhar added on 2026-04-09 12:20:05:

More background to this ticket started is in [23f52946] (Androwish pointer).


nemethi (claiming to be Csaba Nemethi) added on 2026-04-09 11:44:32:

Christian, I have just uploaded a new version of the test script nbtest.tcl. Many thanks for your suggestion! The original version intentionally contained the line

set themeList [ttk::style theme names]

because the branch notebook-fix deals with built-in themes only. OTOH, the updated version can prove useful for testing the layout-related issues of third-party themes, too.

The styling options -tabposition and -tabplacement have been present in Ttk from the very beginning, but the original implementation of the notebook tabs simply ignored them, with the result that in all themes, the tab layout looked as expected on the north side of the widget only. In the last three years I made pretty many changes in both the C code and in the theme-specific scripts of the built-in themes, with the result that now the tabs look as expected on all 4 sides of the notebook widget. This has become even better due to your fix and to the further improvements made now in the notebook-fix branch. And, as you mentioned, the long-awaited vertical texts will improve the tab layouts even further and quite significantly.

To your question regarding the pixel-based themes: I would recommend to try the same method as the one applied to the built-in themes: After setting the notebook style's -tabposition option, invoke ttk::configureNotebookStyle, which in turn calls the proc theme::${theme}::configureNotebookStyle if present. That proc should invoke ttk::style configure and ttk::style map for theme-specific styling options like -padding, -tabmargins, or -expand.


chw added on 2026-04-08 18:21:13:
Thanks for bringing this topic forward, it will improve Tk's look
even more tremendously when Emiliano's angled text will be included
later.

The nbtest.tcl test script is very valuable. Would you improve it
by using "package require opt" right after "package require Tk"
(to update the package list) and setting the "themeList" variable
by "ttk::themes" instead of "ttk::style theme names" (to get all
packaged themes in the option menu).

Now for my observation: with many pixel-based themes (e.g. awarc,
awbreeze, awwinxpblue, keramik, plastik, droid) most non-standard
tab layouts are somehow broken. Do you have an idea how this can
be fixed, generally and hopefully easily?

nemethi (claiming to be Csaba Nemethi) added on 2026-04-08 14:39:26:

Attached the sample script nbtest.tcl and assigned the ticket to myself.


Attachments: