Skip to content
Permalink
Browse files

Added support for underlne borders so that border-bottom with solid c…

…olors don't require image border generation.
  • Loading branch information...
shannah committed Sep 25, 2018
1 parent 01fbd4b commit b6a85e5c8ab161405a18d51871b48df43744e806
Showing with 89 additions and 10 deletions.
  1. +89 −10 CodenameOneDesigner/src/com/codename1/designer/css/CSSTheme.java
@@ -2331,6 +2331,35 @@ boolean isBorderLineOrNone() {
return styleTop == null || "none".equals(styleTop) || "line".equals(styleTop) || "solid".equals(styleTop);
}

public boolean canBeAchievedWithUnderlineBorder(Map<String,LexicalUnit> styles) {
if (this.hasGradient() || !isBorderLineOrNone() || !isNone(backgroundImageUrl) || hasBoxShadow()) {
return false;
}
ScaledUnit topThickness = (ScaledUnit)styles.get("border-top-width");
ScaledUnit leftThickness = (ScaledUnit)styles.get("border-left-width");
ScaledUnit rightThickness = (ScaledUnit)styles.get("border-right-width");
ScaledUnit bottomThickness = (ScaledUnit)styles.get("border-bottom-width");
ScaledUnit[] sideUnits = new ScaledUnit[]{topThickness, leftThickness, rightThickness};
String[] sideStyles = new String[]{styleTop, styleLeft, styleRight};

for (int i=0; i<3; i++) {
ScaledUnit u = sideUnits[i];
String s = sideStyles[i];
if (u != null && u.getPixelValue() != 0 && !(s == null || "none".equals(s))) {
return false;
}
}

if (bottomThickness != null && bottomThickness.getPixelValue() != 0 && ("line".equals(styleBottom) || "solid".equals(styleBottom))) {
LexicalUnit color = styles.get("border-bottom-color");
if (color != null && getColorAlphaInt(color) != 255) {
return false;
}
return true;
}
return false;
}

public boolean canBeAchievedWithRoundRectBorder(Map<String,LexicalUnit> styles) {
//System.out.println("Checking if we can achieve with background image generation "+styles);
if (hasUnequalBorders() || this.hasGradient() || !isBorderLineOrNone() || !isNone(backgroundImageUrl) || hasBoxShadow()) {
@@ -2344,6 +2373,7 @@ 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"};
@@ -3384,7 +3414,7 @@ public boolean requiresBackgroundImageGeneration(Map<String,LexicalUnit> style)
ScaledUnit background = (ScaledUnit) style.get("background");
boolean isCN1Gradient = background != null && background.isCN1Gradient();
Border b = createBorder(style);
if (b.canBeAchievedWithRoundRectBorder(style)) {
if (b.canBeAchievedWithRoundRectBorder(style) || b.canBeAchievedWithUnderlineBorder(style)) {
// If we can do this with a roundrect border
// then we don't need background image
return false;
@@ -3464,7 +3494,7 @@ public boolean requiresImageBorder(Map<String,LexicalUnit> style) {
}

Border b = this.createBorder(style);
if (b.canBeAchievedWithRoundRectBorder(style)) {
if (b.canBeAchievedWithRoundRectBorder(style) || b.canBeAchievedWithUnderlineBorder(style)) {
// If we can do it with a RoundRectBorder, then we don't need to generate an imageborder
return false;
}
@@ -4336,6 +4366,54 @@ private ScaledUnit getBorderRadius(Map<String,LexicalUnit> styles) {
return null;
}

private com.codename1.ui.plaf.Border createUnderlineBorder(Map<String,LexicalUnit> styles) {
LexicalUnit borderColor = styles.get("border-bottom-color");
ScaledUnit borderWidth = (ScaledUnit)styles.get("border-bottom-width");
float borderWidthF=-1;
int borderWidthI=-1;
if (borderWidth != null) {
switch (borderWidth.getLexicalUnitType()) {
case LexicalUnit.SAC_MILLIMETER:
borderWidthF = (float)borderWidth.getNumericValue();
break;
case LexicalUnit.SAC_INTEGER:
case LexicalUnit.SAC_REAL:
case LexicalUnit.SAC_POINT:
borderWidthF = (float)borderWidth.getNumericValue() * 25.4f / 72f;
break;
case LexicalUnit.SAC_PIXEL:
borderWidthI = (int)borderWidth.getNumericValue();
break;
case LexicalUnit.SAC_CENTIMETER:
borderWidthF = (float)borderWidth.getNumericValue() * 10;
break;
case LexicalUnit.SAC_INCH:
borderWidthF = (float)borderWidth.getNumericValue() * 25.4f;
break;
default:
borderWidthI = 1;

}

} else {
borderWidthI = 1;
}
if (borderColor != null) {
int borderColorI = getColorInt(borderColor);
if (borderWidthI > 0) {
return com.codename1.ui.plaf.Border.createUnderlineBorder(borderWidthI, borderColorI);
} else {
return com.codename1.ui.plaf.Border.createUnderlineBorder(borderWidthF, borderColorI);
}
} else {
if (borderWidthI > 0) {
return com.codename1.ui.plaf.Border.createUnderlineBorder(borderWidthI);
} else {
return com.codename1.ui.plaf.Border.createUnderlineBorder(borderWidthF);
}
}
}

private com.codename1.ui.plaf.Border createRoundRectBorder(Map<String,LexicalUnit> styles) {
// We create a round border
//LexicalUnit backgroundColor = styles.get("background-color");
@@ -4354,17 +4432,15 @@ private ScaledUnit getBorderRadius(Map<String,LexicalUnit> styles) {
}

ScaledUnit topLeftRadius = getBorderRadius(styles, "top-left");
ScaledUnit topRightRadius = getBorderRadius(styles, "top-right");
ScaledUnit bottomLeftRadius = getBorderRadius(styles, "bottom-left");
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));
if (!isZero(topLeftRadius) && isZero(bottomRightRadius)) {
//System.out.println("Setting top only mode");
out.topOnlyMode(true);
} else if (isZero(topLeftRadius) && !isZero(bottomRightRadius)) {

out.bottomOnlyMode(true);
}

out.bottomLeftMode(!isZero(bottomLeftRadius));
out.bottomRightMode(!isZero(bottomRightRadius));
out.topLeftMode(!isZero(topLeftRadius));
out.topRightMode(!isZero(topRightRadius));


if (borderWidth != null) {
@@ -4500,6 +4576,9 @@ private ScaledUnit getBorderRadius(Map<String,LexicalUnit> styles) {
if (b.hasBorderRadius()) {
return createRoundRectBorder(styles);
}
if (b.canBeAchievedWithUnderlineBorder(styles)) {
return createUnderlineBorder(styles);
}
if (b.hasUnequalBorders()) {
//System.out.println("We have unequal borders");
return com.codename1.ui.plaf.Border.createCompoundBorder(

0 comments on commit b6a85e5

Please sign in to comment.
You can’t perform that action at this time.