Skip to content

Commit

Permalink
bugfix: menu item alignment issue (#299)
Browse files Browse the repository at this point in the history
* fix: issue #298 menu item alignment issue

* fix: update format

* Update Easydict/Feature/StatusItem/EZMenuItemManager.m

Co-authored-by: Tisfeng <[email protected]>

---------

Co-authored-by: Tisfeng <[email protected]>
  • Loading branch information
phlpsong and tisfeng authored Jan 3, 2024
1 parent ecfd487 commit a2ce4b5
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions Easydict/Feature/StatusItem/EZMenuItemManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,9 @@ - (void)increaseMenuItemHeight:(NSMenuItem *)item lineHeightRatio:(CGFloat)lineH
NSFont *font = [NSFont systemFontOfSize:[NSFont systemFontSize]];
CGFloat fontLineHeight = (font.ascender + fabs(font.descender));
CGFloat lineHeight = fontLineHeight * lineHeightRatio;
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.minimumLineHeight = lineHeight;
style.maximumLineHeight = lineHeight;
CGFloat baselineOffset = (lineHeight - fontLineHeight) / 2;

item.attributedTitle = [[NSAttributedString alloc] initWithString:item.title attributes:@{
NSParagraphStyleAttributeName: style,
NSBaselineOffsetAttributeName: @(baselineOffset)
}];
// Ref stackoverflow: https://stackoverflow.com/a/18034142/8378840
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(1, lineHeight)];
[item setImage:image];
}

- (void)increaseMenuItemsHeight:(NSArray<NSMenuItem *> *)itmes lineHeightRatio:(CGFloat)lineHeightRatio {
Expand Down

0 comments on commit a2ce4b5

Please sign in to comment.