Disable resize

This commit is contained in:
2017-05-17 17:05:49 +02:00
parent d828a47784
commit 5dcfa8074a
3 changed files with 26 additions and 44 deletions

View File

@@ -8,12 +8,6 @@ import org.w3c.dom.HTMLElement
* Time: 16:48 * Time: 16:48
*/ */
enum class LayoutType {
NONE,
HORIZONTAL,
VERTICAL
}
enum class SizeType { enum class SizeType {
NONE, NONE,
ABSOLUTE, ABSOLUTE,
@@ -24,7 +18,6 @@ enum class SizeType {
open class ComponentSize( open class ComponentSize(
val element: HTMLElement, val element: HTMLElement,
val layout: LayoutType,
val type: SizeType, val type: SizeType,
val value: Float val value: Float
) { ) {
@@ -46,7 +39,6 @@ class SizeContainer(
val parentSize: Rect, val parentSize: Rect,
val componentList: List<ComponentSize> val componentList: List<ComponentSize>
) { ) {
var layout: LayoutType? = null
var totalSize = 0 var totalSize = 0
var totalPixels = 0f var totalPixels = 0f
var totalPercentage = 0f var totalPercentage = 0f
@@ -60,13 +52,6 @@ class SizeContainer(
fun calculate() { fun calculate() {
for (size in componentList) { 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) { when(size.type) {
SizeType.ABSOLUTE -> { SizeType.ABSOLUTE -> {
totalPixels += size.value totalPixels += size.value
@@ -83,15 +68,11 @@ class SizeContainer(
} }
} }
if (layout == null) { /* if (layout == LayoutType.HORIZONTAL) {
throw IllegalStateException("No hbox or vbox attribute found!?")
}
if (layout == LayoutType.HORIZONTAL) {
totalSize = parentSize.width totalSize = parentSize.width
} else { } else {
totalSize = parentSize.height totalSize = parentSize.height
} }*/
afterPixels = totalSize - totalPixels afterPixels = totalSize - totalPixels
afterPercentage = afterPixels * totalPercentage / 100f 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) size.calculatedSize = Rect(calculatedStart, parentSize.top, calculatedSize, parentSize.height)
} else { } else {
size.calculatedSize = Rect(parentSize.left, calculatedStart, parentSize.width, calculatedSize) size.calculatedSize = Rect(parentSize.left, calculatedStart, parentSize.width, calculatedSize)
} }*/
calculatedStart += calculatedSize calculatedStart += calculatedSize
console.log("Set component to ${size.calculatedSize}", size.element) console.log("Set component to ${size.calculatedSize}", size.element)

View File

@@ -13,7 +13,13 @@ fun DIV.include(component: HtmlComponent) {
Komp.define(result, component) 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 element: HTMLElement? = null
var size: ComponentSize? = null var size: ComponentSize? = null
@@ -36,6 +42,10 @@ abstract class HtmlComponent {
open fun refresh() { open fun refresh() {
Komp.refresh(element) Komp.refresh(element)
if (sizing != Sizing.NONE) {
// resize children
}
} }
} }

View File

@@ -20,7 +20,7 @@ object Komp {
init { init {
window.onresize = { window.onresize = {
Komp.resize() //Komp.resize()
} }
} }
@@ -41,7 +41,7 @@ object Komp {
elements[element] = component elements[element] = component
elementList.add(component) elementList.add(component)
resize() //resize()
} }
fun remove(element: HTMLElement) { fun remove(element: HTMLElement) {
@@ -77,7 +77,7 @@ object Komp {
} }
} }
resize() //resize()
} }
private fun resize() { private fun resize() {
@@ -98,12 +98,10 @@ object Komp {
} }
for (component in elementList) { for (component in elementList) {
if (component.element?.getAttribute("data-resize") != "true") { if (component.sizing != Sizing.NONE && component.element?.getAttribute("data-resize") != "true") {
if (component.element?.attributes?.get("hbox") != null || component.element?.attributes?.get("vbox") != null) { console.log("resize", component)
console.log("resize", component)
resize(component) resize(component)
}
} }
} }
} }
@@ -165,7 +163,7 @@ object Komp {
val size = getSize(child) val size = getSize(child)
comp?.size = size 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 { fun getSize(element: HTMLElement): ComponentSize {
val horText = element.attributes?.get("hbox")?.value val sizeText = element.attributes?.get("size")?.value
val verText = element.attributes?.get("vbox")?.value
var result: ComponentSize? = null var result: ComponentSize? = null
if (horText != null && verText != null) { if (sizeText != null) {
throw IllegalStateException("Attributes 'hbox' and 'vbox' can not be combined!") val (type, size) = getSizeFromAttribute(sizeText)
} else if (horText != null) {
val (type, size) = getSizeFromAttribute(horText)
result = ComponentSize(element, LayoutType.HORIZONTAL, type, size) result = ComponentSize(element, type, size)
} else if (verText != null) {
val (type, size) = getSizeFromAttribute(verText)
result = ComponentSize(element, LayoutType.VERTICAL, type, size)
} }
return result ?: throw IllegalStateException("Unable to calculate size for $this") return result ?: throw IllegalStateException("Unable to calculate size for $this")