From bb4c7b0a02b62d2bace677cce6fc0a1f9d014c68 Mon Sep 17 00:00:00 2001 From: gazer Date: Fri, 13 Oct 2017 08:16:11 +0300 Subject: [PATCH] box shadow property in Style --- src/dlangui/graphics/resources.d | 2 +- src/dlangui/widgets/styles.d | 33 ++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/dlangui/graphics/resources.d b/src/dlangui/graphics/resources.d index 9866023a..f3f15739 100644 --- a/src/dlangui/graphics/resources.d +++ b/src/dlangui/graphics/resources.d @@ -1136,7 +1136,7 @@ class CombinedDrawable : Drawable { DrawableRef background; DrawableRef border; - this(uint backgroundColor, string backgroundImageId, string borderDescription) { + this(uint backgroundColor, string backgroundImageId, string borderDescription, string boxShadowDescription) { background = (backgroundImageId !is null) ? drawableCache.get(backgroundImageId) : (!backgroundColor.isFullyTransparentColor) ? new SolidFillDrawable(backgroundColor) : null; diff --git a/src/dlangui/widgets/styles.d b/src/dlangui/widgets/styles.d index b074663f..2e762538 100644 --- a/src/dlangui/widgets/styles.d +++ b/src/dlangui/widgets/styles.d @@ -324,6 +324,7 @@ protected: uint _alpha; string _fontFace; string _backgroundImageId; + string _boxShadow; string _border; Rect _padding; Rect _margins; @@ -413,8 +414,10 @@ public: return (cast(Style)this)._backgroundDrawable; string image = backgroundImageId; uint color = backgroundColor; - if (border !is null) { - (cast(Style)this)._backgroundDrawable = new CombinedDrawable(color, image, border); + string borders = border; + string shadows = boxShadow; + if (borders !is null || shadows !is null) { + (cast(Style)this)._backgroundDrawable = new CombinedDrawable(color, image, borders, shadows); } else if (image !is null) { (cast(Style)this)._backgroundDrawable = drawableCache.get(image); } else { @@ -530,6 +533,15 @@ public: return parentStyle.fontSize; } + /// box shadow + @property string boxShadow() const { + if (_boxShadow !is null) + return _boxShadow; + else { + return parentStyle.boxShadow; + } + } + /// border @property string border() const { if (_border !is null) @@ -791,6 +803,12 @@ public: return this; } + @property Style boxShadow(string s) { + _boxShadow = s; + _backgroundDrawable.clear(); + return this; + } + @property Style border(string s) { _border = s; _backgroundDrawable.clear(); @@ -1038,6 +1056,10 @@ class Theme : Style { @property override string backgroundImageId() const { return _backgroundImageId; } + /// box shadow + @property override string boxShadow() const { + return _boxShadow; + } /// border @property override string border() const { return _border; @@ -1527,6 +1549,11 @@ string sanitizeBorderProperty(string s) pure { return cast(string)res; } +/// remove superfluous space characters from a box shadow property +string sanitizeBoxShadowProperty(string s) pure { + return sanitizeBorderProperty(s); +} + /// load style attributes from XML element bool loadStyleAttributes(Style style, Element elem, bool allowStates) { //Log.d("Theme: loadStyleAttributes ", style.id, " ", elem.tag.attr); @@ -1542,6 +1569,8 @@ bool loadStyleAttributes(Style style, Element elem, bool allowStates) { style.padding = decodeRect(elem.tag.attr["padding"]); if ("border" in elem.tag.attr) style.border = sanitizeBorderProperty(elem.tag.attr["border"]); + if ("boxShadow" in elem.tag.attr) + style.boxShadow = sanitizeBoxShadowProperty(elem.tag.attr["boxShadow"]); if ("align" in elem.tag.attr) style.alignment = decodeAlignment(elem.tag.attr["align"]); if ("minWidth" in elem.tag.attr)