Skip to content

Commit

Permalink
Merge pull request #16 from BOTbkcd/dev
Browse files Browse the repository at this point in the history
Table now occupies full height
  • Loading branch information
BOTbkcd authored May 23, 2024
2 parents 4ada19c + 5ee202f commit 83d625d
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions tui/main_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.taskDetails.Focus()
m.navigationKeys = detailsNavigationKeys
}

m.updateViewDimensions(10)

return m, nil

case tea.WindowSizeMsg:
screenWidth = msg.Width
screenHeight = msg.Height
m.updateViewDimensions(14)
return m, nil

default:
Expand All @@ -100,6 +109,14 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

if m.showCustomInput {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
screenWidth = msg.Width
screenHeight = msg.Height
m.updateViewDimensions(14)
return m, nil
}

switch m.customInputType {
//Transfer control to delete confirmation model
case "delete":
Expand Down Expand Up @@ -418,6 +435,8 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.taskTable.Blur()
m.taskDetails.Blur()

m.updateViewDimensions(14)

m.showInput = true

return m, nil
Expand All @@ -438,6 +457,8 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.taskTable.Blur()
m.taskDetails.Blur()

m.updateViewDimensions(14)

m.showInput = true

return m, nil
Expand Down Expand Up @@ -469,6 +490,8 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.taskTable.Blur()
m.taskDetails.Blur()

m.updateViewDimensions(14)

m.showInput = true

return m, nil
Expand Down Expand Up @@ -577,17 +600,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.WindowSizeMsg:
screenWidth = msg.Width
screenHeight = msg.Height
if screenHeight < 35 {
tableViewHeight = 25 - min(35-screenHeight, 10)
} else {
tableViewHeight = 25
}

//Details box viewport dimensions & section width are set at the time of box creation,
//after that they have to be manually adjusted
m.taskDetails.viewport.Width = getDetailsBoxWidth()
m.taskDetails.viewport.Height = getDetailsBoxHeight()
m.updateDetailsBoxData(true)
m.updateViewDimensions(10)

if m.firstRender {
//updateSelectionData() is called here instead of being called from Init()
Expand Down Expand Up @@ -666,12 +679,12 @@ func (m *model) View() string {
}
}

func (m model) stackView() string {
func (m *model) stackView() string {
m.stackTable.SetHeight(tableViewHeight)
return lipgloss.JoinVertical(lipgloss.Center, m.stackTable.View(), m.stackFooter())
}

func (m model) stackFooter() string {
func (m *model) stackFooter() string {
stackFooterStyle := footerContainerStyle.Copy().
Width(stackTableWidth)

Expand All @@ -680,12 +693,12 @@ func (m model) stackFooter() string {
return stackFooterStyle.Render(info)
}

func (m model) taskView() string {
func (m *model) taskView() string {
m.taskTable.SetHeight(tableViewHeight)
return lipgloss.JoinVertical(lipgloss.Center, m.taskTable.View(), m.taskFooter())
}

func (m model) taskFooter() string {
func (m *model) taskFooter() string {
taskFooterStyle := footerContainerStyle.Copy().
Width(taskTableWidth)

Expand Down Expand Up @@ -789,3 +802,13 @@ func (m *model) preserveState() {
m.prevState.taskID = m.data[stackIndex].Tasks[taskIndex].ID
}
}

func (m *model) updateViewDimensions(offset int) {
tableViewHeight = screenHeight - offset

//Details box viewport dimensions & section width are set at the time of box creation,
//after that they have to be manually adjusted
m.taskDetails.viewport.Width = getDetailsBoxWidth()
m.taskDetails.viewport.Height = getDetailsBoxHeight()
m.updateDetailsBoxData(true)
}

0 comments on commit 83d625d

Please sign in to comment.