CPBox: Default custom boxes to clear fill unless set

Previously, a custom box without a fill drew a black rectangle under
Aristo3 because its fill fell back to the theme's background-color—
which Aristo3 supplies as a CSS color that the custom box's drawing
canvas cannot paint.

Matching AppKit, a custom box now defaults to a clear fill while
retaining any fill set explicitly or decoded from an archive, using a
new private -_hasOwnValueForThemeAttribute: helper to distinguish
the two cases.
This commit is contained in:
David Richardson committed 2026-11-25 09:18:51 -06:00
1 parent 4f33729e69
commit 63187a1af1
3 files changed
+74

No files matched your search

+9
View File
@@ -363,6 +363,15 @@ CPBelowBottom = 6;
// MARK: fillColor
- (CPColor)fillColor
{
/*
A custom box has no fill unless one was set, as in AppKit, where fillColor is clear by
default for NSBoxCustom. A custom box without a fill took the theme's fill for primary
boxes. Aristo3 gives that fill as a CSS colour, which the canvas of a custom box cannot
paint, so the box filled black. 2026-11-25
*/
if (_boxType === CPBoxCustom && ![self _hasOwnValueForThemeAttribute:@"background-color"])
return [CPColor clearColor];
return [self valueForThemeAttribute:@"background-color"];
}
+12
View File
@@ -411,6 +411,18 @@ var NULL_THEME = {};
return (_themeAttributes && _themeAttributes[aName] !== undefined);
}
/*
Returns YES when the receiver has a value of its own for the theme attribute aName, in any
state: a value set with -setValue:forThemeAttribute: and its variants, or decoded with the
receiver. Returns NO when every value comes from the theme or the class default.
*/
- (BOOL)_hasOwnValueForThemeAttribute:(CPString)aName
{
var themeAttr = _themeAttributes && _themeAttributes[aName];
return !!themeAttr && [themeAttr hasValues];
}
/*!
Registers theme values encoded in an array at runtime. The format of the data in the array
is the same as that used by ThemeDescriptors.j, with the exception that you need to use
+53
View File
@@ -111,4 +111,57 @@
[self assert:[] equals:warnings];
}
// MARK: - Fill of a custom box
/*
As in AppKit, a custom box has no fill unless one was set: fillColor is clear by default for
NSBoxCustom. A primary box keeps the theme's fill.
*/
- (void)testACustomBoxWithoutAFillHasNoFill
{
[box setBoxType:CPBoxCustom];
[box setBorderType:CPNoBorder];
[self assertTrue:[[box fillColor] isEqual:[CPColor clearColor]] message:@"a custom box without a fill has the clear colour"];
}
- (void)testACustomBoxWithALineBorderAndNoFillHasNoFill
{
[box setBoxType:CPBoxCustom];
[box setBorderType:CPLineBorder];
[self assertTrue:[[box fillColor] isEqual:[CPColor clearColor]] message:@"a custom box with a line border and no fill has the clear colour"];
}
- (void)testACustomBoxKeepsAFillThatWasSet
{
[box setBoxType:CPBoxCustom];
[box setBorderType:CPLineBorder];
[box setFillColor:[CPColor redColor]];
[self assertTrue:[[box fillColor] isEqual:[CPColor redColor]] message:@"a custom box keeps its fill"];
}
- (void)testArchivingKeepsTheFillOfACustomBox
{
[box setBoxType:CPBoxCustom];
[box setBorderType:CPLineBorder];
[box setFillColor:[CPColor redColor]];
[self assertTrue:[[[self archivedBox] fillColor] isEqual:[CPColor redColor]] message:@"a decoded custom box keeps its fill"];
}
- (void)testArchivingKeepsACustomBoxWithoutAFill
{
[box setBoxType:CPBoxCustom];
[box setBorderType:CPNoBorder];
[self assertTrue:[[[self archivedBox] fillColor] isEqual:[CPColor clearColor]] message:@"a decoded custom box without a fill has the clear colour"];
}
- (void)testAPrimaryBoxKeepsTheThemeFill
{
[self assertTrue:[box fillColor] === [box valueForThemeAttribute:@"background-color"] message:@"a primary box takes the theme's fill"];
}
@end