Skip to content

Commit

Permalink
Merge pull request #640 from Shallowmallow/FixAutoWidthButtons
Browse files Browse the repository at this point in the history
Fix auto width buttons
  • Loading branch information
ianharrigan authored Oct 8, 2024
2 parents f009936 + 29ab6b5 commit a094608
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions haxe/ui/components/Button.hx
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,10 @@ class ButtonLayout extends DefaultLayout {
}

if (_component.autoWidth || textAlign != "center") { // label takes full usable size
var cx:Float = label.componentWidth + icon.componentWidth + horizontalSpacing;
var x:Float = Std.int((component.componentWidth / 2) - (cx / 2));
if (textAlign == "left") {
x = paddingLeft;
}
if (iconPosition == "right" || iconPosition == "center-right" || iconPosition == "far-right") {
return x + marginLeft(label) - marginRight(label);
return paddingLeft + marginLeft(label) - marginRight(label);
} else if (iconPosition == "left" || iconPosition == "center-left" || iconPosition == "far-left") {
x += horizontalSpacing + icon.componentWidth;
return x + marginLeft(label) - marginRight(label);
return paddingLeft + horizontalSpacing + icon.componentWidth + marginLeft(label) - marginRight(label);
}
}

Expand Down Expand Up @@ -363,17 +357,10 @@ class ButtonLayout extends DefaultLayout {
}

if (_component.autoWidth || textAlign != "center") { // label takes full usable size
var cx:Float = label.componentWidth + icon.componentWidth + horizontalSpacing;
var x:Float = Std.int((component.componentWidth / 2) - (cx / 2));
if (textAlign == "left") {
x = paddingLeft;
}

if (iconPosition == "right" || iconPosition == "center-right" || iconPosition == "far-right") {
x += horizontalSpacing + label.componentWidth;
return x + marginLeft(icon) - marginRight(icon);
return paddingLeft + horizontalSpacing + label.componentWidth + marginLeft(icon) - marginRight(icon);
} else if (iconPosition == "left" || iconPosition == "center-left" || iconPosition == "far-left") {
return x + marginLeft(icon) - marginRight(icon);
return paddingLeft + marginLeft(icon) - marginRight(icon);
}
}

Expand Down

0 comments on commit a094608

Please sign in to comment.