From 52172ba9297ccfefaeb9497fae39b3360edeea5d Mon Sep 17 00:00:00 2001 From: Steve Hannah Date: Mon, 11 Feb 2019 11:42:57 -0800 Subject: [PATCH] Improved support for round rect border in CSS. Previously CSS would use 9-piece borders for if the it couldn't reproduce it with a round rect border in normal, top-only, or bottom-only mode. E.g. if only the top left and bottom right corners have a radius defined, then it would fall back to a 9-piece border. This change allows roundrectborder to be used for any combination of corners being rounded. It still doesn't allow you to have different non-zero radiuses in different corners. All of the corners need to either have the same radius, or zero. If one corner has, for examle, a radius of 3mm and another has 2mm, then it will fall back to a 9-piece border still. https://github.com/codenameone/CodenameOne/issues/2350 --- .../src/com/codename1/ui/util/Resources.java | 19 +++++++ .../com/codename1/designer/css/CSSTheme.java | 49 +++++-------------- .../codename1/ui/util/EditableResources.java | 12 +++-- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/CodenameOne/src/com/codename1/ui/util/Resources.java b/CodenameOne/src/com/codename1/ui/util/Resources.java index 940aa3ab4e..4b9f005bc1 100644 --- a/CodenameOne/src/com/codename1/ui/util/Resources.java +++ b/CodenameOne/src/com/codename1/ui/util/Resources.java @@ -1622,6 +1622,25 @@ private Object createBorder(DataInputStream input, int type) throws IOException bezierCorners(input.readBoolean()). topOnlyMode(input.readBoolean()). bottomOnlyMode(input.readBoolean()); + // round rect border with top-left, top-right, bottom-right, bottom-left corners + // specified independently + case 0xff15: + return RoundRectBorder.create(). + stroke(input.readFloat(), input.readBoolean()). + strokeColor(input.readInt()). + strokeOpacity(input.readInt()). + shadowBlur(input.readFloat()). + shadowOpacity(input.readInt()). + shadowSpread(input.readFloat()). + shadowX(input.readFloat()). + shadowY(input.readFloat()). + cornerRadius(input.readFloat()). + bezierCorners(input.readBoolean()). + topLeftMode(input.readBoolean()). + topRightMode(input.readBoolean()). + bottomRightMode(input.readBoolean()). + bottomLeftMode(input.readBoolean()); + } return null; } diff --git a/CodenameOneDesigner/src/com/codename1/designer/css/CSSTheme.java b/CodenameOneDesigner/src/com/codename1/designer/css/CSSTheme.java index 170dd1cd3e..a25878e5bd 100644 --- a/CodenameOneDesigner/src/com/codename1/designer/css/CSSTheme.java +++ b/CodenameOneDesigner/src/com/codename1/designer/css/CSSTheme.java @@ -1400,6 +1400,9 @@ public Map calculateSelectorCacheStatus(File cachedFile) th } public void updateResources() { + // TODO: We need to remove stale theme entries + // https://github.com/codenameone/CodenameOne/issues/2698 + for (String id : elements.keySet()) { if (!isModified(id)) { continue; @@ -1415,7 +1418,6 @@ public void updateResources() { String unselId = id; String pressedId = id+".press"; String disabledId = id+".dis"; - res.setThemeProperty(themeName, unselId+".padding", el.getThemePadding(unselectedStyles)); res.setThemeProperty(themeName, unselId+".padUnit", el.getThemePaddingUnit(unselectedStyles)); res.setThemeProperty(themeName, selId+"#padding", el.getThemePadding(selectedStyles)); @@ -2386,18 +2388,10 @@ public boolean canBeAchievedWithUnderlineBorder(Map styles) } public boolean canBeAchievedWithRoundRectBorder(Map styles) { - //System.out.println("Checking if we can achieve with background image generation "+styles); if (hasUnequalBorders() || this.hasGradient() || !isBorderLineOrNone() || !isNone(backgroundImageUrl) || hasBoxShadow()) { - //System.out.println("Failed test 1"); - //System.out.println("unequalBorders? "+hasUnequalBorders()); - //System.out.println("Has gradient? "+hasGradient()); - //System.out.println("BorderLineOrNone? "+isBorderLineOrNone()); - //System.out.println("Background Image URL: "+backgroundImageUrl); return false; } - - String prefix = "cn1-border"; String[] corners = new String[]{"top-left", "top-right", "bottom-left", "bottom-right"}; String[] xy = new String[]{"x", "y"}; @@ -2411,25 +2405,9 @@ public boolean canBeAchievedWithRoundRectBorder(Map 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"); @@ -2440,13 +2418,6 @@ public boolean canBeAchievedWithRoundRectBorder(Map 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"; @@ -4484,11 +4455,15 @@ private com.codename1.ui.plaf.Border createRoundRectBorder(Map