Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Improve the behavior and appearance of BevelButtons. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | bug-0d63621b6c |
Files: | files | file ages | folders |
SHA3-256: |
523b9147c1676ae9acdaebf18b8dd3c6 |
User & Date: | culler 2019-03-17 19:41:04.167 |
Context
2019-03-17
| ||
20:40 | Added a drawing procedure for dark BevelButtons. check-in: 520a121d user: culler tags: bug-0d63621b6c | |
19:41 | Improve the behavior and appearance of BevelButtons. check-in: 523b9147 user: culler tags: bug-0d63621b6c | |
14:13 | Fixed error in height computation for BevelButtons. check-in: a8b91a2d user: culler tags: bug-0d63621b6c | |
Changes
Changes to library/demos/toolbar.tcl.
︙ | ︙ | |||
27 28 29 30 31 32 33 | ## Set up the toolbar hull set t [frame $w.toolbar] ;# Must be a frame! ttk::separator $w.sep ttk::frame $t.tearoff -cursor fleur ttk::separator $t.tearoff.to -orient vertical ttk::separator $t.tearoff.to2 -orient vertical | | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | ## Set up the toolbar hull set t [frame $w.toolbar] ;# Must be a frame! ttk::separator $w.sep ttk::frame $t.tearoff -cursor fleur ttk::separator $t.tearoff.to -orient vertical ttk::separator $t.tearoff.to2 -orient vertical pack $t.tearoff.to -fill y -expand 1 -padx 4 -side left pack $t.tearoff.to2 -fill y -expand 1 -side left ttk::frame $t.contents grid $t.tearoff $t.contents -sticky nsew grid columnconfigure $t $t.contents -weight 1 grid columnconfigure $t.contents 1000 -weight 1 ## Bindings so that the toolbar can be torn off and reattached |
︙ | ︙ | |||
75 76 77 78 79 80 81 | } ## Some content for the rest of the toplevel text $w.txt -width 40 -height 10 interp alias {} doInsert {} $w.txt insert end ;# Make bindings easy to write ## Arrange contents | | | 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | } ## Some content for the rest of the toplevel text $w.txt -width 40 -height 10 interp alias {} doInsert {} $w.txt insert end ;# Make bindings easy to write ## Arrange contents grid $t.button $t.check $t.menu $t.combo -in $t.contents -padx 2 -pady 4 -sticky ns grid $t -sticky ew grid $w.sep -sticky ew grid $w.msg -sticky ew grid $w.txt -sticky nsew grid rowconfigure $w $w.txt -weight 1 grid columnconfigure $w $w.txt -weight 1 ## See Code / Dismiss buttons set btns [addSeeDismiss $w.buttons $w] grid $btns -sticky ew |
Changes to library/ttk/aquaTheme.tcl.
︙ | ︙ | |||
22 23 24 25 26 27 28 | background systemHighlight !focus systemHighlightSecondary} \ -selectforeground { background systemLabelColor !focus systemDialogActiveText} # Buttons | | > | > > > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | background systemHighlight !focus systemHighlightSecondary} \ -selectforeground { background systemLabelColor !focus systemDialogActiveText} # Buttons # ttk::style configure TButton -anchor center -width -6 \ ttk::style configure TButton -anchor center \ -foreground systemControlTextColor ttk::style map TButton \ -foreground { disabled systemDisabledControlTextColor} ttk::style map TCheckbutton \ -foreground { disabled systemDisabledControlTextColor} ttk::style map TRadiobutton \ -foreground { disabled systemDisabledControlTextColor} ttk::style map Toolbutton \ -foreground { disabled systemDisabledControlTextColor } # Workaround for #1100117: # Actually, on Aqua we probably shouldn't stipple images in # disabled buttons even if it did work... ttk::style configure . -stipple {} # Notebook |
︙ | ︙ |
Changes to macosx/ttkMacOSXTheme.c.
︙ | ︙ | |||
41 42 43 44 45 46 47 48 49 50 51 52 53 54 | TkMacOSXDrawingContext dc; \ if (!TkMacOSXSetupDrawingContext((d), NULL, 1, &dc)) {return;} #define END_DRAWING \ TkMacOSXRestoreDrawingContext(&dc); } #define HIOrientation kHIThemeOrientationNormal #define NoThemeMetric 0xFFFFFFFF #ifdef __LP64__ #define RangeToFactor(maximum) (((double) (INT_MAX >> 1)) / (maximum)) #else #define RangeToFactor(maximum) (((double) (LONG_MAX >> 1)) / (maximum)) #endif /* __LP64__ */ | > > > > | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | TkMacOSXDrawingContext dc; \ if (!TkMacOSXSetupDrawingContext((d), NULL, 1, &dc)) {return;} #define END_DRAWING \ TkMacOSXRestoreDrawingContext(&dc); } #define HIOrientation kHIThemeOrientationNormal #define NoThemeMetric 0xFFFFFFFF #define BEVEL_XPAD 6 #define BEVEL_YPAD 6 static Ttk_Padding BevelButtonMargins = {BEVEL_XPAD, BEVEL_YPAD, BEVEL_XPAD, BEVEL_YPAD}; #ifdef __LP64__ #define RangeToFactor(maximum) (((double) (INT_MAX >> 1)) / (maximum)) #else #define RangeToFactor(maximum) (((double) (LONG_MAX >> 1)) / (maximum)) #endif /* __LP64__ */ |
︙ | ︙ | |||
203 204 205 206 207 208 209 | CGContextFillPath(context); CFRelease(path); } /* * NormalizeButtonBounds -- * | | | | | | | > > > > | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | CGContextFillPath(context); CFRelease(path); } /* * NormalizeButtonBounds -- * * Apple's Human Interface Guidelines only allow three specific heights for * most buttons: Regular, small and mini. We always use the regular size. * However, Ttk may provide an arbitrary bounding rectangle. We always draw * the button centered vertically on the rectangle, and having the same width * as the rectangle. This function returns the actual bounding rectangle that * will be used in drawing the button. * * The BevelButton is allowed to have arbitrary size, and also has external * padding. This is handled separately here. */ static CGRect NormalizeButtonBounds( SInt32 heightMetric, CGRect bounds) { SInt32 height; if (heightMetric != NoThemeMetric) { ChkErr(GetThemeMetric, heightMetric, &height); bounds.origin.y += (bounds.size.height - height)/2; bounds.size.height = height; } return bounds; } /* SolidFillRoundedRectangle -- * * Fill a rounded rectangle with a specified solid color. */ static void SolidFillRoundedRectangle( CGContextRef context, CGRect bounds, CGFloat radius, NSColor *color) { CGPathRef path; CGContextSetFillColorWithColor(context, color.CGColor); path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL); CGContextBeginPath(context); CGContextAddPath(context, path); CGContextFillPath(context); CFRelease(path); } /* GradientFillRoundedRectangle -- * * Fill a rounded rectangle with a specified gradient. */ static void GradientFillRoundedRectangle( CGContextRef context, CGRect bounds, CGFloat radius, CGFloat* colors, int numColors) { NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; CGPathRef path; CGPoint end = {bounds.origin.x, bounds.origin.y + bounds.size.height}; CGGradientRef gradient = CGGradientCreateWithColorComponents( deviceRGB.CGColorSpace, colors, NULL, numColors); path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL); CGContextBeginPath(context); CGContextAddPath(context, path); CGContextClip(context); CGContextDrawLinearGradient(context, gradient, bounds.origin, end, 0); CFRelease(path); CFRelease(gradient); } #endif /* MAC_OS_X_VERSION_MIN_REQUIRED > 1080 */ #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300 /*---------------------------------------------------------------------- * +++ Drawing procedures for widgets in Apple's "Dark Mode" (10.14 and up). * * The HIToolbox does not support Dark Mode, and apparently never will, |
︙ | ︙ | |||
327 328 329 330 331 332 333 | CGContextReplacePathWithStrokedPath(context); CGContextClip(context); CGContextDrawLinearGradient(context, topGradient, bounds.origin, topEnd, 0.0); CGContextRestoreGState(context); CFRelease(topGradient); } | < < < < < < < < < < < < < < < < < < < < < < < < < < < | 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | CGContextReplacePathWithStrokedPath(context); CGContextClip(context); CGContextDrawLinearGradient(context, topGradient, bounds.origin, topEnd, 0.0); CGContextRestoreGState(context); CFRelease(topGradient); } /* * DrawDarkButton -- * * This is a standalone drawing procedure which draws PushButtons and * PopupButtons in the Dark Mode style. */ |
︙ | ︙ | |||
386 387 388 389 390 391 392 | /* * Fill the button face with the appropriate color. */ bounds = CGRectInset(bounds, 1, 1); if (kind == kThemePushButton && (state & TTK_STATE_PRESSED)) { | | | | | 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | /* * Fill the button face with the appropriate color. */ bounds = CGRectInset(bounds, 1, 1); if (kind == kThemePushButton && (state & TTK_STATE_PRESSED)) { GradientFillRoundedRectangle(context, bounds, 4, darkSelectedGradient, 2); } else { if (state & TTK_STATE_DISABLED) { faceColor = [NSColor colorWithColorSpace: deviceRGB components: darkDisabledButtonFace count: 4]; } else { faceColor = [NSColor colorWithColorSpace: deviceRGB components: darkButtonFace count: 4]; } SolidFillRoundedRectangle(context, bounds, 4, faceColor); } /* * If this is a popup, draw the arrow button. */ if (kind == kThemePopupButton) { CGFloat x, y; CGRect arrowBounds = bounds; arrowBounds.size.width = 16; arrowBounds.origin.x += bounds.size.width - 16; CGContextSaveGState(context); /* * If the toplevel is front, paint the button blue. */ if (!(state & TTK_STATE_BACKGROUND)) { GradientFillRoundedRectangle(context, arrowBounds, 4, darkSelectedGradient, 2); } /* * Stroke the arrows. */ |
︙ | ︙ | |||
467 468 469 470 471 472 473 | CGContextClipToRect(context, bounds); FillButtonBackground(context, bounds, 4); bounds = CGRectInset(bounds, 1, 1); if (!(state & TTK_STATE_BACKGROUND) && !(state & TTK_STATE_DISABLED) && ((state & TTK_STATE_SELECTED) || (state & TTK_STATE_ALTERNATE))) { | > | > | | 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | CGContextClipToRect(context, bounds); FillButtonBackground(context, bounds, 4); bounds = CGRectInset(bounds, 1, 1); if (!(state & TTK_STATE_BACKGROUND) && !(state & TTK_STATE_DISABLED) && ((state & TTK_STATE_SELECTED) || (state & TTK_STATE_ALTERNATE))) { GradientFillRoundedRectangle(context, bounds, 3, darkSelectedGradient, 2); } else { GradientFillRoundedRectangle(context, bounds, 3, darkInactiveGradient, 2); } HighlightButtonBorder(context, bounds); if ((state & TTK_STATE_SELECTED) || (state & TTK_STATE_ALTERNATE)) { CGContextSetStrokeColorSpace(context, deviceRGB.CGColorSpace); if (state & TTK_STATE_DISABLED) { stroke = [NSColor disabledControlTextColor]; } else { |
︙ | ︙ | |||
522 523 524 525 526 527 528 | CGContextClipToRect(context, bounds); FillButtonBackground(context, bounds, 9); bounds = CGRectInset(bounds, 1, 1); if (!(state & TTK_STATE_BACKGROUND) && !(state & TTK_STATE_DISABLED) && ((state & TTK_STATE_SELECTED) || (state & TTK_STATE_ALTERNATE))) { | > | > | | 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | CGContextClipToRect(context, bounds); FillButtonBackground(context, bounds, 9); bounds = CGRectInset(bounds, 1, 1); if (!(state & TTK_STATE_BACKGROUND) && !(state & TTK_STATE_DISABLED) && ((state & TTK_STATE_SELECTED) || (state & TTK_STATE_ALTERNATE))) { GradientFillRoundedRectangle(context, bounds, 8, darkSelectedGradient, 2); } else { GradientFillRoundedRectangle(context, bounds, 8, darkInactiveGradient, 2); } HighlightButtonBorder(context, bounds); if ((state & TTK_STATE_SELECTED) || (state & TTK_STATE_ALTERNATE)) { CGContextSetStrokeColorSpace(context, deviceRGB.CGColorSpace); if (state & TTK_STATE_DISABLED) { fill = [NSColor disabledControlTextColor]; } else { |
︙ | ︙ | |||
597 598 599 600 601 602 603 | components: darkDisabledButtonFace count: 4]; } else { faceColor = [NSColor colorWithColorSpace: deviceRGB components: darkButtonFace count: 4]; } | | | 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 | components: darkDisabledButtonFace count: 4]; } else { faceColor = [NSColor colorWithColorSpace: deviceRGB components: darkButtonFace count: 4]; } SolidFillRoundedRectangle(context, bounds, 4, faceColor); /* * Draw a separator line on the left side of the tab if it * not first. */ if (!(state & TTK_STATE_FIRST_TAB)) { |
︙ | ︙ | |||
631 632 633 634 635 636 637 | * always drawn last.) */ if ((state & TTK_STATE_FIRST_TAB) && !(state & TTK_STATE_LAST_TAB)) { bounds.size.width += 1; } if (!(state & TTK_STATE_BACKGROUND)) { | > | | | 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 | * always drawn last.) */ if ((state & TTK_STATE_FIRST_TAB) && !(state & TTK_STATE_LAST_TAB)) { bounds.size.width += 1; } if (!(state & TTK_STATE_BACKGROUND)) { GradientFillRoundedRectangle(context, bounds, 4, darkSelectedGradient, 2); } else { faceColor = [NSColor colorWithColorSpace: deviceRGB components: darkInactiveSelectedTab count: 4]; SolidFillRoundedRectangle(context, bounds, 4, faceColor); } HighlightButtonBorder(context, bounds); } } /* * DrawDarkSeparator -- |
︙ | ︙ | |||
679 680 681 682 683 684 685 | ThemeMetric heightMetric; } ThemeButtonParams; static ThemeButtonParams PushButtonParams = { kThemePushButton, kThemeMetricPushButtonHeight }, CheckBoxParams = { kThemeCheckBox, kThemeMetricCheckBoxHeight }, RadioButtonParams = { kThemeRadioButton, kThemeMetricRadioButtonHeight }, | | > | 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 | ThemeMetric heightMetric; } ThemeButtonParams; static ThemeButtonParams PushButtonParams = { kThemePushButton, kThemeMetricPushButtonHeight }, CheckBoxParams = { kThemeCheckBox, kThemeMetricCheckBoxHeight }, RadioButtonParams = { kThemeRadioButton, kThemeMetricRadioButtonHeight }, BevelButtonParams = { kThemeRoundedBevelButton, NoThemeMetric }, PopupButtonParams = { kThemePopupButton, kThemeMetricPopupButtonHeight }, DisclosureParams = { kThemeDisclosureButton, kThemeMetricDisclosureTriangleHeight }, ListHeaderParams = { kThemeListHeaderButton, kThemeMetricListHeaderHeight }; static Ttk_StateTable ButtonValueTable[] = { { kThemeButtonMixed, TTK_STATE_ALTERNATE, 0 }, { kThemeButtonOn, TTK_STATE_SELECTED, 0 }, { kThemeButtonOff, 0, 0 } /* Others: kThemeDisclosureRight, kThemeDisclosureDown, kThemeDisclosureLeft */ }; static Ttk_StateTable ButtonAdornmentTable[] = { { kThemeAdornmentDefault | kThemeAdornmentFocus, TTK_STATE_ALTERNATE | TTK_STATE_FOCUS, 0 }, { kThemeAdornmentDefault, TTK_STATE_ALTERNATE, 0 }, { kThemeAdornmentNone, TTK_STATE_ALTERNATE, 0 }, { kThemeAdornmentFocus, TTK_STATE_FOCUS, 0 }, { kThemeAdornmentNone, 0, 0 }}; /* * computeButtonDrawInfo -- * Fill in an appearance manager HIThemeButtonDrawInfo record. */ |
︙ | ︙ | |||
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | void *clientData, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { ThemeButtonParams *params = clientData; const HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, 0, tkwin); static const CGRect scratchBounds = {{0, 0}, {100, 100}}; CGRect contentBounds; ButtonElementSizeNoPadding( clientData, elementRecord, tkwin, widthPtr, heightPtr, paddingPtr); /* * To compute internal padding, query the appearance manager * for the content bounds of a dummy rectangle, then use * the difference as the padding. */ ChkErr(HIThemeGetButtonContentBounds, &scratchBounds, &info, &contentBounds); | > > > > | > | > > > > > | 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 | void *clientData, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { ThemeButtonParams *params = clientData; const HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, 0, tkwin); static const CGRect scratchBounds = {{0, 0}, {100, 100}}; CGRect contentBounds; int verticalPad; ButtonElementSizeNoPadding( clientData, elementRecord, tkwin, widthPtr, heightPtr, paddingPtr); /* * To compute internal padding, query the appearance manager * for the content bounds of a dummy rectangle, then use * the difference as the padding. */ ChkErr(HIThemeGetButtonContentBounds, &scratchBounds, &info, &contentBounds); CGRect backgroundBounds; ChkErr(HIThemeGetButtonBackgroundBounds, &scratchBounds, &info, &backgroundBounds); paddingPtr->left = contentBounds.origin.x - backgroundBounds.origin.x; paddingPtr->right = CGRectGetMaxX(backgroundBounds) - CGRectGetMaxX(contentBounds); verticalPad = contentBounds.origin.y - backgroundBounds.origin.y; verticalPad += CGRectGetMaxY(backgroundBounds) - CGRectGetMaxY(contentBounds); paddingPtr->top = verticalPad /2; paddingPtr->bottom = verticalPad - paddingPtr->top; } static void ButtonElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { BEGIN_DRAWING(d) |
︙ | ︙ | |||
813 814 815 816 817 818 819 | * inconsistent behavior. We work around this by filling behind an * inactive PopupButton with a white color before asking HIToolbox to * draw it. PopupButton. For PushButtons, we simply draw them in the * active state. */ if (info.kind == kThemePopupButton && (state & TTK_STATE_BACKGROUND)) { CGRect innerBounds = CGRectInset(bounds, 1, 1); | > | > > > > > > > > > > > | 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 | * inconsistent behavior. We work around this by filling behind an * inactive PopupButton with a white color before asking HIToolbox to * draw it. PopupButton. For PushButtons, we simply draw them in the * active state. */ if (info.kind == kThemePopupButton && (state & TTK_STATE_BACKGROUND)) { CGRect innerBounds = CGRectInset(bounds, 1, 1); NSColor *white = [NSColor whiteColor]; SolidFillRoundedRectangle(dc.context, innerBounds, 4, white); } /* * A BevelButton with mixed value is drawn borderless, which does make * much sense for us. */ if (info.kind == kThemeRoundedBevelButton && info.value == kThemeButtonMixed) { info.value = kThemeButtonOff; info.state = kThemeStateInactive; } ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); } END_DRAWING } static Ttk_ElementSpec ButtonElementSpec = { |
︙ | ︙ | |||
1305 1306 1307 1308 1309 1310 1311 | components: darkTrack count: 4]; if (orientation == TTK_ORIENT_HORIZONTAL) { bounds = CGRectInset(bounds, 1, bounds.size.height/2 - 2); } else { bounds = CGRectInset(bounds, bounds.size.width/2 - 3, 2); } | | | 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 | components: darkTrack count: 4]; if (orientation == TTK_ORIENT_HORIZONTAL) { bounds = CGRectInset(bounds, 1, bounds.size.height/2 - 2); } else { bounds = CGRectInset(bounds, bounds.size.width/2 - 3, 2); } SolidFillRoundedRectangle(dc.context, bounds, 2, trackColor); } #endif ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation); END_DRAWING } static Ttk_ElementSpec TrackElementSpec = { |
︙ | ︙ | |||
1427 1428 1429 1430 1431 1432 1433 | components: darkTrack count: 4]; if (orientation == TTK_ORIENT_HORIZONTAL) { bounds = CGRectInset(bounds, 1, bounds.size.height/2 - 3); } else { bounds = CGRectInset(bounds, bounds.size.width/2 - 3, 1); } | | | 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 | components: darkTrack count: 4]; if (orientation == TTK_ORIENT_HORIZONTAL) { bounds = CGRectInset(bounds, 1, bounds.size.height/2 - 3); } else { bounds = CGRectInset(bounds, bounds.size.width/2 - 3, 1); } SolidFillRoundedRectangle(dc.context, bounds, 3, trackColor); } #endif ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation); END_DRAWING } static Ttk_ElementSpec PbarElementSpec = { |
︙ | ︙ |