- commit
- ae51f4c6834d1aaea12035c7d2af0e510bf0ecc8
- parent
- 3ebcbc93554e213103a29bda679eefcf3936ad6a
- parent
- fdc4f5af5bad65ce0b82fbd01d1b8ed46aeb2f39
- author
- Dami <dami.etoile@gmail.com>
| M | model.go | 46 | +++++++++++++++++------------- |
@@ -81,6 +81,9 @@ type model struct {
8181 mode game.Mode8282 game game.Gamer8383 84+ width int // available content width (terminal - rootStyle frame)85+ height int // available content height (terminal - rootStyle frame)86+8487 debug bool8588 debugRenderer *glamour.TermRenderer8689 debuginfo string@@ -133,10 +136,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
133136 case tea.WindowSizeMsg:134137 h, v := rootStyle.GetFrameSize()135138 w, ht := msg.Width-h, msg.Height-v136- m.mainMenuList.SetSize(w, ht)137- m.gameSelectList.SetSize(w, ht)139+ m.width = w140+ m.height = ht141+ menuW, menuH := min(w, 64), min(ht, 24)142+ m.mainMenuList.SetSize(menuW, menuH)143+ m.gameSelectList.SetSize(menuW, menuH)138144 if m.state == modeSelectView {139- m.modeSelectList.SetSize(w, ht)145+ m.modeSelectList.SetSize(menuW, menuH)140146 }141147 if m.state == continueView {142148 m.continueTable.SetWidth(w)@@ -304,26 +310,27 @@ func (m model) handleEscape() (tea.Model, tea.Cmd) {
304310 }305311 306312 func (m model) View() string {307- var s string308-309313 switch m.state {310314 case mainMenuView:311- return rootStyle.Render(m.mainMenuList.View())315+ return rootStyle.Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, m.mainMenuList.View()))312316 case gameSelectView:313- return rootStyle.Render(m.gameSelectList.View())317+ return rootStyle.Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, m.gameSelectList.View()))314318 case modeSelectView:315- return rootStyle.Render(m.modeSelectList.View())319+ return rootStyle.Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, m.modeSelectList.View()))316320 case continueView:321+ var s string317322 if len(m.continueGames) == 0 {318- return rootStyle.Render("No saved games yet.\n\nPress Escape to return.")323+ s = "No saved games yet.\n\nPress Escape to return."324+ } else {325+ title := lipgloss.NewStyle().326+ Bold(true).327+ Foreground(lipgloss.AdaptiveColor{Light: "255", Dark: "255"}).328+ Background(menuAccent).329+ Padding(0, 1).330+ Render("Saved Games")331+ s = lipgloss.JoinVertical(lipgloss.Left, title, "", m.continueTable.View())319332 }320- title := lipgloss.NewStyle().321- Bold(true).322- Foreground(lipgloss.AdaptiveColor{Light: "255", Dark: "255"}).323- Background(menuAccent).324- Padding(0, 1).325- Render("Saved Games")326- return rootStyle.Render(lipgloss.JoinVertical(lipgloss.Left, title, "", m.continueTable.View()))333+ return rootStyle.Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, s))327334 case gameView:328335 if m.game == nil {329336 return ""@@ -332,16 +339,15 @@ func (m model) View() string {
332339 if m.debug {333340 debugInfo = debugStyle.Render(m.debuginfo)334341 }335- s = lipgloss.JoinVertical(lipgloss.Left,342+ s := lipgloss.JoinVertical(lipgloss.Left,336343 m.game.View(),337344 debugInfo,338345 )346+ return rootStyle.Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, s))339347 default:340- s = fmt.Sprintf("unknown state: %d", m.state)348+ s := fmt.Sprintf("unknown state: %d", m.state)341349 panic(s)342350 }343-344- return rootStyle.Render(s)345351 }346352 347353 func initList(items []list.Item, title string) list.Model {