Repository navigation
Centre Button content on a whole pixel - #14700
omarchybot wants to merge 1 commit into
Conversation
anchors.horizontalCenter rounds the button's centre and the row's separately, so once a layout gives a button a whole-pixel width the content can land a pixel right of centre. The Network panel's speed-test action gets width 29 from its RowLayout and its icon row sits at x 7 where the centre is 6.01; at scale 1.25 that is 7 px of highlight left of the icon and 5 right. The row is now placed with a rounded x, which keeps it on a whole pixel within half a pixel of the centre. An x is not mirrored the way an anchor is, so leftAlign mirrors its inset explicitly, as the left anchor it replaces did. Fabian Behrendt measured the same 7/5 offset on #8787 and proposed rounding the row's position. Co-Authored-By: Fabian Behrendt <7931874+fabianbehrendt@users.noreply.github.com> Co-Authored-By: Codex Medium <noreply@openai.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
Read at 5f08540 against Two things the reading did find, for whoever picks it up next:
The diff still merges cleanly with |
Buttoncentred its content withanchors.horizontalCenter, and Qt rounds the button's centre and the content row's centre separately. Once a layout gives a button a whole-pixel width, that can put the content a whole pixel right of centre. The Network panel's speed-test header action is one: itsRowLayoutmakes it 29 px wide, the icon row is 16.98 px, and the row lands at x 7 where the centre is 6.01. At scale 1.25 that is 7 px of highlight left of the icon and 5 px right, which is what #8782 reports from a stock install.The row is now placed with
x: Math.round((root.width - width) / 2), which keeps it on a whole pixel and within half a pixel of the centre at any width.leftAlignkeeps its inset. Anxis not mirrored the way an anchor is, so the mirrored case is computed explicitly and lands where the old mirrored left anchor put it. EveryButtonin the shell gets the same correction, by at most a pixel and always towards the centre; none of them setsleftAlign.test/shell.d/button-centering-test.shbuilds buttons with icon, text and mixed content at whole and fractional widths, plain and mirrored, and requires the content on a whole pixel within half a pixel of the centre. It also checks thatleftAlignkeeps its inset on either side. Onquattroit fails at odd widths for icons and plain text alike.#8787 addresses the other half of #8782, the box being taller than wide, by moving these two actions to
PanelActionButton. That component centres its icon withanchors.centerIn, which rounds the same way, so if #8787 lands these two actions would need the same correction there. @fabianbehrendt measured this 7/5 offset on #8787 and proposed rounding the row's position, which this follows.Fixes #8782