From dcb9c92e89883a729e77e0299f5c6712e83adf16 Mon Sep 17 00:00:00 2001 From: Ian Harrigan Date: Mon, 23 Sep 2024 17:13:10 +0200 Subject: [PATCH] fix for https://github.com/haxeui/haxeui-core/issues/633 --- haxe/ui/core/Component.hx | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/haxe/ui/core/Component.hx b/haxe/ui/core/Component.hx index 0e54de365..7a40c3478 100644 --- a/haxe/ui/core/Component.hx +++ b/haxe/ui/core/Component.hx @@ -660,31 +660,29 @@ class Component extends ComponentImpl } private function assignPositionClasses(invalidate:Bool = true) { - if (childComponents.length == 1) { - childComponents[0].addClasses(["first", "last"], invalidate); - return; - } - var effectiveChildCount = 0; - for (i in 0...childComponents.length) { - var c = childComponents[i]; - if (!c.includeInLayout) { + var effectiveChildren = []; + for (c in childComponents) { + if (!c.includeInLayout || c.hidden) { continue; } - effectiveChildCount++; + effectiveChildren.push(c); + } + + if (effectiveChildren.length == 1) { + effectiveChildren[0].addClasses(["first", "last"], invalidate); + return; } + var n = 0; - for (i in 0...childComponents.length) { - var c = childComponents[i]; - if (!c.includeInLayout) { - continue; - } - if (i == 0) { + for (c in effectiveChildren) { + if (n == 0) { c.swapClass("first", "last", invalidate); - } else if (i == effectiveChildCount - 1) { + } else if (n == effectiveChildren.length - 1) { c.swapClass("last", "first", invalidate); } else { c.removeClasses(["first", "last"], invalidate); } + n++; } }