Skip to content

Centre tab titles and close buttons in the tab bar - #46

Merged
dayglojesus merged 1 commit into
mainfrom
fix/tab-title-centering
Aug 25, 2026
Merged

Centre tab titles and close buttons in the tab bar#46
dayglojesus merged 1 commit into
mainfrom
fix/tab-title-centering

Conversation

@dayglojesus

Copy link
Copy Markdown
Collaborator

Closes #37.

The bug

The tab title and close button were positioned by pinning their bottom edges 3pt and 4pt above the bottom of the tab:

[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[close]-(4)-|" ...]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[title]-(3)-|" ...]];

Those insets centre a 16pt label and a 13pt button only when the tab is 22pt tall, which is what OakTabBarView.mm:720's intrinsicContentSize asks for.

It never gets 22pt. The tab bar is an NSTitlebarAccessoryViewController view (DocumentWindowController.mm:208-212), and AppKit fixes those at a height of its own choosing. Probing it on macOS 26.5 (25F71):

requested intrinsic height -> actual
    10 -> 36.0        36 -> 36.0
    23 -> 36.0        60 -> 36.0

The request is discarded entirely — it is neither a floor nor a ceiling. No window configuration moves it either: titlebarAppearsTransparent, titleVisibility, NSWindowStyleMaskFullSizeContentView, and both unified toolbar styles all give 36. Only layoutAttribute Right or Left differ (32pt), and those place the accessory inline beside the window title, which is no use for a tab bar.

So the accessory is 36pt, tabs fill it at 35pt (NSHeight(self.bounds)-1), and the two bottom-pinned subviews sat well below the middle of them.

Measurements

Clear space above and below the title ink, in device pixels, in a 70px tab, taken from window captures at 2x:

above below
before 38 7
after 26 25

The close button measures 28/28 after the change. Both figures land within a pixel of tagliala's build, which is the reference the issue points at.

The change

Both subviews are constrained to the tab's centre, which holds at whatever height AppKit hands us, with a 1pt constant so they sit fractionally low rather than dead centre — that reads better at this tab height.

Relationship to the upstream PRs

The issue links two PRs on tagliala's fork.

  • tagliala#25 (merged there) is the same approach as this. Its diff does not apply here: it deletes V:[close]-(10)-| and V:[title]-(9)-|, values that fork introduced as a workaround with a TODO admitting as much. This tree still has the original 4 and 3.
  • tagliala#16 (still open there) removes the ±1 in setCurrentLayout's frame arithmetic. It does not touch the pinning, so it does not address the cause; applied on its own here it moves the title 0.5pt further from centre and the close button 1pt. Not taken.

Worth noting separately

intrinsicContentSize returning 23 has no effect on the rendered height and will mislead the next person to read it. tagliala's issue #15 ("the tab navigation bar is too tall") is unfixable from that direction for the same reason — they observed that changing intrinsicContentSize did nothing, and this is why. Left alone here to keep the change to the reported bug.

The title and close button were positioned by pinning their bottom edges
3pt and 4pt above the bottom of the tab. Those insets only centre a 16pt
label and a 13pt button when the tab is 22pt tall, which is what
OakTabBarView's intrinsicContentSize asks for.

It never gets 22pt. The tab bar is a titlebar accessory, and AppKit fixes
those at 36pt no matter what the view requests -- asking for 10, 23, 40 or
60 all come back 36, and no window configuration changes it. Tabs fill the
accessory, so they are 35pt, and the two bottom-pinned subviews ended up
well below the middle of them.

Constrain both to the tab's centre instead, which holds at whatever height
AppKit hands us, plus a point so they sit fractionally low rather than dead
centre.
@dayglojesus
dayglojesus merged commit 9d6f47e into main Aug 25, 2026
2 checks passed
This was referenced Aug 27, 2026
@dayglojesus
dayglojesus deleted the fix/tab-title-centering branch August 27, 2026 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Center tab titles and close buttons in OakTabBarView

1 participant