From 5dcfa8074ac13b952650fe412f13a04780364d65 Mon Sep 17 00:00:00 2001 From: rnentjes Date: Wed, 17 May 2017 17:05:49 +0200 Subject: [PATCH] Disable resize --- .../kotlin/nl/astraeus/komp/ComponentSize.kt | 27 +++------------- .../kotlin/nl/astraeus/komp/HtmlComponent.kt | 12 ++++++- src/main/kotlin/nl/astraeus/komp/Komp.kt | 31 +++++++------------ 3 files changed, 26 insertions(+), 44 deletions(-) diff --git a/src/main/kotlin/nl/astraeus/komp/ComponentSize.kt b/src/main/kotlin/nl/astraeus/komp/ComponentSize.kt index 0fef47f..5a16517 100644 --- a/src/main/kotlin/nl/astraeus/komp/ComponentSize.kt +++ b/src/main/kotlin/nl/astraeus/komp/ComponentSize.kt @@ -8,12 +8,6 @@ import org.w3c.dom.HTMLElement * Time: 16:48 */ -enum class LayoutType { - NONE, - HORIZONTAL, - VERTICAL -} - enum class SizeType { NONE, ABSOLUTE, @@ -24,7 +18,6 @@ enum class SizeType { open class ComponentSize( val element: HTMLElement, - val layout: LayoutType, val type: SizeType, val value: Float ) { @@ -46,7 +39,6 @@ class SizeContainer( val parentSize: Rect, val componentList: List ) { - var layout: LayoutType? = null var totalSize = 0 var totalPixels = 0f var totalPercentage = 0f @@ -60,13 +52,6 @@ class SizeContainer( fun calculate() { for (size in componentList) { - if (layout == null) { - layout = size.layout - } else if (layout != size.layout) { - console.log("hbox/vbox combined:", componentList) - throw IllegalStateException("hbox and vbox mixed between siblings!") - } - when(size.type) { SizeType.ABSOLUTE -> { totalPixels += size.value @@ -83,15 +68,11 @@ class SizeContainer( } } - if (layout == null) { - throw IllegalStateException("No hbox or vbox attribute found!?") - } - - if (layout == LayoutType.HORIZONTAL) { +/* if (layout == LayoutType.HORIZONTAL) { totalSize = parentSize.width } else { totalSize = parentSize.height - } + }*/ afterPixels = totalSize - totalPixels afterPercentage = afterPixels * totalPercentage / 100f @@ -112,11 +93,11 @@ class SizeContainer( } } - if (layout == LayoutType.HORIZONTAL) { +/* if (layout == LayoutType.HORIZONTAL) { size.calculatedSize = Rect(calculatedStart, parentSize.top, calculatedSize, parentSize.height) } else { size.calculatedSize = Rect(parentSize.left, calculatedStart, parentSize.width, calculatedSize) - } + }*/ calculatedStart += calculatedSize console.log("Set component to ${size.calculatedSize}", size.element) diff --git a/src/main/kotlin/nl/astraeus/komp/HtmlComponent.kt b/src/main/kotlin/nl/astraeus/komp/HtmlComponent.kt index 10a9311..b08a831 100644 --- a/src/main/kotlin/nl/astraeus/komp/HtmlComponent.kt +++ b/src/main/kotlin/nl/astraeus/komp/HtmlComponent.kt @@ -13,7 +13,13 @@ fun DIV.include(component: HtmlComponent) { Komp.define(result, component) } -abstract class HtmlComponent { +enum class Sizing { + NONE, + HORIZONTAL, + VERTICAL +} + +abstract class HtmlComponent(val sizing: Sizing = Sizing.NONE) { var element: HTMLElement? = null var size: ComponentSize? = null @@ -36,6 +42,10 @@ abstract class HtmlComponent { open fun refresh() { Komp.refresh(element) + + if (sizing != Sizing.NONE) { + // resize children + } } } diff --git a/src/main/kotlin/nl/astraeus/komp/Komp.kt b/src/main/kotlin/nl/astraeus/komp/Komp.kt index 4a4ef8b..4551069 100644 --- a/src/main/kotlin/nl/astraeus/komp/Komp.kt +++ b/src/main/kotlin/nl/astraeus/komp/Komp.kt @@ -20,7 +20,7 @@ object Komp { init { window.onresize = { - Komp.resize() + //Komp.resize() } } @@ -41,7 +41,7 @@ object Komp { elements[element] = component elementList.add(component) - resize() + //resize() } fun remove(element: HTMLElement) { @@ -77,7 +77,7 @@ object Komp { } } - resize() + //resize() } private fun resize() { @@ -98,12 +98,10 @@ object Komp { } for (component in elementList) { - if (component.element?.getAttribute("data-resize") != "true") { - if (component.element?.attributes?.get("hbox") != null || component.element?.attributes?.get("vbox") != null) { - console.log("resize", component) + if (component.sizing != Sizing.NONE && component.element?.getAttribute("data-resize") != "true") { + console.log("resize", component) - resize(component) - } + resize(component) } } } @@ -165,7 +163,7 @@ object Komp { val size = getSize(child) comp?.size = size - result.add(ComponentSize(child, size.layout, size.type, size.value)) + result.add(ComponentSize(child, size.type, size.value)) } } @@ -173,20 +171,13 @@ object Komp { } fun getSize(element: HTMLElement): ComponentSize { - val horText = element.attributes?.get("hbox")?.value - val verText = element.attributes?.get("vbox")?.value + val sizeText = element.attributes?.get("size")?.value var result: ComponentSize? = null - if (horText != null && verText != null) { - throw IllegalStateException("Attributes 'hbox' and 'vbox' can not be combined!") - } else if (horText != null) { - val (type, size) = getSizeFromAttribute(horText) + if (sizeText != null) { + val (type, size) = getSizeFromAttribute(sizeText) - result = ComponentSize(element, LayoutType.HORIZONTAL, type, size) - } else if (verText != null) { - val (type, size) = getSizeFromAttribute(verText) - - result = ComponentSize(element, LayoutType.VERTICAL, type, size) + result = ComponentSize(element, type, size) } return result ?: throw IllegalStateException("Unable to calculate size for $this")