aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/css
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2017-10-12 23:37:08 +0200
committerRobert Jaros <rjaros@finn.pl>2017-10-12 23:37:08 +0200
commitdaa6f55e70e85c15c55ef06fd2912d95ea4922fc (patch)
tree6816eaa07f9c827645853444e6ba76ae5466c3cb /src/main/kotlin/pl/treksoft/kvision/css
parentaa790685ba102fdf88bf45daa33028376e340e42 (diff)
downloadkvision-daa6f55e70e85c15c55ef06fd2912d95ea4922fc.tar.gz
kvision-daa6f55e70e85c15c55ef06fd2912d95ea4922fc.tar.bz2
kvision-daa6f55e70e85c15c55ef06fd2912d95ea4922fc.zip
color, opacity and background css properties
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/css')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/css/Css.kt95
1 files changed, 94 insertions, 1 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/css/Css.kt b/src/main/kotlin/pl/treksoft/kvision/css/Css.kt
index ce92813f..e2a4122b 100644
--- a/src/main/kotlin/pl/treksoft/kvision/css/Css.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/css/Css.kt
@@ -1,5 +1,6 @@
package pl.treksoft.kvision.css
+import pl.treksoft.kvision.core.ResString
import pl.treksoft.kvision.utils.Utils
@Suppress("EnumNaming", "EnumEntryName")
@@ -181,6 +182,36 @@ enum class COLOR(val color: String) {
YELLOWGREEN("yellowgreen")
}
+enum class BGSIZE(val size: String) {
+ COVER("cover"),
+ CONTAIN("contain")
+}
+
+enum class BGREPEAT(val repeat: String) {
+ REPEAT("repeat"),
+ REPEATX("repeat-x"),
+ REPEATY("repeat-y"),
+ NOREPEAT("no-repeat")
+}
+
+enum class BGATTACH(val attachment: String) {
+ SCROLL("scroll"),
+ FIXED("fixed"),
+ LOCAL("local")
+}
+
+enum class BGORIGIN(val origin: String) {
+ PADDING("padding-box"),
+ BORDER("border-box"),
+ CONTENT("content-box")
+}
+
+enum class BGCLIP(val clip: String) {
+ PADDING("padding-box"),
+ BORDER("border-box"),
+ CONTENT("content-box")
+}
+
class Border private constructor(private val width: CssSize? = null, private val style: BORDERSTYLE? = null,
private val color: String? = null) {
constructor(width: CssSize? = null, style: BORDERSTYLE? = null) : this(width, style, null)
@@ -193,6 +224,68 @@ class Border private constructor(private val width: CssSize? = null, private val
val w = width?.let {
it.first.toString() + it.second.unit
}
- return w.orEmpty() + " " + style?.borderStyle.orEmpty() + " " + color.orEmpty()
+ return w.orEmpty() + " " + (style?.borderStyle).orEmpty() + " " + color.orEmpty()
+ }
+}
+
+class Color private constructor(private val color: String? = null) {
+ constructor(color: Int) : this("#" + Utils.intToHexString(color))
+ constructor(color: COLOR) : this(color.color)
+
+ fun asString(): String {
+ return color.orEmpty()
+ }
+}
+
+class Background private constructor(private val color: String? = null, private val image: ResString? = null,
+ private val positionX: CssSize? = null, private val positionY: CssSize? = null,
+ private val sizeX: CssSize? = null, private val sizeY: CssSize? = null,
+ private val size: BGSIZE? = null, private val repeat: BGREPEAT? = null,
+ private val origin: BGORIGIN? = null, private val clip: BGCLIP? = null,
+ private val attachment: BGATTACH? = null) {
+ constructor(image: ResString? = null, positionX: CssSize? = null, positionY: CssSize? = null,
+ sizeX: CssSize? = null, sizeY: CssSize? = null, size: BGSIZE? = null,
+ repeat: BGREPEAT? = null, origin: BGORIGIN? = null, clip: BGCLIP? = null,
+ attachment: BGATTACH? = null) : this(null,
+ image, positionX, positionY, sizeX, sizeY, size, repeat, origin, clip, attachment)
+
+ constructor(color: Int, image: ResString? = null, positionX: CssSize? = null,
+ positionY: CssSize? = null,
+ sizeX: CssSize? = null, sizeY: CssSize? = null, size: BGSIZE? = null,
+ repeat: BGREPEAT? = null, origin: BGORIGIN? = null, clip: BGCLIP? = null,
+ attachment: BGATTACH? = null) : this("#" +
+ Utils.intToHexString(color), image, positionX, positionY, sizeX, sizeY, size, repeat, origin, clip,
+ attachment)
+
+ constructor(color: COLOR, image: ResString? = null, positionX: CssSize? = null,
+ positionY: CssSize? = null, sizeX: CssSize? = null, sizeY: CssSize? = null,
+ size: BGSIZE? = null, repeat: BGREPEAT? = null, origin: BGORIGIN? = null, clip: BGCLIP? = null,
+ attachment: BGATTACH? = null) : this(color.color, image,
+ positionX, positionY, sizeX, sizeY, size, repeat, origin, clip, attachment)
+
+ fun asString(): String {
+ val img = image?.let {
+ "url($image)"
+ }
+ val posX = positionX?.let {
+ it.first.toString() + it.second.unit
+ }
+ val posY = positionY?.let {
+ it.first.toString() + it.second.unit
+ }
+ val sX = sizeX?.let {
+ it.first.toString() + it.second.unit
+ }
+ val sY = sizeY?.let {
+ it.first.toString() + it.second.unit
+ }
+ return color.orEmpty() + " " + img.orEmpty() + " " + posX.orEmpty() + " " + posY.orEmpty() +
+ if (sX != null || sY != null || size != null) {
+ (if (posX != null || posY != null) " / " else " 0px 0px / ") +
+ sX.orEmpty() + " " + sY.orEmpty() + " " + (size?.size).orEmpty()
+ } else {
+ ""
+ } + " " + (repeat?.repeat).orEmpty() + " " + (origin?.origin).orEmpty() + " " +
+ (clip?.clip).orEmpty() + " " + (attachment?.attachment).orEmpty()
}
}