fix: content height on viewports expanding to max

This commit is contained in:
2026-04-30 15:39:25 +02:00
parent 06d8624f92
commit e2eb34498f
2 changed files with 35 additions and 24 deletions
+14 -8
View File
@@ -90,10 +90,10 @@ func New(options Options) Model {
height: 24, height: 24,
focus: focusStreamers, focus: focusStreamers,
authViewport: newAuthViewport(contentWidth(defaultViewWidth), authViewportHeight(24)), authViewport: newAuthViewport(contentWidth(defaultViewWidth), authViewportHeight(24)),
ircViewport: newIRCViewport(detailViewportWidth(defaultViewWidth), detailViewportHeight(24)), ircViewport: newIRCViewport(detailViewportWidth(defaultViewWidth), detailViewportHeight(24, "")),
minerViewport: newMinerViewport( minerViewport: newMinerViewport(
detailViewportWidth(defaultViewWidth), detailViewportWidth(defaultViewWidth),
detailViewportHeight(24), detailViewportHeight(24, ""),
), ),
} }
if options.AuthState != nil { if options.AuthState != nil {
@@ -370,9 +370,9 @@ func (m *Model) resizeComponents() {
m.authViewport.Width = contentWidth(m.width) m.authViewport.Width = contentWidth(m.width)
m.authViewport.Height = authViewportHeight(m.height) m.authViewport.Height = authViewportHeight(m.height)
m.ircViewport.Width = detailViewportWidth(m.width) m.ircViewport.Width = detailViewportWidth(m.width)
m.ircViewport.Height = detailViewportHeight(m.height) m.ircViewport.Height = detailViewportHeight(m.height, m.ircViewportContent())
m.minerViewport.Width = detailViewportWidth(m.width) m.minerViewport.Width = detailViewportWidth(m.width)
m.minerViewport.Height = detailViewportHeight(m.height) m.minerViewport.Height = detailViewportHeight(m.height, m.minerViewportContent())
} }
func (m *Model) syncAuthViewport() { func (m *Model) syncAuthViewport() {
@@ -388,24 +388,30 @@ func (m Model) authLogContent() string {
} }
func (m *Model) syncIRCViewport(forceBottom bool) { func (m *Model) syncIRCViewport(forceBottom bool) {
stickToBottom := forceBottom || m.ircViewport.AtBottom()
content := m.ircViewportContent()
m.ircViewport.Width = detailViewportWidth(m.width)
m.ircViewport.Height = detailViewportHeight(m.height, content)
if m.ircViewport.Width <= 0 || m.ircViewport.Height <= 0 { if m.ircViewport.Width <= 0 || m.ircViewport.Height <= 0 {
return return
} }
stickToBottom := forceBottom || m.ircViewport.AtBottom() m.ircViewport.SetContent(content)
m.ircViewport.SetContent(m.ircViewportContent())
if stickToBottom { if stickToBottom {
m.ircViewport.GotoBottom() m.ircViewport.GotoBottom()
} }
} }
func (m *Model) syncMinerViewport(forceBottom bool) { func (m *Model) syncMinerViewport(forceBottom bool) {
stickToBottom := forceBottom || m.minerViewport.AtBottom()
content := m.minerViewportContent()
m.minerViewport.Width = detailViewportWidth(m.width)
m.minerViewport.Height = detailViewportHeight(m.height, content)
if m.minerViewport.Width <= 0 || m.minerViewport.Height <= 0 { if m.minerViewport.Width <= 0 || m.minerViewport.Height <= 0 {
return return
} }
stickToBottom := forceBottom || m.minerViewport.AtBottom() m.minerViewport.SetContent(content)
m.minerViewport.SetContent(m.minerViewportContent())
if stickToBottom { if stickToBottom {
m.minerViewport.GotoBottom() m.minerViewport.GotoBottom()
} }
+21 -16
View File
@@ -9,7 +9,10 @@ import (
"parasocial/internal/twitch" "parasocial/internal/twitch"
) )
const dashboardPanelGap = 1 const (
dashboardPanelGap = 1
detailPanelHeaderHeight = 2
)
// View renders either the login log screen or the authenticated streamer dashboard. // View renders either the login log screen or the authenticated streamer dashboard.
func (m Model) View() string { func (m Model) View() string {
@@ -43,14 +46,16 @@ func (m Model) renderStreamerView() string {
rightStyle = focusedPanelStyle rightStyle = focusedPanelStyle
} }
leftContent := labelStyle.Render("Streamers") + "\n" + m.renderStreamerRows(streamerListHeight(m.height))
left := leftStyle. left := leftStyle.
Width(streamerListWidth(m.width)). Width(streamerListWidth(m.width)).
Height(panelHeight(m.height)). Height(panelHeight(m.height)).
Render(labelStyle.Render("Streamers") + "\n" + m.renderStreamerRows()) Render(leftContent)
rightContent := m.renderDetailPanel()
right := rightStyle. right := rightStyle.
Width(detailWidth(m.width)). Width(detailWidth(m.width)).
Height(panelHeight(m.height)). Height(panelHeight(m.height)).
Render(m.renderDetailPanel()) Render(rightContent)
body := lipgloss.JoinHorizontal(lipgloss.Top, left, strings.Repeat(" ", dashboardPanelGap), right) body := lipgloss.JoinHorizontal(lipgloss.Top, left, strings.Repeat(" ", dashboardPanelGap), right)
return dashboardPageStyle.Render(header+"\n\n"+body) + "\n" return dashboardPageStyle.Render(header+"\n\n"+body) + "\n"
@@ -142,8 +147,8 @@ func (m Model) renderMinerTab() string {
return m.minerViewport.View() return m.minerViewport.View()
} }
func (m Model) renderStreamerRows() string { func (m Model) renderStreamerRows(maxRows int) string {
entries := m.visibleStreamers() entries := m.visibleStreamers(maxRows)
if len(entries) == 0 { if len(entries) == 0 {
return mutedStyle.Render("none") return mutedStyle.Render("none")
} }
@@ -163,9 +168,9 @@ func (m Model) renderStreamerRows() string {
return strings.Join(lines, "\n") return strings.Join(lines, "\n")
} }
func (m Model) visibleStreamers() []twitch.StreamerEntry { func (m Model) visibleStreamers(maxRows int) []twitch.StreamerEntry {
entries := m.orderedStreamers() entries := m.orderedStreamers()
visible := max(1, streamerListHeight(m.height)) visible := max(1, maxRows)
if len(entries) <= visible { if len(entries) <= visible {
return entries return entries
} }
@@ -276,17 +281,17 @@ func detailViewportWidth(width int) int {
} }
func streamerListHeight(height int) int { func streamerListHeight(height int) int {
if height <= 0 { return max(1, dashboardPanelContentHeight(height)-1)
return 14
}
return max(4, height-10)
} }
func detailViewportHeight(height int) int { func detailViewportHeight(height int, content string) int {
if height <= 0 { contentHeight := max(1, lipgloss.Height(content))
return 9 maxBodyHeight := max(1, dashboardPanelContentHeight(height)-detailPanelHeaderHeight)
} return max(1, min(contentHeight, maxBodyHeight))
return max(4, panelHeight(height)-6) }
func dashboardPanelContentHeight(height int) int {
return max(1, panelHeight(height)-panelStyle.GetVerticalPadding())
} }
func panelHeight(height int) int { func panelHeight(height int) int {