Skip to content

Commit

Permalink
fix: fixed the dynamic resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
TypicalAM committed May 21, 2023
1 parent 8d93395 commit 18ea34d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
3 changes: 1 addition & 2 deletions internal/model/browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

// Resize every tab
for i := range m.tabs {
m.tabs[i] = m.tabs[i].SetWidth(m.windowWidth)
m.tabs[i] = m.tabs[i].SetHeight(m.windowHeight - 5)
m.tabs[i] = m.tabs[i].SetSize(m.windowWidth, m.windowHeight-5)
}

case tea.KeyMsg:
Expand Down
17 changes: 17 additions & 0 deletions internal/model/simplelist/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@ func (m Model) View() string {
return lipgloss.JoinVertical(lipgloss.Top, sections...)
}

// SetHeight sets the height of the list
func (m *Model) SetHeight(height int) {
// Calculate the items per page
if m.showDesc {
m.itemsPerPage = (height - lipgloss.Height(m.style.titleStyle.Render(""))) / 2
} else {
m.itemsPerPage = height - lipgloss.Height(m.style.titleStyle.Render(""))
}

m.height = height
}

// Items returns the items in the list
func (m Model) Items() []list.Item {
return m.items
}

// SetItems sets the items in the list
func (m *Model) SetItems(items []list.Item) {
if len(items) > 36 {
Expand Down
10 changes: 3 additions & 7 deletions internal/model/tab/category/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,11 @@ func (m Model) Type() tab.Type {
return tab.Category
}

// SetWidth sets the width of the tab
func (m Model) SetWidth(width int) tab.Tab {
// SetSize sets the dimensions of the tab
func (m Model) SetSize(width, height int) tab.Tab {
m.width = width
return m
}

// SetHeight sets the height of the tab
func (m Model) SetHeight(height int) tab.Tab {
m.height = height
m.list.SetHeight(m.height)
return m
}

Expand Down
17 changes: 9 additions & 8 deletions internal/model/tab/feed/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,17 @@ func (m Model) Type() tab.Type {
return tab.Feed
}

// SetWidth sets the width of the tab
func (m Model) SetWidth(width int) tab.Tab {
// SetSize sets the dimensions of the tab
func (m Model) SetSize(width, height int) tab.Tab {
listWidth := width / 4
viewportWidth := width - listWidth - 2
m.list.SetSize(listWidth, height)
m.viewport.Width = viewportWidth
m.viewport.Height = height
m.width = width
return m
}

// SetHeight sets the height of the tab
func (m Model) SetHeight(height int) tab.Tab {
m.height = height
return m
newTab, _ := m.updateViewport()
return newTab
}

func (m Model) ShowHelp() string {
Expand Down
3 changes: 1 addition & 2 deletions internal/model/tab/tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ type Tab interface {
// general fields
Title() string
Type() Type
SetWidth(int) Tab
SetHeight(int) Tab
SetSize(width, height int) Tab
ShowHelp() string

// bubbletea methods
Expand Down
10 changes: 3 additions & 7 deletions internal/model/tab/welcome/welcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,11 @@ func (m Model) Type() tab.Type {
return tab.Welcome
}

// SetWidth sets the width of the tab
func (m Model) SetWidth(width int) tab.Tab {
// SetSize sets the dimensions of the tab
func (m Model) SetSize(width, height int) tab.Tab {
m.width = width
return m
}

// SetHeight sets the height of the tab
func (m Model) SetHeight(height int) tab.Tab {
m.height = height
m.list.SetHeight(m.height)
return m
}

Expand Down

0 comments on commit 18ea34d

Please sign in to comment.