From 1a270ba78205a4d04e543b3c4cd51fa7545d7d9c Mon Sep 17 00:00:00 2001 From: phlpsong Date: Wed, 3 Jan 2024 21:12:41 +0800 Subject: [PATCH 1/3] fix: issue #298 menu item alignment issue --- Easydict/Feature/StatusItem/EZMenuItemManager.m | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Easydict/Feature/StatusItem/EZMenuItemManager.m b/Easydict/Feature/StatusItem/EZMenuItemManager.m index 80a2ba965..8f6cc96c6 100644 --- a/Easydict/Feature/StatusItem/EZMenuItemManager.m +++ b/Easydict/Feature/StatusItem/EZMenuItemManager.m @@ -326,15 +326,8 @@ - (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) - }]; + NSImage *image= [[NSImage alloc] initWithSize:NSMakeSize(1, lineHeight)]; + [item setImage:image]; } - (void)increaseMenuItemsHeight:(NSArray *)itmes lineHeightRatio:(CGFloat)lineHeightRatio { From fc33677d0caf9491c57b02478ca6b53fa18e085f Mon Sep 17 00:00:00 2001 From: phlpsong Date: Wed, 3 Jan 2024 21:34:25 +0800 Subject: [PATCH 2/3] fix: update format --- Easydict/Feature/StatusItem/EZMenuItemManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Easydict/Feature/StatusItem/EZMenuItemManager.m b/Easydict/Feature/StatusItem/EZMenuItemManager.m index 8f6cc96c6..b2c9462f6 100644 --- a/Easydict/Feature/StatusItem/EZMenuItemManager.m +++ b/Easydict/Feature/StatusItem/EZMenuItemManager.m @@ -326,7 +326,7 @@ - (void)increaseMenuItemHeight:(NSMenuItem *)item lineHeightRatio:(CGFloat)lineH NSFont *font = [NSFont systemFontOfSize:[NSFont systemFontSize]]; CGFloat fontLineHeight = (font.ascender + fabs(font.descender)); CGFloat lineHeight = fontLineHeight * lineHeightRatio; - NSImage *image= [[NSImage alloc] initWithSize:NSMakeSize(1, lineHeight)]; + NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(1, lineHeight)]; [item setImage:image]; } From 47a424bd3427d587471a9ddec8a8a82cddd476dd Mon Sep 17 00:00:00 2001 From: phlpsong <103433299+phlpsong@users.noreply.github.com> Date: Wed, 3 Jan 2024 21:53:09 +0800 Subject: [PATCH 3/3] Update Easydict/Feature/StatusItem/EZMenuItemManager.m Co-authored-by: Tisfeng --- Easydict/Feature/StatusItem/EZMenuItemManager.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Easydict/Feature/StatusItem/EZMenuItemManager.m b/Easydict/Feature/StatusItem/EZMenuItemManager.m index b2c9462f6..ca784ad32 100644 --- a/Easydict/Feature/StatusItem/EZMenuItemManager.m +++ b/Easydict/Feature/StatusItem/EZMenuItemManager.m @@ -326,6 +326,7 @@ - (void)increaseMenuItemHeight:(NSMenuItem *)item lineHeightRatio:(CGFloat)lineH NSFont *font = [NSFont systemFontOfSize:[NSFont systemFontSize]]; CGFloat fontLineHeight = (font.ascender + fabs(font.descender)); CGFloat lineHeight = fontLineHeight * lineHeightRatio; + // Ref stackoverflow: https://stackoverflow.com/a/18034142/8378840 NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(1, lineHeight)]; [item setImage:image]; }