From df6304caa69164eeaa2969c28afd6b33e175bce8 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Mon, 16 Dec 2019 16:28:08 +0100 Subject: [PATCH] add baselineOffset override to better align icons Cocoa by default aligns the cell on the text baseline, which is not suitable for our needs, solved by subclassing NSTextAttachmentCell --- src/osx/cocoa/dataview.mm | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 6ad23b57a1..7041b5bcd1 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -3404,6 +3404,25 @@ void wxDataViewCheckIconTextRenderer::Allow3rdStateForUser(bool allow) m_allow3rdStateForUser = allow; } +@interface wxNSTextAttachmentCellWithBaseline : NSTextAttachmentCell +{ +NSPoint _offset; +} +@end + +@implementation wxNSTextAttachmentCellWithBaseline + +- (void) setCellBaselineOffset:(NSPoint) offset +{ + _offset=offset; +} +- (NSPoint)cellBaselineOffset +{ + return _offset; +} + +@end + bool wxDataViewCheckIconTextRenderer::MacRender() { wxDataViewCheckIconText checkIconText; @@ -3432,8 +3451,8 @@ bool wxDataViewCheckIconTextRenderer::MacRender() const wxIcon& icon = checkIconText.GetIcon(); if ( icon.IsOk() ) { - NSTextAttachmentCell* const attachmentCell = - [[NSTextAttachmentCell alloc] initImageCell: icon.GetNSImage()]; + wxNSTextAttachmentCellWithBaseline* const attachmentCell = + [[wxNSTextAttachmentCellWithBaseline alloc] initImageCell: icon.GetNSImage()]; NSTextAttachment* const attachment = [NSTextAttachment new]; [attachment setAttachmentCell: attachmentCell]; @@ -3450,6 +3469,8 @@ bool wxDataViewCheckIconTextRenderer::MacRender() NSMutableAttributedString* const fullString = [NSMutableAttributedString new]; + [attachmentCell setCellBaselineOffset: NSMakePoint(0.0, -5.0)]; + [fullString appendAttributedString: iconString]; [fullString appendAttributedString: separatorString]; [fullString appendAttributedString: textAttrString];