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
This commit is contained in:
Stefan Csomor
2019-12-16 16:28:08 +01:00
parent 7fa1afafc2
commit df6304caa6

View File

@@ -3404,6 +3404,25 @@ void wxDataViewCheckIconTextRenderer::Allow3rdStateForUser(bool allow)
m_allow3rdStateForUser = 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() bool wxDataViewCheckIconTextRenderer::MacRender()
{ {
wxDataViewCheckIconText checkIconText; wxDataViewCheckIconText checkIconText;
@@ -3432,8 +3451,8 @@ bool wxDataViewCheckIconTextRenderer::MacRender()
const wxIcon& icon = checkIconText.GetIcon(); const wxIcon& icon = checkIconText.GetIcon();
if ( icon.IsOk() ) if ( icon.IsOk() )
{ {
NSTextAttachmentCell* const attachmentCell = wxNSTextAttachmentCellWithBaseline* const attachmentCell =
[[NSTextAttachmentCell alloc] initImageCell: icon.GetNSImage()]; [[wxNSTextAttachmentCellWithBaseline alloc] initImageCell: icon.GetNSImage()];
NSTextAttachment* const attachment = [NSTextAttachment new]; NSTextAttachment* const attachment = [NSTextAttachment new];
[attachment setAttachmentCell: attachmentCell]; [attachment setAttachmentCell: attachmentCell];
@@ -3450,6 +3469,8 @@ bool wxDataViewCheckIconTextRenderer::MacRender()
NSMutableAttributedString* const fullString = NSMutableAttributedString* const fullString =
[NSMutableAttributedString new]; [NSMutableAttributedString new];
[attachmentCell setCellBaselineOffset: NSMakePoint(0.0, -5.0)];
[fullString appendAttributedString: iconString]; [fullString appendAttributedString: iconString];
[fullString appendAttributedString: separatorString]; [fullString appendAttributedString: separatorString];
[fullString appendAttributedString: textAttrString]; [fullString appendAttributedString: textAttrString];