Skip to content

Commit

Permalink
Fix animations on tonal radio buttons and checkboxes
Browse files Browse the repository at this point in the history
For #400
  • Loading branch information
kirill-grouchnikov committed Dec 6, 2024
1 parent a9726e6 commit 3f659fb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ private static class SimplisticSoftBorderReverseFillPainter extends FractionBase

private SimplisticSoftBorderReverseFillPainter() {
super("Simplistic Soft Border Reverse",
new float[] {0.0f, 0.5f, 1.0f},
new ColorSchemeSingleColorQuery[] {
ColorSchemeSingleColorQuery.ULTRALIGHT,
scheme -> RadianceColorUtilities.getInterpolatedColor(
scheme.getMidColor(), scheme.getUltraLightColor(), 0.5f),
ColorSchemeSingleColorQuery.MID
}
new float[] {0.0f, 0.5f, 1.0f},
new ColorSchemeSingleColorQuery[] {
ColorSchemeSingleColorQuery.ULTRALIGHT,
scheme -> RadianceColorUtilities.getInterpolatedColor(
scheme.getMidColor(), scheme.getUltraLightColor(), 0.5f),
ColorSchemeSingleColorQuery.MID
}
);
}
}
Expand Down Expand Up @@ -157,14 +157,12 @@ public static void drawCheckBox(Graphics2D g, JComponent component, RadianceFill
contourDim, contourDim,
cornerRadius, null, 0.0f);

RadianceFillPainter finalFillPainter = componentState.isActive() ? fillPainter
: SimplisticSoftBorderReverseFillPainter.INSTANCE;
graphics1X.setComposite(getAlphaComposite(alpha));
Shape contourFill = RadianceOutlineUtilities.getBaseOutline(
component.getComponentOrientation(),
contourDim + 1, contourDim + 1,
cornerRadius, null, 0.5f);
finalFillPainter.paintContourBackground(graphics1X, component,
fillPainter.paintContourBackground(graphics1X, component,
contourDim, contourDim,
contourFill, renderColorTokens);

Expand Down Expand Up @@ -292,10 +290,8 @@ public static void drawRadioButton(Graphics2D g, AbstractButton button, Radiance
int contourDim = scaledWidth;
Shape contourOuter = new Ellipse2D.Float(0.0f, 0.0f, contourDim, contourDim);

RadianceFillPainter finalFillPainter = componentState.isActive() ? fillPainter
: SimplisticSoftBorderReverseFillPainter.INSTANCE;
graphics1X.setComposite(getAlphaComposite(alpha));
finalFillPainter.paintContourBackground(graphics1X, button,
fillPainter.paintContourBackground(graphics1X, button,
contourDim, contourDim,
new Ellipse2D.Float(0.5f, 0.5f, contourDim, contourDim),
renderColorTokens);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ public static void populateColorTokens(
ContainerRenderColorTokens currColorTokens = (treatEnabledAsActive && (currState == ComponentState.ENABLED))
? RadianceColorSchemeUtilities.getActiveRenderColorTokens(component, currState)
: RadianceColorSchemeUtilities.getRenderColorTokens(component, associationKind, currState);

Color containerLowest = currColorTokens.getContainerColorTokens().getContainerLowest();
Color containerLow = currColorTokens.getContainerColorTokens().getContainerLow();
Color container = currColorTokens.getContainerColorTokens().getContainer();
Expand All @@ -314,7 +313,8 @@ public static void populateColorTokens(

if (!currState.isDisabled() && (activeStates != null) && (activeStates.size() > 1)) {
for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates.entrySet()) {
if (activeEntry.getKey() == currState) {
ComponentState activeState = activeEntry.getKey();
if (activeState == currState) {
// Already accounted for the currently active state
continue;
}
Expand All @@ -324,9 +324,9 @@ public static void populateColorTokens(
continue;
}
// Get the color scheme that matches the contribution state
ContainerRenderColorTokens contributionColorTokens = (treatEnabledAsActive && (activeEntry.getKey() == ComponentState.ENABLED))
? RadianceColorSchemeUtilities.getActiveRenderColorTokens(component, activeEntry.getKey())
: RadianceColorSchemeUtilities.getRenderColorTokens(component, associationKind, activeEntry.getKey());
ContainerRenderColorTokens contributionColorTokens = (treatEnabledAsActive && (activeState == ComponentState.ENABLED))
? RadianceColorSchemeUtilities.getActiveRenderColorTokens(component, activeState)
: RadianceColorSchemeUtilities.getRenderColorTokens(component, associationKind, activeState);

// And interpolate the colors
containerLowest = RadianceColorUtilities.getInterpolatedColor(containerLowest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public void paintIcon(Component c, Graphics g, int x, int y) {

// Populate color schemes based on the current transition state of the check box.
BladeUtils.populateColorTokens(mutableRenderColorTokens, button, modelStateInfo,
currState, RadianceThemingSlices.ContainerColorTokensAssociationKind.MARK, false);
currState, RadianceThemingSlices.ContainerColorTokensAssociationKind.MARK,
false);

Graphics2D graphics = (Graphics2D) g.create();
graphics.translate(x, y);
Expand Down

0 comments on commit 3f659fb

Please sign in to comment.