diff --git a/.idea/modules/komp.iml b/.idea/modules/komp.iml index f0bd2ef..74dcc6c 100644 --- a/.idea/modules/komp.iml +++ b/.idea/modules/komp.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp.iml b/.idea/modules/komp.iml index f0bd2ef..74dcc6c 100644 --- a/.idea/modules/komp.iml +++ b/.idea/modules/komp.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp_main.iml b/.idea/modules/komp_main.iml index 1f5e908..bb3080e 100644 --- a/.idea/modules/komp_main.iml +++ b/.idea/modules/komp_main.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp.iml b/.idea/modules/komp.iml index f0bd2ef..74dcc6c 100644 --- a/.idea/modules/komp.iml +++ b/.idea/modules/komp.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp_main.iml b/.idea/modules/komp_main.iml index 1f5e908..bb3080e 100644 --- a/.idea/modules/komp_main.iml +++ b/.idea/modules/komp_main.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp_test.iml b/.idea/modules/komp_test.iml index d5310df..c66a9fc 100644 --- a/.idea/modules/komp_test.iml +++ b/.idea/modules/komp_test.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp.iml b/.idea/modules/komp.iml index f0bd2ef..74dcc6c 100644 --- a/.idea/modules/komp.iml +++ b/.idea/modules/komp.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp_main.iml b/.idea/modules/komp_main.iml index 1f5e908..bb3080e 100644 --- a/.idea/modules/komp_main.iml +++ b/.idea/modules/komp_main.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp_test.iml b/.idea/modules/komp_test.iml index d5310df..c66a9fc 100644 --- a/.idea/modules/komp_test.iml +++ b/.idea/modules/komp_test.iml @@ -1,5 +1,5 @@ - + diff --git a/build.gradle b/build.gradle index ad79484..50230cf 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '0.0.1-SNAPSHOT' +version '0.0.2-SNAPSHOT' apply plugin: 'kotlin2js' apply plugin: 'idea' diff --git a/.idea/modules/komp.iml b/.idea/modules/komp.iml index f0bd2ef..74dcc6c 100644 --- a/.idea/modules/komp.iml +++ b/.idea/modules/komp.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp_main.iml b/.idea/modules/komp_main.iml index 1f5e908..bb3080e 100644 --- a/.idea/modules/komp_main.iml +++ b/.idea/modules/komp_main.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp_test.iml b/.idea/modules/komp_test.iml index d5310df..c66a9fc 100644 --- a/.idea/modules/komp_test.iml +++ b/.idea/modules/komp_test.iml @@ -1,5 +1,5 @@ - + diff --git a/build.gradle b/build.gradle index ad79484..50230cf 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '0.0.1-SNAPSHOT' +version '0.0.2-SNAPSHOT' apply plugin: 'kotlin2js' apply plugin: 'idea' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7271855..eb34d53 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#Sun Apr 02 22:05:18 CEST 2017 +#Wed May 10 15:59:40 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/.idea/modules/komp.iml b/.idea/modules/komp.iml index f0bd2ef..74dcc6c 100644 --- a/.idea/modules/komp.iml +++ b/.idea/modules/komp.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp_main.iml b/.idea/modules/komp_main.iml index 1f5e908..bb3080e 100644 --- a/.idea/modules/komp_main.iml +++ b/.idea/modules/komp_main.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp_test.iml b/.idea/modules/komp_test.iml index d5310df..c66a9fc 100644 --- a/.idea/modules/komp_test.iml +++ b/.idea/modules/komp_test.iml @@ -1,5 +1,5 @@ - + diff --git a/build.gradle b/build.gradle index ad79484..50230cf 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '0.0.1-SNAPSHOT' +version '0.0.2-SNAPSHOT' apply plugin: 'kotlin2js' apply plugin: 'idea' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7271855..eb34d53 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#Sun Apr 02 22:05:18 CEST 2017 +#Wed May 10 15:59:40 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/kotlin/nl/astraeus/komp/ComponentSize.kt b/src/main/kotlin/nl/astraeus/komp/ComponentSize.kt new file mode 100644 index 0000000..2f103b4 --- /dev/null +++ b/src/main/kotlin/nl/astraeus/komp/ComponentSize.kt @@ -0,0 +1,24 @@ +package nl.astraeus.komp + +/** + * User: rnentjes + * Date: 10-5-17 + * Time: 16:48 + */ + +enum class SizeType { + NONE, + ABSOLUTE, + PERCENTAGE, + FLEX, + FILL +} + +open class ComponentSize( + val xType: SizeType, + val yType: SizeType, + val xValue: Float, + val yValue: Float +) + +class NotSized : ComponentSize(SizeType.NONE, SizeType.NONE, 0f, 0f) diff --git a/.idea/modules/komp.iml b/.idea/modules/komp.iml index f0bd2ef..74dcc6c 100644 --- a/.idea/modules/komp.iml +++ b/.idea/modules/komp.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp_main.iml b/.idea/modules/komp_main.iml index 1f5e908..bb3080e 100644 --- a/.idea/modules/komp_main.iml +++ b/.idea/modules/komp_main.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp_test.iml b/.idea/modules/komp_test.iml index d5310df..c66a9fc 100644 --- a/.idea/modules/komp_test.iml +++ b/.idea/modules/komp_test.iml @@ -1,5 +1,5 @@ - + diff --git a/build.gradle b/build.gradle index ad79484..50230cf 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '0.0.1-SNAPSHOT' +version '0.0.2-SNAPSHOT' apply plugin: 'kotlin2js' apply plugin: 'idea' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7271855..eb34d53 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#Sun Apr 02 22:05:18 CEST 2017 +#Wed May 10 15:59:40 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/kotlin/nl/astraeus/komp/ComponentSize.kt b/src/main/kotlin/nl/astraeus/komp/ComponentSize.kt new file mode 100644 index 0000000..2f103b4 --- /dev/null +++ b/src/main/kotlin/nl/astraeus/komp/ComponentSize.kt @@ -0,0 +1,24 @@ +package nl.astraeus.komp + +/** + * User: rnentjes + * Date: 10-5-17 + * Time: 16:48 + */ + +enum class SizeType { + NONE, + ABSOLUTE, + PERCENTAGE, + FLEX, + FILL +} + +open class ComponentSize( + val xType: SizeType, + val yType: SizeType, + val xValue: Float, + val yValue: Float +) + +class NotSized : ComponentSize(SizeType.NONE, SizeType.NONE, 0f, 0f) diff --git a/src/main/kotlin/nl/astraeus/komp/HtmlComponent.kt b/src/main/kotlin/nl/astraeus/komp/HtmlComponent.kt index 23fb491..48a4420 100644 --- a/src/main/kotlin/nl/astraeus/komp/HtmlComponent.kt +++ b/src/main/kotlin/nl/astraeus/komp/HtmlComponent.kt @@ -36,4 +36,6 @@ open fun refresh() { Komp.refresh(element) } + + open fun getSize(): ComponentSize? = null } diff --git a/.idea/modules/komp.iml b/.idea/modules/komp.iml index f0bd2ef..74dcc6c 100644 --- a/.idea/modules/komp.iml +++ b/.idea/modules/komp.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp_main.iml b/.idea/modules/komp_main.iml index 1f5e908..bb3080e 100644 --- a/.idea/modules/komp_main.iml +++ b/.idea/modules/komp_main.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/komp_test.iml b/.idea/modules/komp_test.iml index d5310df..c66a9fc 100644 --- a/.idea/modules/komp_test.iml +++ b/.idea/modules/komp_test.iml @@ -1,5 +1,5 @@ - + diff --git a/build.gradle b/build.gradle index ad79484..50230cf 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '0.0.1-SNAPSHOT' +version '0.0.2-SNAPSHOT' apply plugin: 'kotlin2js' apply plugin: 'idea' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7271855..eb34d53 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#Sun Apr 02 22:05:18 CEST 2017 +#Wed May 10 15:59:40 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/kotlin/nl/astraeus/komp/ComponentSize.kt b/src/main/kotlin/nl/astraeus/komp/ComponentSize.kt new file mode 100644 index 0000000..2f103b4 --- /dev/null +++ b/src/main/kotlin/nl/astraeus/komp/ComponentSize.kt @@ -0,0 +1,24 @@ +package nl.astraeus.komp + +/** + * User: rnentjes + * Date: 10-5-17 + * Time: 16:48 + */ + +enum class SizeType { + NONE, + ABSOLUTE, + PERCENTAGE, + FLEX, + FILL +} + +open class ComponentSize( + val xType: SizeType, + val yType: SizeType, + val xValue: Float, + val yValue: Float +) + +class NotSized : ComponentSize(SizeType.NONE, SizeType.NONE, 0f, 0f) diff --git a/src/main/kotlin/nl/astraeus/komp/HtmlComponent.kt b/src/main/kotlin/nl/astraeus/komp/HtmlComponent.kt index 23fb491..48a4420 100644 --- a/src/main/kotlin/nl/astraeus/komp/HtmlComponent.kt +++ b/src/main/kotlin/nl/astraeus/komp/HtmlComponent.kt @@ -36,4 +36,6 @@ open fun refresh() { Komp.refresh(element) } + + open fun getSize(): ComponentSize? = null } diff --git a/src/main/kotlin/nl/astraeus/komp/Komp.kt b/src/main/kotlin/nl/astraeus/komp/Komp.kt index 51ed669..bc54015 100644 --- a/src/main/kotlin/nl/astraeus/komp/Komp.kt +++ b/src/main/kotlin/nl/astraeus/komp/Komp.kt @@ -52,10 +52,43 @@ if (element is HTMLElement && comp != null) { val parent = element.parentElement val newElement = comp.create() + val size = comp.getSize() + + if (size != null) { + sizeElement(newElement, size) + } parent?.replaceChild(newElement, element) } } } + fun sizeElement(element: HTMLElement, size: ComponentSize) { + var width = "" + var height = "" + val parent = element.parentElement as HTMLElement + + when(size.xType) { + SizeType.ABSOLUTE -> { + width = "${size.xValue.toInt()}px" + } + SizeType.PERCENTAGE -> { + width = "${(parent.clientWidth * size.xValue / 100f).toInt()}px" + } + SizeType.FILL -> { + + } + SizeType.FLEX -> { + + } + } + + if (width.isNotBlank()) { + element.style.width = width + } + if (height.isNotBlank()) { + element.style.height = height + } + } + } \ No newline at end of file