cyclable text macro for SimpleWindow

This commit is contained in:
2025-07-31 12:35:45 -05:00
parent 061fb64db9
commit 67c33b53a3
2 changed files with 19 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
(loadFrom "kiss-flixel" "src/kiss_flixel/SimpleWindowTools.kiss")
(import flixel.FlxState)
(import flixel.text.FlxText)
(import kiss_flixel.Log)
@@ -50,6 +52,10 @@
onDeselect
->_ (print "$letter deselected"))))
(prop &mut cycleIdx 0)
(prop cycle (for i (range 10) (* i "*")))
(makeCycleText window cycleIdx "Counter" cycle)
(window.makeTextV2 "{tab} Back"
(object onClick
->:Void _

View File

@@ -1,3 +1,4 @@
// TODO these evaluate args multiple times. withEvalOnce can't be used, because it strips the type annotations in the typeCase
(defMacro makeToggleText [window v label on off &opt objArgs]
(unless objArgs (set objArgs []))
`(.makeTextV2 ,window (+ ,label ": " (if ,v ,on ,off))
@@ -9,3 +10,15 @@
(set text.text (+ ,label ": " (if ,v ,on ,off))))
(never otherwise))
,@objArgs)))
(defMacro makeCycleText [window idxV label values &opt objArgs]
(unless objArgs (set objArgs []))
`(.makeTextV2 ,window (+ ,label ": " (nth ,values ,idxV))
(object
onClick ->self
(typeCase [self]
([:FlxText text]
(set ,idxV (% (+ ,idxV 1) .length ,values))
(set text.text (+ ,label ": " (nth ,values ,idxV))))
(never otherwise))
,@objArgs)))