- commit
- fdc4f5af5bad65ce0b82fbd01d1b8ed46aeb2f39
- parent
- ff6f3b2af1c53ba561df91c1fe1820fdd2d32eba
- author
- Dami <dami.etoile@gmail.com>
| M | model.go | 46 | +++++++++++++++++------------- |
@@ -79,6 +79,9 @@ type model struct {
7979 mode game.Mode8080 game game.Gamer8181 82+ width int // available content width (terminal - rootStyle frame)83+ height int // available content height (terminal - rootStyle frame)84+8285 debug bool8386 debugRenderer *glamour.TermRenderer8487 debuginfo string@@ -131,10 +134,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
131134 case tea.WindowSizeMsg:132135 h, v := rootStyle.GetFrameSize()133136 w, ht := msg.Width-h, msg.Height-v134- m.mainMenuList.SetSize(w, ht)135- m.gameSelectList.SetSize(w, ht)137+ m.width = w138+ m.height = ht139+ menuW, menuH := min(w, 64), min(ht, 24)140+ m.mainMenuList.SetSize(menuW, menuH)141+ m.gameSelectList.SetSize(menuW, menuH)136142 if m.state == modeSelectView {137- m.modeSelectList.SetSize(w, ht)143+ m.modeSelectList.SetSize(menuW, menuH)138144 }139145 if m.state == continueView {140146 m.continueTable.SetWidth(w)@@ -302,26 +308,27 @@ func (m model) handleEscape() (tea.Model, tea.Cmd) {
302308 }303309 304310 func (m model) View() string {305- var s string306-307311 switch m.state {308312 case mainMenuView:309- return rootStyle.Render(m.mainMenuList.View())313+ return rootStyle.Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, m.mainMenuList.View()))310314 case gameSelectView:311- return rootStyle.Render(m.gameSelectList.View())315+ return rootStyle.Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, m.gameSelectList.View()))312316 case modeSelectView:313- return rootStyle.Render(m.modeSelectList.View())317+ return rootStyle.Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, m.modeSelectList.View()))314318 case continueView:319+ var s string315320 if len(m.continueGames) == 0 {316- return rootStyle.Render("No saved games yet.\n\nPress Escape to return.")321+ s = "No saved games yet.\n\nPress Escape to return."322+ } else {323+ title := lipgloss.NewStyle().324+ Bold(true).325+ Foreground(lipgloss.AdaptiveColor{Light: "255", Dark: "255"}).326+ Background(menuAccent).327+ Padding(0, 1).328+ Render("Saved Games")329+ s = lipgloss.JoinVertical(lipgloss.Left, title, "", m.continueTable.View())317330 }318- title := lipgloss.NewStyle().319- Bold(true).320- Foreground(lipgloss.AdaptiveColor{Light: "255", Dark: "255"}).321- Background(menuAccent).322- Padding(0, 1).323- Render("Saved Games")324- return rootStyle.Render(lipgloss.JoinVertical(lipgloss.Left, title, "", m.continueTable.View()))331+ return rootStyle.Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, s))325332 case gameView:326333 if m.game == nil {327334 return ""@@ -330,16 +337,15 @@ func (m model) View() string {
330337 if m.debug {331338 debugInfo = debugStyle.Render(m.debuginfo)332339 }333- s = lipgloss.JoinVertical(lipgloss.Left,340+ s := lipgloss.JoinVertical(lipgloss.Left,334341 m.game.View(),335342 debugInfo,336343 )344+ return rootStyle.Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, s))337345 default:338- s = fmt.Sprintf("unknown state: %d", m.state)346+ s := fmt.Sprintf("unknown state: %d", m.state)339347 panic(s)340348 }341-342- return rootStyle.Render(s)343349 }344350 345351 func initList(items []list.Item, title string) list.Model {