aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/css/Css.kt
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2017-10-08 20:03:45 +0200
committerRobert Jaros <rjaros@finn.pl>2017-10-08 20:03:45 +0200
commitd5b33bcbcca3d9ef512703a42a562770600e6836 (patch)
tree252ac0e93885af2ce87088367dbf3e7900090029 /src/main/kotlin/pl/treksoft/kvision/css/Css.kt
parentdc9dc5df0e012b487dd6fd5918a1e0bd3d06a4ce (diff)
downloadkvision-d5b33bcbcca3d9ef512703a42a562770600e6836.tar.gz
kvision-d5b33bcbcca3d9ef512703a42a562770600e6836.tar.bz2
kvision-d5b33bcbcca3d9ef512703a42a562770600e6836.zip
Refactoring StyledComponent out of Widget
Implementation of border, margin and padding properties
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/css/Css.kt')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/css/Css.kt62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/css/Css.kt b/src/main/kotlin/pl/treksoft/kvision/css/Css.kt
new file mode 100644
index 00000000..14c242e8
--- /dev/null
+++ b/src/main/kotlin/pl/treksoft/kvision/css/Css.kt
@@ -0,0 +1,62 @@
+package pl.treksoft.kvision.css
+
+import pl.treksoft.kvision.utils.Utils
+
+@Suppress("EnumNaming", "EnumEntryName")
+enum class UNIT(val unit: String) {
+ px("px"),
+ pt("pt"),
+ em("em"),
+ cm("cm"),
+ mm("mm"),
+ `in`("in"),
+ pc("pc"),
+ ch("ch"),
+ rem("rem"),
+ vw("vw"),
+ vh("vh"),
+ vmin("vmin"),
+ vmax("vmax"),
+ perc("%")
+}
+
+typealias CssSize = Pair<Int, UNIT>
+
+enum class BORDERSTYLE(val borderStyle: String) {
+ NONE("none"),
+ HIDDEN("hidden"),
+ DOTTED("dotted"),
+ DASHED("dashed"),
+ SOLID("solid"),
+ DOUBLE("double"),
+ GROOVE("groove"),
+ RIDGE("ridge"),
+ INSET("inset"),
+ OUTSET("outset"),
+ INITIAL("initial"),
+ INHERIT("inherit")
+}
+
+enum class COLOR(val color: String) {
+ RED("red"),
+ BLUE("blue"),
+ GREEN("green"),
+ BLACK("black"),
+ WHITE("white")
+}
+
+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)
+ constructor(width: CssSize? = null, style: BORDERSTYLE? = null, color: Int) : this(width, style,
+ "#" + Utils.intToHexString(color))
+
+ constructor(width: CssSize? = null, style: BORDERSTYLE? = null, color: COLOR) : this(width, style, color.color)
+
+ fun asString(): String {
+ val w = width?.let {
+ it.first.toString() + it.second.unit
+ }
+ return w.orEmpty() + " " + style?.borderStyle.orEmpty() + " " + color.orEmpty()
+ }
+}