1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
package testdata
import (
tui "github.com/grindlemire/go-tui"
)
type myModal struct {
app *tui.App
showModal *tui.State[bool]
gameOver *tui.State[bool]
confirmBtn tui.Ref
}
func MyModal() *myModal {
return &myModal{
showModal: tui.NewState(false),
gameOver: tui.NewState(false),
}
}
func (c *myModal) gameOverKeys() tui.KeyMap {
return tui.KeyMap{
tui.OnPreemptStop(tui.Rune('n'), func(ke tui.KeyEvent) {}),
tui.OnPreemptStop(tui.Rune('q'), func(ke tui.KeyEvent) {}),
}
}
func (c *myModal) Render(app *tui.App) *tui.Element {
__tui_0 := tui.New(
tui.WithDisplay(tui.DisplayFlex), tui.WithDirection(tui.Column),
)
__tui_1 := tui.New(
tui.WithText("Background content"),
)
__tui_0.AddChild(__tui_1)
__tui_2 := app.MountPersistent(c, 0, func() tui.Component {
return tui.NewModal(
tui.WithModalOpen(c.showModal),
tui.WithModalBackdrop("dim"),
tui.WithModalElementOptions(tui.WithJustify(tui.JustifyCenter), tui.WithAlign(tui.AlignCenter)),
)
})
__tui_3 := tui.New(
tui.WithWidth(40),
tui.WithBorder(tui.BorderRounded),
tui.WithPadding(2),
tui.WithDisplay(tui.DisplayFlex), tui.WithDirection(tui.Column),
tui.WithGap(1),
)
__tui_4 := tui.New(
tui.WithText("Are you sure?"),
tui.WithTextStyle(tui.NewStyle().Bold()),
)
__tui_3.AddChild(__tui_4)
__tui_5 := tui.New()
c.confirmBtn.Set(__tui_5)
__tui_6 := tui.New(tui.WithText("OK"))
__tui_5.AddChild(__tui_6)
__tui_3.AddChild(__tui_5)
__tui_2.AddChild(__tui_3)
__tui_0.AddChild(__tui_2)
__tui_7 := app.MountPersistent(c, 1, func() tui.Component {
return tui.NewModal(
tui.WithModalOpen(c.gameOver),
tui.WithModalKeyMap(c.gameOverKeys()),
tui.WithModalTrapFocus(false),
)
})
__tui_8 := tui.New(
tui.WithBorder(tui.BorderRounded),
tui.WithPadding(2),
)
__tui_9 := tui.New(
tui.WithText("Game Over"),
)
__tui_8.AddChild(__tui_9)
__tui_7.AddChild(__tui_8)
__tui_0.AddChild(__tui_7)
return __tui_0
}
func (c *myModal) UpdateProps(fresh tui.Component) {
f, ok := fresh.(*myModal)
if !ok {
return
}
c.app = f.app
}
var _ tui.PropsUpdater = (*myModal)(nil)
func (c *myModal) bindAppFields(app *tui.App) {
c.app = app
if c.showModal != nil {
c.showModal.BindApp(app)
}
if c.gameOver != nil {
c.gameOver.BindApp(app)
}
}
func (c *myModal) BindApp(app *tui.App) {
c.bindAppFields(app)
}
var _ tui.AppBinder = (*myModal)(nil)
|