Skip to content

Commit

Permalink
feat: added basic dynamic resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
TypicalAM committed Jan 20, 2023
1 parent 7201855 commit b835c06
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/model/browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Delete the item
return m.deleteItem(msg)

case tea.WindowSizeMsg:
// Resize the window
m.windowWidth = msg.Width
m.windowHeight = msg.Height

// 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)
}

case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "esc":
Expand Down
12 changes: 12 additions & 0 deletions internal/model/tab/category/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ func (m Model) Help() tab.Help {
}
}

// SetWidth sets the width of the tab
func (m Model) SetWidth(width 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
return m
}

// Init initializes the tab
func (m Model) Init() tea.Cmd {
return m.reader(m.title)
Expand Down
12 changes: 12 additions & 0 deletions internal/model/tab/feed/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ func (m Model) Help() tab.Help {
}
}

// SetWidth sets the width of the tab
func (m Model) SetWidth(width 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
return m
}

// Init initializes the tab
func (m Model) Init() tea.Cmd {
return tea.Batch(m.reader(m.title), m.loadingSpinner.Tick)
Expand Down
2 changes: 2 additions & 0 deletions internal/model/tab/tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type Tab interface {
Title() string
Type() Type
Help() Help
SetWidth(int) Tab
SetHeight(int) Tab

// bubbletea methods
Init() tea.Cmd
Expand Down
12 changes: 12 additions & 0 deletions internal/model/tab/welcome/welcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ func (m Model) Help() tab.Help {
}
}

// SetWidth sets the width of the tab
func (m Model) SetWidth(width 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
return m
}

// Init initializes the tab
func (m Model) Init() tea.Cmd {
return m.reader()
Expand Down

0 comments on commit b835c06

Please sign in to comment.