Skip to content

Commit

Permalink
Sixth step to migrate tonal color scheme bundles to use per-state con…
Browse files Browse the repository at this point in the history
…tainer tokens

Convert existing tonal skins to use container token APIs, and remove the old ones

For #400
  • Loading branch information
kirill-grouchnikov committed Jan 6, 2025
1 parent eb4c985 commit 0fb1a28
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,13 @@ public SampleSkin(RadianceColorScheme accentScheme) {

RadianceColorSchemeBundle2 bundle2 = new RadianceColorSchemeBundle2(lightColorScheme);

RadianceColorScheme2 lightMarkColorScheme =
ColorSchemeUtils.getLightTonalBalancedColorScheme(Hct.fromInt(0xFF20F490), 8.0, 6.0);

bundle2.registerColorScheme(lightMarkColorScheme,
bundle2.registerContainerTokens(
ColorSchemeUtils.getLightTonalFidelityContainerTokens(Hct.fromInt(0xFF20F490)),
RadianceThemingSlices.ContainerColorTokensAssociationKind.MARK,
ComponentState.getActiveStates());

RadianceColorScheme2 lightHighlightColorScheme =
ColorSchemeUtils.getLightTonalBalancedColorScheme(Hct.fromInt(0xFF20F490), 8.0, 6.0);

bundle2.registerColorScheme(lightHighlightColorScheme,
bundle2.registerContainerTokens(
ColorSchemeUtils.getLightTonalFidelityContainerTokens(Hct.fromInt(0xFF20F490)),
RadianceThemingSlices.ContainerColorTokensAssociationKind.HIGHLIGHT,
ComponentState.getActiveStates());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.pushingpixels.radiance.theming.api.painter.overlay.BottomLineOverlayPainter;
import org.pushingpixels.radiance.theming.api.painter.overlay.BottomLineTonalOverlayPainter;
import org.pushingpixels.radiance.theming.api.palette.ColorSchemeUtils;
import org.pushingpixels.radiance.theming.api.palette.ContainerColorTokens;
import org.pushingpixels.radiance.theming.api.palette.RadianceColorScheme2;
import org.pushingpixels.radiance.theming.api.palette.TonalSkin;
import org.pushingpixels.radiance.theming.api.shaper.ClassicButtonShaper;
Expand Down Expand Up @@ -282,37 +283,37 @@ public OfficeSilver2007TonalSkin() {
RadianceColorSchemeBundle2 officeSilverDefaultBundle =
new RadianceColorSchemeBundle2(officeSilverColorScheme);

RadianceColorScheme2 rolloverScheme2 = ColorSchemeUtils.getLightTonalFidelityColorScheme(
Hct.fromInt(0xFFFFD111), Hct.fromInt(0xFFE6EAEE), Hct.fromInt(0xFFF2F5F5));
RadianceColorScheme2 selectedScheme2 = ColorSchemeUtils.getLightTonalFidelityColorScheme(
Hct.fromInt(0xFFFFBD51), Hct.fromInt(0xFFE6EAEE), Hct.fromInt(0xFFF2F5F5));
RadianceColorScheme2 rolloverSelectedScheme2 = ColorSchemeUtils.getLightTonalFidelityColorScheme(
Hct.fromInt(0xFFFFA400), Hct.fromInt(0xFFE6EAEE), Hct.fromInt(0xFFF2F5F5));
RadianceColorScheme2 pressedScheme2 = ColorSchemeUtils.getLightTonalFidelityColorScheme(
Hct.fromInt(0xFFFF8C18), Hct.fromInt(0xFFE6EAEE), Hct.fromInt(0xFFF2F5F5));
RadianceColorScheme2 pressedSelectedScheme2 = ColorSchemeUtils.getLightTonalFidelityColorScheme(
Hct.fromInt(0xFFFF991C), Hct.fromInt(0xFFE6EAEE), Hct.fromInt(0xFFF2F5F5));
ContainerColorTokens rolloverContainerTokens =
ColorSchemeUtils.getLightTonalFidelityContainerTokens(Hct.fromInt(0xFFFFD111));
ContainerColorTokens selectedContainerTokens =
ColorSchemeUtils.getLightTonalFidelityContainerTokens(Hct.fromInt(0xFFFFBD51));
ContainerColorTokens rolloverSelectedContainerTokens =
ColorSchemeUtils.getLightTonalFidelityContainerTokens(Hct.fromInt(0xFFFFA400));
ContainerColorTokens pressedContainerTokens =
ColorSchemeUtils.getLightTonalFidelityContainerTokens(Hct.fromInt(0xFFFF8C18));
ContainerColorTokens pressedSelectedContainerTokens =
ColorSchemeUtils.getLightTonalFidelityContainerTokens(Hct.fromInt(0xFFFF991C));

// register state-specific color schemes on rollovers, presses and selections
officeSilverDefaultBundle.registerColorScheme(rolloverScheme2,
officeSilverDefaultBundle.registerContainerTokens(rolloverContainerTokens,
ComponentState.ROLLOVER_UNSELECTED);
officeSilverDefaultBundle.registerColorScheme(rolloverSelectedScheme2,
officeSilverDefaultBundle.registerContainerTokens(rolloverSelectedContainerTokens,
ComponentState.ROLLOVER_SELECTED);
officeSilverDefaultBundle.registerColorScheme(selectedScheme2,
officeSilverDefaultBundle.registerContainerTokens(selectedContainerTokens,
ComponentState.SELECTED);
officeSilverDefaultBundle.registerColorScheme(pressedScheme2,
officeSilverDefaultBundle.registerContainerTokens(pressedContainerTokens,
ComponentState.PRESSED_UNSELECTED);
officeSilverDefaultBundle.registerColorScheme(pressedSelectedScheme2,
officeSilverDefaultBundle.registerContainerTokens(pressedSelectedContainerTokens,
ComponentState.PRESSED_SELECTED);

// register state-specific highlight color schemes on rollover and selections
officeSilverDefaultBundle.registerColorScheme(rolloverScheme2,
officeSilverDefaultBundle.registerContainerTokens(rolloverContainerTokens,
RadianceThemingSlices.ContainerColorTokensAssociationKind.HIGHLIGHT,
ComponentState.ROLLOVER_UNSELECTED);
officeSilverDefaultBundle.registerColorScheme(selectedScheme2,
officeSilverDefaultBundle.registerContainerTokens(selectedContainerTokens,
RadianceThemingSlices.ContainerColorTokensAssociationKind.HIGHLIGHT,
ComponentState.SELECTED, ComponentState.ARMED, ComponentState.ROLLOVER_ARMED);
officeSilverDefaultBundle.registerColorScheme(rolloverSelectedScheme2,
officeSilverDefaultBundle.registerContainerTokens(rolloverSelectedContainerTokens,
RadianceThemingSlices.ContainerColorTokensAssociationKind.HIGHLIGHT,
ComponentState.ROLLOVER_SELECTED);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,54 +88,51 @@ public RadianceColorSchemeBundle2(RadianceColorScheme2 mainColorScheme) {
}

/**
* Registers a color scheme for the specific component state.
* Registers container color tokens for the specific active component states.
*
* @param stateColorScheme Color scheme for the specified component state.
* @param states Component states.
* @param stateContainerTokens Container color tokens for the specified active component states.
* @param activeStates Component states.
*/
public void registerColorScheme(RadianceColorScheme2 stateColorScheme, ComponentState... states) {
this.registerColorScheme(stateColorScheme,
public void registerContainerTokens(ContainerColorTokens stateContainerTokens,
ComponentState... activeStates) {
this.registerContainerTokens(stateContainerTokens,
RadianceThemingSlices.ContainerColorTokensAssociationKind.DEFAULT,
states);
activeStates);
}

/**
* Registers the color scheme to be used for the specified visual area of
* controls under the specified states. For example, if the light orange
* scheme has to be used for gradient fill for rollover selected and rollover
* controls, the parameters would be:
* Registers the container color tokens to be used for controls in specified active states.
* For example, if light orange color tokens are to be used for rollover selected and rollover
* controls in highlights, the parameters would be:
*
* <ul>
* <li><code>scheme</code>=light orange scheme</li>
* <li>
* <code>associationKind</code>={@link RadianceThemingSlices.ColorSchemeAssociationKind#FILL}</li>
* <li>
* <code>states</code>={@link ComponentState#ROLLOVER_SELECTED},
* {@link ComponentState#ROLLOVER_UNSELECTED}</li>
* <li><code>stateContainerTokens</code>=light orange color tokens</li>
* <li><code>associationKind</code>={@link RadianceThemingSlices.ContainerColorTokensAssociationKind#HIGHLIGHT}</li>
* <li><code>states</code>={@link ComponentState#ROLLOVER_SELECTED}, {@link ComponentState#ROLLOVER_UNSELECTED}</li>
* </ul>
*
* @param scheme Color scheme.
* @param stateContainerTokens Container color tokens for the specified active component states.
* @param associationKind Color scheme association kind that specifies the visual areas
* of controls to be painted with this color scheme.
* @param states Component states that further restrict the usage of the
* @param activeStates Component states that further restrict the usage of the
* specified color scheme.
*/
public void registerColorScheme(RadianceColorScheme2 scheme,
public void registerContainerTokens(ContainerColorTokens stateContainerTokens,
RadianceThemingSlices.ContainerColorTokensAssociationKind associationKind,
ComponentState... states) {
if (scheme == null) {
throw new IllegalArgumentException("Cannot pass null color scheme");
ComponentState... activeStates) {
if (stateContainerTokens == null) {
throw new IllegalArgumentException("Cannot pass null color tokens");
}

if ((states == null) || (states.length == 0)) {
if ((activeStates == null) || (activeStates.length == 0)) {
throw new IllegalArgumentException("Must pass at least one state");
}

for (ComponentState state : states) {
for (ComponentState state : activeStates) {
if (state.isDisabled() || !state.isActive()) {
throw new IllegalArgumentException("Only active states can have custom color schemes");
}
this.colorTokensForActiveStates.get(associationKind).put(state, scheme.getActiveContainerTokens());
this.colorTokensForActiveStates.get(associationKind).put(state, stateContainerTokens);
}
}

Expand Down Expand Up @@ -190,16 +187,17 @@ public RadianceColorScheme2 getMainColorScheme() {
}

/**
* Returns the color scheme to be used for painting the specified visual
* area of the component under the specified component state.
* Returns the color tokens to be used for painting components under the specified component
* state.
*
* @param associationKind Color scheme association kind.
* @param componentState Component state.
* @param allowFallback If true, this method will return a color scheme for the fallback
* @param allowFallback If true, this method will return color tokens for the fallback
* association kind.
* @return Color scheme to be used for painting the specified visual area of
* @return Color tokens to be used for painting the specified visual area of
* the component under the specified component state.
* @see #registerColorScheme(RadianceColorScheme2, ComponentState...)
* @see #registerContainerTokens(ContainerColorTokens, ComponentState...)
* @see #registerContainerTokens(ContainerColorTokens, RadianceThemingSlices.ContainerColorTokensAssociationKind, ComponentState...)
*/
public ContainerColorTokens getContainerTokens(
RadianceThemingSlices.ContainerColorTokensAssociationKind associationKind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ public RadianceColorScheme getWindowChromeAccent() {
public static abstract class TonalAccented extends RadianceSkin implements TonalSkin {
public final static class AccentBuilder {
private RadianceColorScheme2 windowChromeAccent;
private RadianceColorScheme2 windowChromeHighlightsAccent;
private ContainerColorTokens windowChromeHighlightsAccent;
private RadianceColorScheme2 enabledControlsAccent;
private RadianceColorScheme2 activeControlsAccent;
private RadianceColorScheme2 highlightsAccent;
private ContainerColorTokens highlightsAccent;
private RadianceColorScheme2 backgroundAccent;

public AccentBuilder() {
Expand All @@ -207,7 +207,7 @@ public AccentBuilder withWindowChromeAccent(RadianceColorScheme2 windowChromeAcc
return this;
}

public AccentBuilder withWindowChromeHighlightsAccent(RadianceColorScheme2 windowChromeHighlightsAccent) {
public AccentBuilder withWindowChromeHighlightsAccent(ContainerColorTokens windowChromeHighlightsAccent) {
this.windowChromeHighlightsAccent = windowChromeHighlightsAccent;
return this;
}
Expand All @@ -222,7 +222,7 @@ public AccentBuilder withEnabledControlsAccent(RadianceColorScheme2 enabledContr
return this;
}

public AccentBuilder withHighlightsAccent(RadianceColorScheme2 highlightsAccent) {
public AccentBuilder withHighlightsAccent(ContainerColorTokens highlightsAccent) {
this.highlightsAccent = highlightsAccent;
return this;
}
Expand All @@ -234,10 +234,10 @@ public AccentBuilder withBackgroundAccent(RadianceColorScheme2 backgroundAccent)
}

private final RadianceColorScheme2 windowChromeAccent;
private final RadianceColorScheme2 windowChromeHighlightsAccent;
private final ContainerColorTokens windowChromeHighlightsAccent;
private final RadianceColorScheme2 activeControlsAccent;
private final RadianceColorScheme2 enabledControlsAccent;
private final RadianceColorScheme2 highlightsAccent;
private final ContainerColorTokens highlightsAccent;
private final RadianceColorScheme2 backgroundAccent;

protected TonalAccented(AccentBuilder accentBuilder) {
Expand All @@ -261,15 +261,15 @@ public RadianceColorScheme2 getEnabledControlsAccent() {
return this.enabledControlsAccent;
}

public RadianceColorScheme2 getHighlightsAccent() {
public ContainerColorTokens getHighlightsAccent() {
return this.highlightsAccent;
}

public RadianceColorScheme2 getWindowChromeAccent() {
return this.windowChromeAccent;
}

public RadianceColorScheme2 getWindowChromeHighlightsAccent() {
public ContainerColorTokens getWindowChromeHighlightsAccent() {
return this.windowChromeHighlightsAccent;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,14 @@ public static ContainerColorTokens getLightTonalFidelityContainerTokens(Hct seed
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL);
}

public static ContainerColorTokens getLightTonalBalancedContainerTokens(Hct seed) {
return ColorSchemeUtils.getLightContainerTokens(
/* sourceColorHct */ seed,
/* isFidelity */ false,
/* palette */ TonalPalette.fromHct(seed),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL);
}

public static ContainerColorTokens tint(ContainerColorTokens original, float tintFactor) {
return new ContainerColorTokens() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected BusinessAccentedTonalSkin(AccentBuilder accentBuilder) {

RadianceColorSchemeBundle2 businessDefaultBundle =
new RadianceColorSchemeBundle2(this.getActiveControlsAccent());
businessDefaultBundle.registerColorScheme(this.getHighlightsAccent(),
businessDefaultBundle.registerContainerTokens(this.getHighlightsAccent(),
RadianceThemingSlices.ContainerColorTokensAssociationKind.HIGHLIGHT,
ComponentState.getActiveStates());
// TODO: TONAL tabs
Expand All @@ -72,7 +72,8 @@ protected BusinessAccentedTonalSkin(AccentBuilder accentBuilder) {
RadianceColorSchemeBundle2 businessDefaultHeaderBundle =
new RadianceColorSchemeBundle2(this.getWindowChromeAccent());
if (this.getWindowChromeHighlightsAccent() != null) {
businessDefaultHeaderBundle.registerColorScheme(this.getWindowChromeHighlightsAccent(),
businessDefaultHeaderBundle.registerContainerTokens(
this.getWindowChromeHighlightsAccent(),
RadianceThemingSlices.ContainerColorTokensAssociationKind.HIGHLIGHT,
ComponentState.getActiveStates());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,21 @@ public BusinessBlackSteelTonalSkin() {
super(new AccentBuilder()
.withWindowChromeAccent(ColorSchemeUtils.getDarkTonalFidelityColorScheme(
Hct.fromInt(0xFF404040), Hct.fromInt(0xFF565656), Hct.fromInt(0xFF616161)))
.withWindowChromeHighlightsAccent(ColorSchemeUtils.getLightTonalFidelityColorScheme(
Hct.fromInt(0xFF85A3B5), Hct.fromInt(0xFFC4C8CC), Hct.fromInt(0xFFE4EAF0)))
.withWindowChromeHighlightsAccent(ColorSchemeUtils.getLightTonalFidelityContainerTokens(
Hct.fromInt(0xFF85A3B5)))
.withActiveControlsAccent(ColorSchemeUtils.getLightTonalFidelityColorScheme(
Hct.fromInt(0xFF98B7CC), Hct.fromInt(0xFFC4C8CC), Hct.fromInt(0xFFE4EAF0)))
.withHighlightsAccent(ColorSchemeUtils.getLightTonalFidelityColorScheme(
Hct.fromInt(0xFFA1BCCF), Hct.fromInt(0xFFC4C8CC), Hct.fromInt(0xFFE4EAF0))));
.withHighlightsAccent(ColorSchemeUtils.getLightTonalFidelityContainerTokens(
Hct.fromInt(0xFFA1BCCF))));

RadianceColorScheme2 controlPaneColorScheme =
ColorSchemeUtils.getLightTonalFidelityColorScheme(Hct.fromInt(0xFFAFBEC7),
Hct.fromInt(0xFFD5DBDF), Hct.fromInt(0xFFD0D7DC));

RadianceColorSchemeBundle2 businessBlueSteelControlBundle =
new RadianceColorSchemeBundle2(controlPaneColorScheme);
businessBlueSteelControlBundle.registerColorScheme(
getActiveControlsAccent(),
businessBlueSteelControlBundle.registerContainerTokens(
getActiveControlsAccent().getActiveContainerTokens(),
RadianceThemingSlices.ContainerColorTokensAssociationKind.HIGHLIGHT,
ComponentState.getActiveStates());
this.registerDecorationAreaSchemeBundle(businessBlueSteelControlBundle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,21 @@ public BusinessBlueSteelTonalSkin() {
super(new AccentBuilder()
.withWindowChromeAccent(ColorSchemeUtils.getLightTonalFidelityColorScheme(
Hct.fromInt(0xFFA1BCD0), Hct.fromInt(0xFFC4C8CC), Hct.fromInt(0xFFE4EAF0)))
.withWindowChromeHighlightsAccent(ColorSchemeUtils.getLightTonalFidelityColorScheme(
Hct.fromInt(0xFF83AFCE), Hct.fromInt(0xFFC4C8CC), Hct.fromInt(0xFFE4EAF0)))
.withWindowChromeHighlightsAccent(ColorSchemeUtils.getLightTonalFidelityContainerTokens(
Hct.fromInt(0xFF83AFCE)))
.withActiveControlsAccent(ColorSchemeUtils.getLightTonalFidelityColorScheme(
Hct.fromInt(0xFF98B7CC), Hct.fromInt(0xFFC4C8CC), Hct.fromInt(0xFFE4EAF0)))
.withHighlightsAccent(ColorSchemeUtils.getLightTonalBalancedColorScheme(
Hct.fromInt(0xFFEBD296), 5.0, 2.0)));
.withHighlightsAccent(ColorSchemeUtils.getLightTonalBalancedContainerTokens(
Hct.fromInt(0xFFEBD296))));

RadianceColorScheme2 controlPaneColorScheme =
ColorSchemeUtils.getLightTonalFidelityColorScheme(Hct.fromInt(0xFF94B9D3),
Hct.fromInt(0xFFBFCFDB), Hct.fromInt(0xFFBFCFDB));

RadianceColorSchemeBundle2 businessBlueSteelControlBundle =
new RadianceColorSchemeBundle2(controlPaneColorScheme);
businessBlueSteelControlBundle.registerColorScheme(
getActiveControlsAccent(),
businessBlueSteelControlBundle.registerContainerTokens(
getActiveControlsAccent().getActiveContainerTokens(),
RadianceThemingSlices.ContainerColorTokensAssociationKind.HIGHLIGHT,
ComponentState.getActiveStates());
this.registerDecorationAreaSchemeBundle(businessBlueSteelControlBundle,
Expand Down
Loading

0 comments on commit 0fb1a28

Please sign in to comment.