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
*/
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<ComponentSize>
) {
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)

View File

@@ -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
}
}
}

View File

@@ -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")