Support underlined/strikethrough fonts for window labels in wxOSX
Use setAttributedTitle: to take into account font underline/strikethrough attributes when using it for the window label. See https://github.com/wxWidgets/wxWidgets/pull/187
This commit is contained in:
committed by
Vadim Zeitlin
parent
54a64fc549
commit
cb3ac0e6fc
@@ -2420,6 +2420,46 @@ bool wxWidgetCocoaImpl::SetBackgroundStyle( wxBackgroundStyle style )
|
|||||||
|
|
||||||
void wxWidgetCocoaImpl::SetLabel( const wxString& title, wxFontEncoding encoding )
|
void wxWidgetCocoaImpl::SetLabel( const wxString& title, wxFontEncoding encoding )
|
||||||
{
|
{
|
||||||
|
if ( [m_osxView respondsToSelector:@selector(setAttributedTitle:) ] )
|
||||||
|
{
|
||||||
|
wxFont f = GetWXPeer()->GetFont();
|
||||||
|
if ( f.GetStrikethrough() || f.GetUnderlined() )
|
||||||
|
{
|
||||||
|
wxCFStringRef cf(title, encoding );
|
||||||
|
|
||||||
|
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]
|
||||||
|
initWithString:cf.AsNSString()];
|
||||||
|
|
||||||
|
[attrString beginEditing];
|
||||||
|
[attrString setAlignment:NSCenterTextAlignment
|
||||||
|
range:NSMakeRange(0, [attrString length])];
|
||||||
|
|
||||||
|
[attrString addAttribute:NSFontAttributeName
|
||||||
|
value:f.OSXGetNSFont()
|
||||||
|
range:NSMakeRange(0, [attrString length])];
|
||||||
|
if ( f.GetStrikethrough() )
|
||||||
|
{
|
||||||
|
[attrString addAttribute:NSStrikethroughStyleAttributeName
|
||||||
|
value:@(NSUnderlineStyleSingle)
|
||||||
|
range:NSMakeRange(0, [attrString length])];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( f.GetUnderlined() )
|
||||||
|
{
|
||||||
|
[attrString addAttribute:NSUnderlineStyleAttributeName
|
||||||
|
value:@(NSUnderlineStyleSingle)
|
||||||
|
range:NSMakeRange(0, [attrString length])];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[attrString endEditing];
|
||||||
|
|
||||||
|
[(id)m_osxView setAttributedTitle:attrString];
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( [m_osxView respondsToSelector:@selector(setTitle:) ] )
|
if ( [m_osxView respondsToSelector:@selector(setTitle:) ] )
|
||||||
{
|
{
|
||||||
wxCFStringRef cf( title , encoding );
|
wxCFStringRef cf( title , encoding );
|
||||||
|
Reference in New Issue
Block a user