Skip to content

Commit

Permalink
Fixed round rect border handling to only use roundrectborder if eithe…
Browse files Browse the repository at this point in the history
…r all of the corners have the same radius, or top corners have the same radius (and bottom has no radius), or bottom corners have same radius (and top has no radius) - otherwise it falls back to image border. Ultimately we should move to supporting topRightMode, topLeftMode, bottomRightMode, and bottomLeftMode for independent corner radii, but the resource file currently doesn't support these settings... and didn't want to delve into that right now.
  • Loading branch information
shannah committed Sep 25, 2018
1 parent b6a85e5 commit 66c87a6
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions CodenameOneDesigner/src/com/codename1/designer/css/CSSTheme.java
Expand Up @@ -2373,7 +2373,6 @@ public boolean canBeAchievedWithRoundRectBorder(Map<String,LexicalUnit> styles)




String prefix = "cn1-border";
String[] corners = new String[]{"top-left", "top-right", "bottom-left", "bottom-right"};
String[] xy = new String[]{"x", "y"};
Expand All @@ -2387,9 +2386,25 @@ public boolean canBeAchievedWithRoundRectBorder(Map<String,LexicalUnit> styles)
}

ScaledUnit val = null;
boolean topLeft=false;
boolean topRight = false;
boolean bottomLeft = false;
boolean bottomRight = false;
for (String cornerStyle : radiusAtts) {
ScaledUnit u = (ScaledUnit)styles.get(cornerStyle);
if (u != null && u.getPixelValue() != 0) {
if (cornerStyle.indexOf("top-left") != -1) {
topLeft = true;
}
if (cornerStyle.indexOf("top-right") != -1) {
topRight = true;
}
if (cornerStyle.indexOf("bottom-left") != -1) {
bottomLeft = true;
}
if (cornerStyle.indexOf("bottom-right") != -1) {
bottomRight = true;
}
if (val != null && val.getPixelValue() != u.getPixelValue()) {
// We have more than one non-zero corner radius
//System.out.println("Failed corner test");
Expand All @@ -2400,6 +2415,13 @@ public boolean canBeAchievedWithRoundRectBorder(Map<String,LexicalUnit> styles)
}
}


if (topLeft != topRight || bottomLeft != bottomRight) {
// Resource files don't currently support topLeftMode, topRightMode, bottomLeftMode, and bottomRightMode
// so we need to fall back to image borders if the left and right have different radii
return false;
}

// All corners are the same, so we can proceed to the next step.

prefix = "border";
Expand Down Expand Up @@ -4437,10 +4459,12 @@ private com.codename1.ui.plaf.Border createRoundRectBorder(Map<String,LexicalUni
ScaledUnit bottomRightRadius = getBorderRadius(styles, "bottom-right");
//System.out.println("TopLeftRadius is : "+topLeftRadius+" isZero? "+isZero(topLeftRadius));
//System.out.println("BottomRight Radius is : "+bottomRightRadius+" isZero? "+isZero(bottomRightRadius));
out.bottomLeftMode(!isZero(bottomLeftRadius));
out.bottomRightMode(!isZero(bottomRightRadius));
out.topLeftMode(!isZero(topLeftRadius));
out.topRightMode(!isZero(topRightRadius));
if (!isZero(bottomLeftRadius) && !isZero(bottomRightRadius) && isZero(topLeftRadius) && isZero(topRightRadius)) {
out.bottomOnlyMode(true);
} else if (isZero(bottomLeftRadius) && isZero(bottomRightRadius) && !isZero(topLeftRadius) && !isZero(topRightRadius)) {
out.topOnlyMode(true);
}



if (borderWidth != null) {
Expand Down

0 comments on commit 66c87a6

Please sign in to comment.