Setting table.WithWidth to the full terminal width caused the table to fill the screen, preventing lipgloss.Place from centering it. Compute the table width from column definitions so centering works correctly.
- commit
- 345254c08b80aaf6ab9c6520af7951f9f5ff5f85
- parent
- 1a9a2e294dbd51d2f8d3eb93a4401a77f4b0b890
- author
- Dami <dami.etoile@gmail.com>
| M | ui/ | 11 | +++++++++-- |
| M | update.go | 2 | +- |
@@ -25,7 +25,7 @@ func FormatStatus(s store.GameStatus) string {
2525 2626 // InitContinueTable loads saved games from the store and builds the table2727 // widget. Returns the table, the loaded games, and the column definitions.28-func InitContinueTable(s *store.Store, width, height int) (table.Model, []store.GameRecord) {28+func InitContinueTable(s *store.Store, height int) (table.Model, []store.GameRecord) {2929 games, err := s.ListGames()3030 if err != nil {3131 log.Printf("failed to list games: %v", err)@@ -51,11 +51,18 @@ func InitContinueTable(s *store.Store, width, height int) (table.Model, []store.
5151 }5252 }5353 54+ tableWidth := 055+ for _, c := range columns {56+ tableWidth += c.Width57+ }58+ // Account for column gaps (2 chars between each column).59+ tableWidth += (len(columns) - 1) * 260+5461 t := table.New(5562 table.WithColumns(columns),5663 table.WithRows(rows),5764 table.WithFocused(true),58- table.WithWidth(width),65+ table.WithWidth(tableWidth),5966 table.WithHeight(max(height-2, 1)),6067 )6168 @@ -148,7 +148,7 @@ func (m model) handleMainMenuEnter() (tea.Model, tea.Cmd) {
148148 case "Generate":149149 m.state = gameSelectView150150 case "Continue":151- m.continueTable, m.continueGames = ui.InitContinueTable(m.store, m.width, m.height)151+ m.continueTable, m.continueGames = ui.InitContinueTable(m.store, m.height)152152 m.state = continueView153153 case "Guides":154154 m.helpSelectList = ui.InitList(GameCategories, "How to Play")