From c36c309d4b782660583f918b44ae93dae4fb38e3 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Mon, 3 Jul 2023 08:53:11 -0600 Subject: [PATCH] SimpleWindow allow non-layout controls --- src/kiss_flixel/SimpleWindow.kiss | 49 ++++++++++++++++++------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/kiss_flixel/SimpleWindow.kiss b/src/kiss_flixel/SimpleWindow.kiss index 81bc459..a478316 100644 --- a/src/kiss_flixel/SimpleWindow.kiss +++ b/src/kiss_flixel/SimpleWindow.kiss @@ -99,32 +99,40 @@ (prop :FlxTypedGroup inputTexts (new FlxTypedGroup)) -(method addControl [:FlxSprite control] +(prop &mut :Array nonLayoutControls []) + +(method addControl [:FlxSprite control &opt :Bool ignoreLayout] + (when ?ignoreLayout + (nonLayoutControls.push control)) (when (Std.isOfType control KissInputText) (inputTexts.add (cast control KissInputText))) (set control.cameras [controlCamera]) - (set control.x nextControlX) - (set control.y nextControlY) (controls.add control) - (+= nextControlY control.height) - // TODO controls that aren't the same height as text will be able to vertically overflow - (unless _useScrolling - (let [columnControls (controls.members.slice (if title 1 0))] - // Don't count special controls as part of any column: - (doFor c [xText leftText rightText] - (when c (columnControls.remove c))) - (doFor c columnTexts - (when c (columnControls.remove c))) + + (unless ?ignoreLayout + (set control.x nextControlX) + (set control.y nextControlY) + (+= nextControlY control.height) + // TODO controls that aren't the same height as text will be able to vertically overflow + (unless _useScrolling + (let [columnControls (controls.members.slice (if title 1 0))] + // Don't count special controls as part of any column: + (doFor c [xText leftText rightText] + (when c (columnControls.remove c))) + (doFor c columnTexts + (when c (columnControls.remove c))) + (doFor c nonLayoutControls + (when c (columnControls.remove c))) - (setNth columnWidths -1 (max (+ control.width textSize) (last columnWidths))) - (when (and columnControls (= 0 (% columnControls.length controlsPerColumn))) - (set nextControlY 0) - (when title (+= nextControlY control.height)) - (+= nextControlX (last columnWidths)) - (columnWidths.push 0) - (when (> (apply + columnWidths) width) - (makeScrollArrows))))) + (setNth columnWidths -1 (max (+ control.width textSize) (last columnWidths))) + (when (and columnControls (= 0 (% columnControls.length controlsPerColumn))) + (set nextControlY 0) + (when title (+= nextControlY control.height)) + (+= nextControlX (last columnWidths)) + (columnWidths.push 0) + (when (> (apply + columnWidths) width) + (makeScrollArrows)))))) control) (prop &mut :Bool _useScrolling false) @@ -308,6 +316,7 @@ (makeXControls) (set nextControlX 0) (set nextControlY 0) + (set nonLayoutControls []) (set titleText (makeText title titleColor))) (method :Void show [&opt :Int _cameraColumn]