Skip to content

Commit

Permalink
Fix height calculations (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhantac authored Aug 11, 2024
1 parent 753d6ea commit ca293d1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
7 changes: 6 additions & 1 deletion ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,14 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.help.Width = msg.Width
m.width = msg.Width
m.height = msg.Height
log.Printf("model: WindowSizeMsg: h=%v", msg.Height)

headerHeight := lipgloss.Height(header())
footerHeight := lipgloss.Height(m.help.View())
msg.Height = msg.Height - (headerHeight + footerHeight)
m.updateAllModels(msg)

log.Printf("WindowSizeMsg: full: h=%d, w=%d. mainView: h=%d, w=%d", m.height, msg.Width, msg.Height, msg.Width)

return m, m.refresh()

case tea.KeyMsg:
Expand Down
10 changes: 2 additions & 8 deletions ui/pager.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,14 @@ func (p *pager) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
case tea.WindowSizeMsg:
p.width = msg.Width
headerHeight := lipgloss.Height(header())
verticalMarginHeight := headerHeight + footerHeight
log.Printf("pager(%s): WindowSizeMsg: h=%v, headerHeight=%v, footerHeight=%v, verticalMarginHeight=%v", p.name, msg.Height, headerHeight, footerHeight, verticalMarginHeight)
if !p.ready {
log.Printf("pager(%s): not-ready. height=%v, ypos=%v", p.name, p.viewport.Height, p.viewport.YPosition)
p.viewport = viewport.New(msg.Width, msg.Height-verticalMarginHeight)
p.viewport.YPosition = headerHeight
p.viewport = viewport.New(msg.Width, msg.Height)
p.ready = true
} else {
p.viewport.Width = msg.Width
p.viewport.Height = msg.Height - verticalMarginHeight
p.viewport.Height = msg.Height
}
// case pagerLoading:
// p.viewport.SetContent("\n Loading...")

case tea.KeyMsg:
switch {
Expand Down
15 changes: 4 additions & 11 deletions ui/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)

type TableData interface {
Expand Down Expand Up @@ -57,13 +56,12 @@ func (t *Table) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
case tea.WindowSizeMsg:
tableWidth := percent(msg.Width, 100)
headerHeight := lipgloss.Height(header())
verticalMarginHeight := headerHeight + footerHeight
tableHeight := msg.Height - verticalMarginHeight - 3
log.Printf("table: height=%v, tableHeight=%v, verticalMarginHeight=%v", msg.Height, tableHeight, verticalMarginHeight)
tableHeight := msg.Height - 3
log.Printf("table: height=%v, tableHeight=%v", msg.Height, tableHeight)

t.SetWidth(tableWidth)
t.SetHeight(tableHeight)
t.height = tableHeight
t.Model.SetHeight(tableHeight)

case tea.KeyMsg:
switch msg.String() {
Expand Down Expand Up @@ -109,11 +107,6 @@ func (t *Table) SetWidth(width int) {
t.Model.SetWidth(width)
}

func (t *Table) SetHeight(height int) {
t.height = height
t.Model.SetHeight(height)
}

func (t *Table) SetColumns(firstRow table.Row) {
if len(t.columnPercentages) != len(firstRow) {
panic("length not equal")
Expand Down
2 changes: 1 addition & 1 deletion ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
footerHeight = 3
footerHeight = 2
)

var Version string
Expand Down

0 comments on commit ca293d1

Please sign in to comment.