diff options
author | marc_culler <marc.culler@gmail.com> | 2020-09-12 21:30:41 (GMT) |
---|---|---|
committer | marc_culler <marc.culler@gmail.com> | 2020-09-12 21:30:41 (GMT) |
commit | cd9987e74b4772140be98620c89fde03aac58ea2 (patch) | |
tree | 5fcb8c8f7e7b7fc8fe06cdeea50134e344e17dd4 /macosx/ttkMacOSXTheme.c | |
parent | db31b9f1cedb54fbdc52442ea1c21bf06c556b68 (diff) | |
download | tk-cd9987e74b4772140be98620c89fde03aac58ea2.zip tk-cd9987e74b4772140be98620c89fde03aac58ea2.tar.gz tk-cd9987e74b4772140be98620c89fde03aac58ea2.tar.bz2 |
Add a disclosure triangle that works in Big Sur
Diffstat (limited to 'macosx/ttkMacOSXTheme.c')
-rw-r--r-- | macosx/ttkMacOSXTheme.c | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/macosx/ttkMacOSXTheme.c b/macosx/ttkMacOSXTheme.c index df597f4..e999fc2 100644 --- a/macosx/ttkMacOSXTheme.c +++ b/macosx/ttkMacOSXTheme.c @@ -303,9 +303,10 @@ static void GetBackgroundColor( /*---------------------------------------------------------------------- - * +++ Single Arrow Buttons -- + * +++ Single Arrow Images -- * - * Used in ListHeaders and Comboboxes. + * Used in ListHeaders and Comboboxes as well as disclosure triangles in + * macOS 11. */ static void DrawDownArrow( @@ -352,6 +353,48 @@ static void DrawUpArrow( CGContextStrokePath(context); } +static void DrawClosedDisclosure( + CGContextRef context, + CGRect bounds, + CGFloat inset, + CGFloat size, + CGFloat *rgba) +{ + CGFloat x, y; + + CGContextSetRGBStrokeColor(context, rgba[0], rgba[1], rgba[2], rgba[3]); + CGContextSetLineWidth(context, 1.5); + x = bounds.origin.x + inset; + y = bounds.origin.y + trunc(bounds.size.height / 2); + CGContextBeginPath(context); + CGPoint arrow[3] = { + {x, y - size / 4 - 1}, {x + size / 2, y}, {x, y + size / 4 + 1} + }; + CGContextAddLines(context, arrow, 3); + CGContextStrokePath(context); +} + +static void DrawOpenDisclosure( + CGContextRef context, + CGRect bounds, + CGFloat inset, + CGFloat size, + CGFloat *rgba) +{ + CGFloat x, y; + + CGContextSetRGBStrokeColor(context, rgba[0], rgba[1], rgba[2], rgba[3]); + CGContextSetLineWidth(context, 1.5); + x = bounds.origin.x + inset; + y = bounds.origin.y + trunc(bounds.size.height / 2); + CGContextBeginPath(context); + CGPoint arrow[3] = { + {x, y - size / 4}, {x + size / 2, y + size / 2}, {x + size, y - size / 4} + }; + CGContextAddLines(context, arrow, 3); + CGContextStrokePath(context); +} + /*---------------------------------------------------------------------- * +++ Double Arrow Buttons -- * @@ -3001,8 +3044,21 @@ static void DisclosureElementDraw( }; BEGIN_DRAWING(d) - ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, + if ([NSApp macOSVersion] >= 110000) { + CGFloat rgba[4]; + NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; + NSColor *stroke = [[NSColor textColor] + colorUsingColorSpace: deviceRGB]; + [stroke getComponents: rgba]; + if (state & TTK_TREEVIEW_STATE_OPEN) { + DrawOpenDisclosure(dc.context, bounds, 2, 8, rgba); + } else { + DrawClosedDisclosure(dc.context, bounds, 2, 12, rgba); + } + } else { + ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); + } END_DRAWING } } |