Tk Source Code

View Ticket
Login
Ticket UUID: f569b9410c84870537f01d07e286c03b1b4ad0ce
Title: Improve the look of the focus indicator on Windows
Type: Patch Version: all
Submitter: nemethi Created on: 2024-08-07 17:28:04
Subsystem: 88. Themed Tk Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2024-08-10 15:39:11
Resolution: Accepted Closed By: nemethi
    Closed on: 2024-08-10 15:39:11
Description:

In the current implementation of Tk for Windows, the following widget components are drawn with the aid of the native DrawFocusRect() function:

  • the focus ring of the Tk core button widgets;
  • for the themes vista, winnative and xpnative, the focus ring of the ttk::button widgets, the focus element, and the filled focus ring of the read-only ttk::combobox widgets.

As seen in the screenshots contained in the left half of the attachment dottedRect.png and its magnified version dottedRect_x3.png, the resulting dotted rectangle has a thickness of 2px, which cannot be changed without manipulating the global system settings. IMHO, the thickness of 2px has a suboptimal look. In addition, the rectangle's outline interferes with the widget's text; this overlapping effect can be seen especially in the case of the ttk::combobox widget.

In order to eliminate the above-mentioned visual issues, I propose to replace the invocations of DrawFocusRect() with TkWinDrawDottedRect(). This function, introduced in checkin [22d56237], is already used (not only on Windows) to draw a better-looking focus element for the themes default, alt, and clam. The resulting visual improvements can be seen in the right half of the attachments.

User Comments: nemethi (claiming to be Csaba Nemethi) added on 2024-08-10 15:39:11:

Closing the ticket.


nemethi (claiming to be Csaba Nemethi) added on 2024-08-09 09:35:06:

Merged, see commits [39d50971], [06a3ce9c], and [907d8190].


fvogel added on 2024-08-08 19:07:43:
All what you're saying makes a lot of sense to me, please proceed.

nemethi (claiming to be Csaba Nemethi) added on 2024-08-08 18:36:49:

In the old days, the rectangle drawn via DrawFocusRect() had a thickness of 1px. Starting with Windows XP, the rectangle can be thicker than 1px, and this can be set both programmatically (using the SystemParametersInfo() function) and interactively, via the Control Panel or the Registry. The Control Panel of Windows 11 no longer supports this setting, but the Registry still does. Apparently, the default is currently 2px, although modern Window applications seem to no longer make use of the DrawFocusRect() function.

My proposal takes into account that the DrawFocusRect() function seems to be outdated, and the rectangle drawn by it is IMHO too thick. In addition, the dotted focus rectangle of the themes default, alt, and clam is always 1px thick, which is yet another argument in favor of changing the thickness to 1px for the Windows-specific themes, too.


fvogel added on 2024-08-07 20:32:04:

Sounds OK for me, except that I'm wondering: isn't the Windows API native function DrawFocusRect() supposed to provide native look to the focus ring? I'm a bit surprised that our own TkWinDrawDottedRect() would provide an even more Windows native look.


nemethi (claiming to be Csaba Nemethi) added on 2024-08-07 17:56:53:

The proposed patch is in checkin [d1e3cc0c].


Attachments: