CPToolbar: Separate item label styling from behavior via theme descriptors

Toolbar item labels hardcoded fixed colors and shadows across init,
FIXME_setIsHUD:, and setHighlighted:, coupling presentation to view
behavior and ignoring the active theme and appearance. As a result,
labels on dark backgrounds were unreadable.

_CPToolbarView now declares label-color, label-font, label-shadow-color,
and label-shadow-offset theme attributes, which _CPToolbarItemView reads
for its current theme state during layout. Disabled items now dim only
their image while rendering the label at full opacity using the
state-specific theme color.

The FIXME_setIsHUD: path is removed from _CPToolbarView,
_CPToolbarItemView, and _CPWindowView, as CPThemeStateHUD already
propagates to every view in a HUD window.

Aristo, Aristo2, and Aristo3 register disabled and HUD label colors in
their theme descriptors. Dark mode values will follow its theme
descriptor clean-up.
This commit is contained in:
David Richardson committed 2026-11-18 14:30:18 -06:00
1 parent 886f50fc88
commit d2d67042fd
6 files changed
+133 -66

No files matched your search

+31 -62
View File
@@ -653,12 +653,8 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
CPArray _invisibleItems;
CPPopUpButton _additionalItemsButton;
CPColor _labelColor;
CPColor _labelShadowColor;
float _minWidth;
BOOL _FIXME_isHUD;
}
+ (CPString)defaultThemeClass
@@ -678,6 +674,10 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
@"small-size-height": 46.0,
@"image-item-separator-color": [CPNull null],
@"image-item-separator-size": CGRectMake(0.0, 0.0, 2.0, 32.0),
@"label-color": [CPColor labelColor],
@"label-font": [CPFont systemFontOfSize:11.0],
@"label-shadow-color": [CPNull null],
@"label-shadow-offset": CGSizeMakeZero(),
};
}
@@ -689,9 +689,6 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
{
_minWidth = 0;
_labelColor = [CPColor blackColor];
_labelShadowColor = [CPColor colorWithWhite:1.0 alpha:0.75];
_additionalItemsButton = [[CPPopUpButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 10.0, 15.0) pullsDown:YES];
[_additionalItemsButton setBordered:NO];
@@ -713,20 +710,6 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
return _toolbar;
}
- (void)FIXME_setIsHUD:(BOOL)shouldBeHUD
{
if (_FIXME_isHUD === shouldBeHUD)
return;
_FIXME_isHUD = shouldBeHUD;
var items = [_toolbar items],
count = [items count];
while (count--)
[[self viewForItem:items[count]] FIXME_setIsHUD:shouldBeHUD];
}
// This *should* be roughly O(3N) = O(N)
- (void)resizeSubviewsWithOldSize:(CGSize)aSize
{
@@ -775,7 +758,6 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
[invisibleItemsSortedByPriority addObject:item];
[view setHidden:YES];
[view FIXME_setIsHUD:_FIXME_isHUD];
}
}
@@ -1056,8 +1038,6 @@ var LABEL_MARGIN = 2.0;
CPView _highlightView;
CPTextField _labelField;
BOOL _FIXME_isHUD;
}
- (BOOL)acceptsFirstResponder
@@ -1086,10 +1066,11 @@ var LABEL_MARGIN = 2.0;
_labelField = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[_labelField setFont:[CPFont systemFontOfSize:11.0]];
[_labelField setTextColor:[self FIXME_labelColor]];
[_labelField setTextShadowColor:[self FIXME_labelShadowColor]];
[_labelField setTextShadowOffset:CGSizeMake(0.0, 1.0)];
/*
The font sets the label size, which -updateFromItem measures below, before the
toolbar view is assigned. Colour and shadow follow in -layoutSubviews.
*/
[_labelField setFont:[aToolbar valueForThemeAttribute:@"label-font" inState:[self themeState]]];
[_labelField setAutoresizingMask:CPViewWidthSizable | CPViewMinXMargin];
[self addSubview:_labelField];
@@ -1125,13 +1106,6 @@ var LABEL_MARGIN = 2.0;
[_toolbarItem removeObserver:self forKeyPath:_CPToolbarItemViewObservedKeyPaths[index]];
}
- (void)FIXME_setIsHUD:(BOOL)shouldBeHUD
{
_FIXME_isHUD = shouldBeHUD;
[_labelField setTextColor:[self FIXME_labelColor]];
[_labelField setTextShadowColor:[self FIXME_labelShadowColor]];
}
- (void)updateFromItem
{
var identifier = [_toolbarItem itemIdentifier];
@@ -1191,6 +1165,9 @@ var LABEL_MARGIN = 2.0;
var minSize = [_toolbarItem minSize],
maxSize = [_toolbarItem maxSize];
if (_toolbar)
[_labelField setFont:[_toolbar valueForThemeAttribute:@"label-font" inState:[self themeState]]];
[_labelField setStringValue:[_toolbarItem label]];
[_labelField sizeToFit]; // FIXME
@@ -1244,6 +1221,8 @@ var LABEL_MARGIN = 2.0;
viewWidth,
viewHeight)];
[self _layoutLabelAppearance];
// Label is always drawn at the bottom of the view. So if the view is really tall but the icon is tiny, the icon is centred above the label while the label remains on the bottom.
[_labelField setFrameOrigin:CGPointMake(ROUND((width - _labelSize.width) / 2.0), CGRectGetHeight(bounds) - _labelSize.height)];
}
@@ -1271,34 +1250,29 @@ var LABEL_MARGIN = 2.0;
[super setEnabled:shouldBeEnabled];
if (shouldBeEnabled)
{
[_imageView setAlphaValue:1.0];
[_labelField setAlphaValue:1.0];
}
else
{
[_imageView setAlphaValue:0.5];
[_labelField setAlphaValue:0.5];
}
/*
The label takes its disabled look from the toolbar view's theme in -layoutSubviews.
*/
[_imageView setAlphaValue:shouldBeEnabled ? 1.0 : 0.5];
[_toolbar tile];
}
- (CPColor)FIXME_labelColor
/*
Applies the label colour and shadow of the toolbar view's theme for the receiver's state:
highlighted, disabled, and HUD in a HUD window.
Labels had black text and a white shadow, hard-coded in this class, so they ignored the
theme and the appearance; the shadow was wrong in dark mode. The values now come from the
toolbar view's theme attributes, applied in layout, and no theme gives a shadow.
*/
- (void)_layoutLabelAppearance
{
if (_FIXME_isHUD)
return [CPColor whiteColor];
var state = [self themeState];
return [CPColor blackColor];
}
- (CPColor)FIXME_labelShadowColor
{
if (_FIXME_isHUD)
return [self isHighlighted] ? [CPColor colorWithWhite:1.0 alpha:0.5] : [CPColor clearColor];
return [self isHighlighted] ? [CPColor colorWithWhite:0.0 alpha:0.3] : [CPColor colorWithWhite:1.0 alpha:0.75];
[_labelField setTextColor:[_toolbar valueForThemeAttribute:@"label-color" inState:state]];
[_labelField setTextShadowColor:[_toolbar valueForThemeAttribute:@"label-shadow-color" inState:state]];
[_labelField setTextShadowOffset:[_toolbar valueForThemeAttribute:@"label-shadow-offset" inState:state]];
}
- (void)setHighlighted:(BOOL)shouldBeHighlighted
@@ -1324,7 +1298,6 @@ var LABEL_MARGIN = 2.0;
[_imageView addSubview:_highlightView];
}
[_labelField setTextShadowOffset:CGSizeMakeZero()];
}
else
{
@@ -1334,11 +1307,7 @@ var LABEL_MARGIN = 2.0;
[_imageView setImage:image];
[_highlightView removeFromSuperview];
[_labelField setTextShadowOffset:CGSizeMake(0.0, 1.0)];
}
[_labelField setTextShadowColor:[self FIXME_labelShadowColor]];
}
- (BOOL)sendAction:(SEL)anAction to:(id)aSender
-1
View File
@@ -1114,7 +1114,6 @@ function _CPWindowViewSetCornerRadii(aDOMElement, someRadii)
if (toolbarView)
{
[toolbarView removeFromSuperview];
[toolbarView FIXME_setIsHUD:_styleMask & CPHUDBackgroundWindowMask];
[self addSubview:toolbarView];
}
+4 -1
View File
@@ -3489,7 +3489,10 @@ function ButtonBarImageAction()
[@"regular-size-height", 59.0],
[@"small-size-height", 46.0],
[@"image-item-separator-color", toolbarSeparatorColor],
[@"image-item-separator-size", CGRectMake(0.0, 0.0, 2.0, 32.0)]
[@"image-item-separator-size", CGRectMake(0.0, 0.0, 2.0, 32.0)],
[@"label-color", [CPColor disabledControlTextColor], CPThemeStateDisabled],
[@"label-color", [CPColor whiteColor], CPThemeStateHUD],
[@"label-color", [CPColor colorWithWhite:1.0 alpha:0.5], [CPThemeStateHUD, CPThemeStateDisabled]]
];
+4 -1
View File
@@ -2976,7 +2976,10 @@ function ButtonBarImageAction()
[@"regular-size-height", 59.0],
[@"small-size-height", 46.0],
[@"image-item-separator-color", toolbarSeparatorColor],
[@"image-item-separator-size", CGRectMake(0.0, 0.0, 2.0, 32.0)]
[@"image-item-separator-size", CGRectMake(0.0, 0.0, 2.0, 32.0)],
[@"label-color", [CPColor disabledControlTextColor], CPThemeStateDisabled],
[@"label-color", [CPColor whiteColor], CPThemeStateHUD],
[@"label-color", [CPColor colorWithWhite:1.0 alpha:0.5], [CPThemeStateHUD, CPThemeStateDisabled]]
];
+4 -1
View File
@@ -9476,7 +9476,10 @@ function A3MaskIcon(aMaskImage, aColor)
[@"regular-size-height", 59.0],
[@"small-size-height", 46.0],
[@"image-item-separator-color", toolbarSeparatorColor],
[@"image-item-separator-size", CGRectMake(0.0, 0.0, 2.0, 32.0)]
[@"image-item-separator-size", CGRectMake(0.0, 0.0, 2.0, 32.0)],
[@"label-color", [CPColor disabledControlTextColor], CPThemeStateDisabled],
[@"label-color", [CPColor whiteColor], CPThemeStateHUD],
[@"label-color", [CPColor colorWithWhite:1.0 alpha:0.5], [CPThemeStateHUD, CPThemeStateDisabled]]
];
+90
View File
@@ -224,4 +224,94 @@ var ToolbarTestMakeViewItem = function(aTarget)
[self assertTrue:[discardedItemView isEnabled] message:@"a discarded item view must no longer follow its item"];
}
/*
Returns the toolbar view and the view of the first item of a new toolbar.
*/
- (CPArray)toolbarViewAndItemView
{
var delegate = [_ToolbarTestDelegate new],
toolbar = [[CPToolbar alloc] initWithIdentifier:@"CPToolbarTestLabel"];
[toolbar setDelegate:delegate];
var toolbarView = [toolbar _toolbarView];
return [toolbarView, [toolbarView viewForItem:[toolbar items][0]]];
}
- (void)testNoThemeGivesToolbarLabelsAShadow
{
var toolbarView = [self toolbarViewAndItemView][0];
[self assertNull:[toolbarView valueForThemeAttribute:@"label-shadow-color" inState:CPThemeStateNormal]];
[self assertNull:[toolbarView valueForThemeAttribute:@"label-shadow-color" inState:CPThemeStateHighlighted]];
}
- (void)testALabelTakesTheLabelColorOfTheToolbarView
{
var views = [self toolbarViewAndItemView],
color = [CPColor redColor];
[views[0] setValue:color forThemeAttribute:@"label-color"];
[views[1] layoutSubviews];
[self assert:color same:[views[1]._labelField textColor]];
}
- (void)testADisabledItemTakesTheDisabledLabelColorAtFullOpacity
{
var views = [self toolbarViewAndItemView],
color = [CPColor blueColor];
[views[0] setValue:[CPColor redColor] forThemeAttribute:@"label-color"];
[views[0] setValue:color forThemeAttribute:@"label-color" inState:CPThemeStateDisabled];
[views[1] setEnabled:NO];
[views[1] layoutSubviews];
[self assert:color same:[views[1]._labelField textColor]];
[self assert:1.0 equals:[views[1]._labelField alphaValue]];
}
- (void)testAnItemInAHUDWindowTakesTheHUDLabelColor
{
var views = [self toolbarViewAndItemView],
color = [CPColor greenColor];
[views[0] setValue:color forThemeAttribute:@"label-color" inState:CPThemeStateHUD];
[views[1] setThemeState:CPThemeStateHUD];
[views[1] layoutSubviews];
[self assert:color same:[views[1]._labelField textColor]];
}
- (void)testAHighlightedItemTakesTheHighlightedLabelShadow
{
var views = [self toolbarViewAndItemView],
color = [CPColor redColor],
offset = CGSizeMake(0.0, 2.0);
[views[0] setValue:color forThemeAttribute:@"label-shadow-color" inState:CPThemeStateHighlighted];
[views[0] setValue:offset forThemeAttribute:@"label-shadow-offset" inState:CPThemeStateHighlighted];
/*
The test item has a custom view, which never takes the highlight: -mouseDown: passes the
click on. The label depends only on the highlighted theme state, so the test sets it.
*/
[views[1] setThemeState:CPThemeStateHighlighted];
[views[1] layoutSubviews];
[self assert:color same:[views[1]._labelField textShadowColor]];
[self assertTrue:CGSizeEqualToSize(offset, [views[1]._labelField textShadowOffset])];
}
- (void)testALabelTakesTheLabelFontOfTheToolbarView
{
var views = [self toolbarViewAndItemView],
font = [CPFont boldSystemFontOfSize:13.0];
[views[0] setValue:font forThemeAttribute:@"label-font"];
[views[1] updateFromItem];
[self assert:font same:[views[1]._labelField font]];
}
@end