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 <tisfeng@gmail.com>

---------

Co-authored-by: Tisfeng <tisfeng@gmail.com>
  • Loading branch information
phlpsong and tisfeng committed Jan 6, 2024
1 parent 5cc15b1 commit 792ea08
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 792ea08

Please sign in to comment.