From 2b0c52e68df11649a11b109c32c6529ccd5a2e7f Mon Sep 17 00:00:00 2001 From: Shallowmallow Date: Tue, 8 Oct 2024 14:33:30 +0200 Subject: [PATCH] Fix button with icon with no width --- haxe/ui/components/Button.hx | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/haxe/ui/components/Button.hx b/haxe/ui/components/Button.hx index ad83cdceb..58a0afe25 100644 --- a/haxe/ui/components/Button.hx +++ b/haxe/ui/components/Button.hx @@ -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 { @@ -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); } @@ -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); } @@ -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); } @@ -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); } } @@ -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);