diff --git a/haxe/ui/components/Button.hx b/haxe/ui/components/Button.hx index 9e1ece5e0..b22eaadbd 100644 --- a/haxe/ui/components/Button.hx +++ b/haxe/ui/components/Button.hx @@ -159,6 +159,11 @@ class ButtonLayout extends DefaultLayout { } else if (label.width > 0 && _component.componentWidth > 0 && ucx > 0) { // devezas so the label width "recovers" when dynamically (percent wise) we change the width of the button from lower (that has the text wrapped) to higher: label.width = label.layout.calcAutoWidth(); + if (hasFixedMaxWidth(_component)) { + if (maxWidth(_component) < label.width) { + label.width = maxWidth(_component); + } + } } } @@ -166,6 +171,14 @@ class ButtonLayout extends DefaultLayout { if (itemRenderer != null) { itemRenderer.width = ucx; } + } else { + if (hasFixedMaxWidth(_component)) { + var ucx = usableSize.width; + var label:Label = component.findComponent(Label, false); + if (maxWidth(_component) == _component.width) { + label.width = ucx; + } + } } if (_component.autoHeight == false) { diff --git a/haxe/ui/components/Label.hx b/haxe/ui/components/Label.hx index 2b2936c10..d1c6ea70b 100644 --- a/haxe/ui/components/Label.hx +++ b/haxe/ui/components/Label.hx @@ -92,6 +92,11 @@ private class LabelLayout extends DefaultLayout { #end } else { component.getTextDisplay().width = component.getTextDisplay().textWidth; + if (hasFixedMaxWidth(component)) { + if (maxWidth(component) < component.getTextDisplay().textWidth) { + component.width = maxWidth(component); + } + } } if (component.autoHeight == true) { diff --git a/haxe/ui/core/Component.hx b/haxe/ui/core/Component.hx index 5c9a09228..6012a6a74 100644 --- a/haxe/ui/core/Component.hx +++ b/haxe/ui/core/Component.hx @@ -1951,8 +1951,6 @@ class Component extends ComponentImpl if (_componentWidth != _actualWidth || _componentHeight != _actualHeight) { _actualWidth = _componentWidth; _actualHeight = _componentHeight; - - enforceSizeConstraints(); if (parentComponent != null) { parentComponent.invalidateComponentLayout(); @@ -1973,64 +1971,6 @@ class Component extends ComponentImpl return sizeChanged; } - private function enforceSizeConstraints() { - if (style != null) { - // enforce min width - if (style.minWidth != null && _componentWidth < style.minWidth) { - _componentWidth = _actualWidth = _width = style.minWidth; - } - - // enforce max width - if (style.maxWidth != null && style.maxPercentWidth == null && _componentWidth > style.maxWidth) { - _componentWidth = _actualWidth = _width = style.maxWidth; - } else if (style.maxWidth == null && style.maxPercentWidth != null) { - var p = this; - var max:Float = 0; - while (p != null) { - if (p.style != null && p.style.maxPercentWidth == null) { - max += p.width; - break; - } - if (p.style != null && p != this) { - max -= (p.style.paddingLeft + p.style.paddingRight); - } - p = p.parentComponent; - } - max = (max * style.maxPercentWidth) / 100; - if (max > 0 && _componentWidth > max) { - _componentWidth = _actualWidth = _width = max; - } - } - - // enforce min height - if (style.minHeight != null && _componentHeight < style.minHeight) { - _componentHeight = _actualHeight = _height = style.minHeight; - } - - // enforce max height - if (style.maxHeight != null && style.maxPercentHeight == null && _componentHeight > style.maxHeight) { - _componentHeight = _actualHeight = _height = style.maxHeight; - } else if (style.maxHeight == null && style.maxPercentHeight != null) { - var p = this; - var max:Float = 0; - while (p != null) { - if (p.style != null && p.style.maxPercentHeight == null) { - max += p.height; - break; - } - if (p.style != null && p != this) { - max -= (p.style.paddingTop + p.style.paddingBottom); - } - p = p.parentComponent; - } - max = (max * style.maxPercentHeight) / 100; - if (max > 0 && _componentHeight > max) { - _componentHeight = _actualHeight = _height = max; - } - } - } - } - private override function validateComponentStyle() { var s:Style = Toolkit.styleSheet.buildStyleFor(this); if (this.styleSheet != null) { diff --git a/haxe/ui/layouts/DefaultLayout.hx b/haxe/ui/layouts/DefaultLayout.hx index cb515df64..eb803d38f 100644 --- a/haxe/ui/layouts/DefaultLayout.hx +++ b/haxe/ui/layouts/DefaultLayout.hx @@ -94,8 +94,27 @@ class DefaultLayout extends Layout { var cx:Null = null; var cy:Null = null; - if (child.percentWidth != null) { - var childPercentWidth = child.percentWidth; + var childPercentWidth = child.percentWidth; + if (hasFixedMinPercentWidth(child)) { + if (childPercentWidth != null) { + if (childPercentWidth < minPercentWidth(child)) { + childPercentWidth = minPercentWidth(child); + } + } else { + childPercentWidth = minPercentWidth(child); + } + } + if (hasFixedMaxPercentWidth(child)) { + if (childPercentWidth != null) { + if (childPercentWidth > maxPercentWidth(child)) { + childPercentWidth = maxPercentWidth(child); + } + } else { + childPercentWidth = maxPercentWidth(child); + } + } + + if (childPercentWidth != null) { if (childPercentWidth == 100) { childPercentWidth = fullWidthValue; } @@ -117,6 +136,28 @@ class DefaultLayout extends Layout { #end */ } + + + var childPercentHeight = child.percentHeight; + if (hasFixedMinPercentHeight(child)) { + if (childPercentHeight != null) { + if (childPercentHeight < minPercentHeight(child)) { + childPercentHeight = minPercentHeight(child); + } + } else { + childPercentHeight = minPercentHeight(child); + } + } + if (hasFixedMaxPercentHeight(child)) { + if (childPercentHeight != null) { + if (childPercentHeight > maxPercentHeight(child)) { + childPercentHeight = maxPercentHeight(child); + } + } else { + childPercentHeight = maxPercentHeight(child); + } + } + if (child.percentHeight != null) { var childPercentHeight = child.percentHeight; if (childPercentHeight == 100) { @@ -133,14 +174,91 @@ class DefaultLayout extends Layout { */ } - if (fixedMinWidth(child) && child.percentWidth != null) { - percentWidth -= child.percentWidth; + var skipMaxWidth = false; + + if (hasFixedMinWidth(child) ) { + if (child.percentWidth != null) { + if (cx > minWidth(child)) { + } else { + cx = minWidth(child); + skipMaxWidth = true; + } + //percentWidth -= child.percentWidth; + } else { + if (child.width < minWidth(child)) { + cx = minWidth(child); + } + } + } + + if (hasFixedMinPercentWidth(child)) { + if (child.style != null && child.style.width != null) { + if (cx < child.style.width) { + cx = child.style.width; + } + } + } + + if (hasFixedMaxPercentWidth(child)) { + if (child.style != null && child.style.width != null) { + if (cx > child.style.width) { + cx = child.style.width; + } + } } - if (fixedMinHeight(child) && child.percentHeight != null) { - percentHeight -= child.percentHeight; + + + if (!skipMaxWidth && hasFixedMaxWidth(child) ) { + if (child.percentWidth != null) { + if (cx > maxWidth(child)) { + cx = maxWidth(child); + } + } + } + + var skipMaxHeight = false; + + if (hasFixedMinHeight(child) ) { + if (child.percentHeight != null) { + if (cy > minHeight(child)) { + } else { + cy = minHeight(child); + skipMaxHeight = true; + } + } else { + if (child.height < minHeight(child)) { + cy = minHeight(child); + } + } + } + + if (hasFixedMinPercentHeight(child)) { + if (child.style != null && child.style.height != null) { + if (cy < child.style.height) { + cy = child.style.height; + } + } + } + + if (hasFixedMaxPercentHeight(child)) { + if (child.style != null && child.style.height != null) { + if (cy > child.style.height) { + cy = child.style.height; + } + } + } + + if (!skipMaxHeight && hasFixedMaxHeight(child) ) { + if (child.percentHeight != null) { + if (cy > maxHeight(child)) { + cy = maxHeight(child); + } + //percentWidth -= child.percentWidth; + } } child.resizeComponent(cx, cy); + } } diff --git a/haxe/ui/layouts/HorizontalLayout.hx b/haxe/ui/layouts/HorizontalLayout.hx index 5339bd19a..f496a731d 100644 --- a/haxe/ui/layouts/HorizontalLayout.hx +++ b/haxe/ui/layouts/HorizontalLayout.hx @@ -72,7 +72,7 @@ class HorizontalLayout extends DefaultLayout { else { child.moveComponent(xpos + marginLeft(child), ypos); } - xpos += child.componentWidth + spacing; + if (child.componentWidth > 0) xpos += child.componentWidth + spacing; } } @@ -86,8 +86,10 @@ class HorizontalLayout extends DefaultLayout { continue; } - if (child.componentWidth > 0 && (child.percentWidth == null || fixedMinWidth(child) == true)) { // means its a fixed width, ie, not a % sized control - size.width -= child.componentWidth + marginLeft(child) + marginRight(child); + if (child.componentWidth > 0 && (child.percentWidth == null || hasFixedMinWidth(child) == true)) { // means its a fixed width, ie, not a % sized control + if (!hasFixedMinPercentWidth(child)) { + size.width -= child.componentWidth + marginLeft(child) + marginRight(child); + } } } @@ -95,8 +97,9 @@ class HorizontalLayout extends DefaultLayout { size.width -= horizontalSpacing * (visibleChildren - 1); } - if (size.width < 0) { + if (size.width <= 0) { size.width = 0; + visibleChildren--; } return size; diff --git a/haxe/ui/layouts/Layout.hx b/haxe/ui/layouts/Layout.hx index 166adebbf..e0f197fc1 100644 --- a/haxe/ui/layouts/Layout.hx +++ b/haxe/ui/layouts/Layout.hx @@ -168,6 +168,70 @@ class Layout implements ILayout { return fixedMinWidth; } + private function hasFixedMinWidth(child:Component):Bool { + if (child != null && child.style != null && child.style.minWidth != null) { + return true; + } + return false; + } + + private function hasFixedMinPercentWidth(child:Component):Bool { + if (child != null && child.style != null && child.style.minPercentWidth != null) { + return true; + } + return false; + } + + private function hasFixedMaxPercentWidth(child:Component):Bool { + if (child != null && child.style != null && child.style.maxPercentWidth != null) { + return true; + } + return false; + } + + private function fixedMaxWidth(child:Component):Bool { + var fixedMaxWidth = false; + if (child != null && child.style != null && child.style.maxWidth != null) { + fixedMaxWidth = child.componentWidth >= child.style.maxWidth; + } + return fixedMaxWidth; + } + + private function hasFixedMaxWidth(child:Component):Bool { + if (child != null && child.style != null && child.style.maxWidth != null) { + return true; + } + return false; + } + + private inline function minWidth(child:Component):Float { + if (child != null && child.style != null && child.style.minWidth != null) { + return child.style.minWidth; + } + return 0; + } + + private inline function minPercentWidth(child:Component):Float { + if (child != null && child.style != null && child.style.minPercentWidth != null) { + return child.style.minPercentWidth; + } + return 0; + } + + private inline function maxWidth(child:Component):Float { + if (child != null && child.style != null && child.style.maxWidth != null) { + return child.style.maxWidth; + } + return 0; + } + + private inline function maxPercentWidth(child:Component):Float { + if (child != null && child.style != null && child.style.maxPercentWidth != null) { + return child.style.maxPercentWidth; + } + return 0; + } + private function fixedMinHeight(child:Component):Bool { var fixedMinHeight = false; if (child != null && child.style != null && child.style.minHeight != null) { @@ -176,6 +240,70 @@ class Layout implements ILayout { return fixedMinHeight; } + private function hasFixedMinHeight(child:Component):Bool { + if (child != null && child.style != null && child.style.minHeight != null) { + return true; + } + return false; + } + + private function hasFixedMinPercentHeight(child:Component):Bool { + if (child != null && child.style != null && child.style.minPercentHeight != null) { + return true; + } + return false; + } + + private function hasFixedMaxPercentHeight(child:Component):Bool { + if (child != null && child.style != null && child.style.maxPercentHeight != null) { + return true; + } + return false; + } + + private function fixedMaxHeight(child:Component):Bool { + var fixedMaxHeight = false; + if (child != null && child.style != null && child.style.maxHeight != null) { + fixedMaxHeight = child.componentWidth >= child.style.maxHeight; + } + return fixedMaxHeight; + } + + private function hasFixedMaxHeight(child:Component):Bool { + if (child != null && child.style != null && child.style.maxHeight != null) { + return true; + } + return false; + } + + private inline function minHeight(child:Component):Float { + if (child != null && child.style != null && child.style.minHeight != null) { + return child.style.minHeight; + } + return 0; + } + + private inline function minPercentHeight(child:Component):Float { + if (child != null && child.style != null && child.style.minPercentHeight != null) { + return child.style.minPercentHeight; + } + return 0; + } + + private inline function maxHeight(child:Component):Float { + if (child != null && child.style != null && child.style.maxHeight != null) { + return child.style.maxHeight; + } + return 0; + } + + private inline function maxPercentHeight(child:Component):Float { + if (child != null && child.style != null && child.style.maxPercentHeight != null) { + return child.style.maxPercentHeight; + } + return 0; + } + //****************************************************************************************** // Helper props //****************************************************************************************** @@ -321,7 +449,7 @@ class Layout implements ILayout { continue; } - if (child.percentWidth == null) { + if (child.percentWidth == null || minWidth(child) > 0) { if (child.left < x1) { x1 = child.left - marginLeft(child) + marginRight(child); } @@ -330,7 +458,7 @@ class Layout implements ILayout { } } - if (child.percentHeight == null) { + if (child.percentHeight == null || minHeight(child) > 0) { if (child.top < y1) { y1 = child.top - marginTop(child) + marginBottom(child); } @@ -355,6 +483,62 @@ class Layout implements ILayout { h += y1; } + if (hasFixedMinPercentWidth(component) && component.parentComponent != null && component.parentComponent.layout != null) { + var p = component; + var min:Float = 0; + min = (p.parentComponent.layout.usableSize.width * p.style.minPercentWidth) / 100; + if (min > 0 && w < min) { + w = min; + } + } + + if (hasFixedMaxPercentWidth(component) && component.parentComponent != null && component.parentComponent.layout != null) { + var p = component; + var max:Float = 0; + max = (p.parentComponent.layout.usableSize.width * p.style.maxPercentWidth) / 100; + if (max > 0 && w > max) { + w = max; + } + } + + if (hasFixedMinPercentHeight(component) && component.parentComponent != null && component.parentComponent.layout != null) { + var p = component; + var min:Float = 0; + min = (p.parentComponent.layout.usableSize.height * p.style.minPercentHeight) / 100; + if (min > 0 && h < min) { + h = min; + } + } + + if (hasFixedMaxPercentHeight(component) && component.parentComponent != null && component.parentComponent.layout != null) { + var p = component; + var max:Float = 0; + max = (p.parentComponent.layout.usableSize.height * p.style.maxPercentHeight) / 100; + if (max > 0 && h > max) { + h = max; + } + } + + if (hasFixedMinWidth(component)) { + var min = minWidth(component); + if (w < min) w = min; + } + + if (hasFixedMinHeight(component)) { + var min = minHeight(component); + if (h < min) h = min; + } + + if (hasFixedMaxWidth(component)) { + var max = maxWidth(component); + if (w > max) w = max; + } + + if (hasFixedMaxHeight(component)) { + var max = maxHeight(component); + if (h > max) h = max; + } + return new Size(w, h); } diff --git a/haxe/ui/layouts/VerticalLayout.hx b/haxe/ui/layouts/VerticalLayout.hx index 73197d350..08528398d 100644 --- a/haxe/ui/layouts/VerticalLayout.hx +++ b/haxe/ui/layouts/VerticalLayout.hx @@ -31,7 +31,7 @@ class VerticalLayout extends DefaultLayout { } child.moveComponent(xpos, ypos + marginTop(child)); - ypos += child.componentHeight + verticalSpacing; + if (child.componentHeight > 0) ypos += child.componentHeight + verticalSpacing; } } @@ -46,7 +46,9 @@ class VerticalLayout extends DefaultLayout { } if (child.componentHeight > 0 && (child.percentHeight == null || fixedMinHeight(child) == true)) { // means its a fixed height, ie, not a % sized control - size.height -= child.componentHeight + marginTop(child) + marginBottom(child); + if (!hasFixedMinPercentHeight(child)) { + size.height -= child.componentHeight + marginTop(child) + marginBottom(child); + } } } @@ -54,8 +56,9 @@ class VerticalLayout extends DefaultLayout { size.height -= verticalSpacing * (visibleChildren - 1); } - if (size.height < 0) { + if (size.height <= 0) { size.height = 0; + visibleChildren--; } return size; }