Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Constraints #651

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions haxe/ui/components/Button.hx
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,26 @@ 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);
}
}
}
}

var itemRenderer = component.findComponent(ItemRenderer);
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) {
Expand Down
5 changes: 5 additions & 0 deletions haxe/ui/components/Label.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
60 changes: 0 additions & 60 deletions haxe/ui/core/Component.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1951,8 +1951,6 @@ class Component extends ComponentImpl
if (_componentWidth != _actualWidth || _componentHeight != _actualHeight) {
_actualWidth = _componentWidth;
_actualHeight = _componentHeight;

enforceSizeConstraints();

if (parentComponent != null) {
parentComponent.invalidateComponentLayout();
Expand All @@ -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) {
Expand Down
130 changes: 124 additions & 6 deletions haxe/ui/layouts/DefaultLayout.hx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,27 @@ class DefaultLayout extends Layout {
var cx:Null<Float> = null;
var cy:Null<Float> = 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;
}
Expand All @@ -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) {
Expand All @@ -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);

}
}

Expand Down
11 changes: 7 additions & 4 deletions haxe/ui/layouts/HorizontalLayout.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -86,17 +86,20 @@ 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);
}
}
}

if (visibleChildren > 1) {
size.width -= horizontalSpacing * (visibleChildren - 1);
}

if (size.width < 0) {
if (size.width <= 0) {
size.width = 0;
visibleChildren--;
}

return size;
Expand Down
Loading