aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-07-22 16:16:13 -0400
committerFlorian Fischer <florian.fischer@muhq.space>2025-07-24 12:22:10 -0400
commitee963b2772d6416fae9a11ffe7414b3e7eda7301 (patch)
tree94ac91956d44d071d66ff40f1a7509a5c455c9dd
parentc59b6d5e3e71ceebec87242b8c54457078ebfcbd (diff)
downloadmuhqs-game-ee963b2772d6416fae9a11ffe7414b3e7eda7301.tar.gz
muhqs-game-ee963b2772d6416fae9a11ffe7414b3e7eda7301.zip
present reset button on top of prompt
-rw-r--r--go/client/game.go9
-rw-r--r--go/ui/collection.go10
2 files changed, 16 insertions, 3 deletions
diff --git a/go/client/game.go b/go/client/game.go
index 19677ea5..5718371b 100644
--- a/go/client/game.go
+++ b/go/client/game.go
@@ -96,7 +96,7 @@ func newGame(app *app, gameState game.State) *Game {
g.resetButton = ui.NewRoundSimpleButton(
10,
- g.Height/2+DEFAULT_BUTTON_HEIGHT/2,
+ g.Height/2,
DEFAULT_BUTTON_HEIGHT,
"X",
func(*ui.SimpleButton) {
@@ -395,10 +395,13 @@ func (g *Game) declareAction(a game.Action) {
g.stateBar.ForceRedraw()
}
-// show a widget by adding it to the collection
+// show ensures a widget is visible by adding it to the collection or moving it to the last position.
func (g *Game) show(w ui.Widget) {
- if g.FindWidget(w) == -1 {
+ idx := g.FindWidget(w)
+ if idx == -1 {
g.AddWidget(w)
+ } else {
+ g.MoveIdxToLast(idx)
}
}
diff --git a/go/ui/collection.go b/go/ui/collection.go
index f60f5f3b..d4c2cd69 100644
--- a/go/ui/collection.go
+++ b/go/ui/collection.go
@@ -50,6 +50,16 @@ func (c *Collection) AddWidget(w Widget) {
if slices.Contains(c.widgets, w) {
log.Panicf("Double insertion of %v", w)
}
+ log.Println("add", w)
+ c.widgets = append(c.widgets, w)
+}
+
+// MoveIdxToLast shifts the widget at index idx to the last position.
+func (c *Collection) MoveIdxToLast(idx int) {
+ w := c.widgets[idx]
+ after := c.widgets[idx+1:]
+ c.widgets = c.widgets[:idx]
+ c.widgets = append(c.widgets, after...)
c.widgets = append(c.widgets, w)
}