Skip to content

Commit

Permalink
Merge pull request #642 from Shallowmallow/NoIconWidthButton
Browse files Browse the repository at this point in the history
Fix button with icon with no width
  • Loading branch information
ianharrigan authored Oct 8, 2024
2 parents 75ce97b + 2b0c52e commit 2252c16
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions haxe/ui/components/Button.hx
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ class ButtonLayout extends DefaultLayout {
icon = null;
}

if (label != null && label.componentWidth != 0){
if (label != null && label.componentWidth != 0 && label.componentHeight != 0) {
label.top = calcLabelPositionTop();
label.left = calcLabelPositionLeft();
}
if (icon != null) {
if (icon != null && icon.componentWidth != 0 && icon.componentHeight != 0) {
if (label != null) {
icon.left = calcIconPositionLeft(label.left);
} else {
Expand All @@ -243,9 +243,6 @@ class ButtonLayout extends DefaultLayout {
var label:Label = component.findComponent(Label, false);
var icon:Image = component.findComponent("button-icon", false);


if (label == null || label.componentHeight == 0) return 0;

if (label != null && icon == null){
return Std.int((component.componentHeight / 2) - (label.componentHeight / 2)) + marginTop(label) - marginBottom(label);
}
Expand All @@ -270,8 +267,6 @@ class ButtonLayout extends DefaultLayout {
var icon:Image = component.findComponent("button-icon", false);
var label:Label = component.findComponent(Label, false);

if (icon == null || icon.componentWidth == 0) return 0;

if (label == null && icon != null) {
return Std.int((component.componentHeight / 2) - (icon.componentHeight / 2)) + marginTop(icon) - marginBottom(icon);
}
Expand All @@ -298,9 +293,6 @@ class ButtonLayout extends DefaultLayout {
var icon:Image = component.findComponent("button-icon", false);
var textAlign = cast(component, Button).textAlign;


if (label == null || label.componentWidth == 0) return 0;

if (label != null && icon == null){
return getTextAlignPos(label, component.componentWidth);
}
Expand All @@ -309,7 +301,9 @@ class ButtonLayout extends DefaultLayout {
if (iconPosition == "right" || iconPosition == "center-right" || iconPosition == "far-right") {
return paddingLeft + marginLeft(label) - marginRight(label);
} else if (iconPosition == "left" || iconPosition == "center-left" || iconPosition == "far-left") {
return paddingLeft + horizontalSpacing + icon.componentWidth + marginLeft(label) - marginRight(label);
var x = paddingLeft;
if (icon.componentWidth != 0) x += icon.componentWidth + horizontalSpacing;
return x + marginLeft(label) - marginRight(label);
}
}

Expand Down Expand Up @@ -344,8 +338,6 @@ class ButtonLayout extends DefaultLayout {
var label:Label = component.findComponent(Label, false);
var textAlign = cast(component, Button).textAlign;

if (icon == null || icon.componentWidth == 0) return 0;

if (label == null && icon != null) {
if (iconPosition == "far-right") {
return (component.componentWidth - icon.componentWidth - paddingRight) + marginLeft(icon) - marginRight(icon);
Expand Down

0 comments on commit 2252c16

Please sign in to comment.