Skip to content

Commit

Permalink
UI/mac: Fix tab title icon and text layout
Browse files Browse the repository at this point in the history
Make the tab title icon and text vertical center
  • Loading branch information
bestwnh committed Oct 15, 2024
1 parent 7a92b47 commit 3ea5a47
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Ladybird/AppKit/UI/Tab.mm
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,19 @@ - (void)updateTabTitleAndFavicon
[favicon_attribute addAttribute:NSForegroundColorAttributeName
value:[NSColor clearColor]
range:NSMakeRange(0, [favicon_attribute length])];
// Add a offset to make the icon vertical center, maybe have better solution
[favicon_attribute addAttribute:NSBaselineOffsetAttributeName
value:@-2
range:NSMakeRange(0, [favicon_attribute length])];

// By default, the text attachment will be aligned to the bottom of the string. We have to manually
// try to center it vertically.
// FIXME: Figure out a way to programmatically arrive at a good NSBaselineOffsetAttributeName. Using
// half the distance between the font's line height and the height of the favicon produces a
// value that results in the title being aligned too low still.
CGFloat titleFontSize = 12;
CGFloat baselineOffset = (self.favicon.size.height - titleFontSize) / 2;
auto* title_attributes = @{
NSForegroundColorAttributeName : [NSColor textColor],
NSBaselineOffsetAttributeName : @3
NSBaselineOffsetAttributeName : @(baselineOffset),
NSFontAttributeName : [NSFont systemFontOfSize:titleFontSize]
};

auto* title_attribute = [[NSAttributedString alloc] initWithString:self.title
Expand Down

0 comments on commit 3ea5a47

Please sign in to comment.