diff --git a/internal/ui/build_page.go b/internal/ui/build_page.go index fc1acc5..b9f9409 100644 --- a/internal/ui/build_page.go +++ b/internal/ui/build_page.go @@ -240,6 +240,7 @@ func (p *BuildPage) updateFileBuildProgress(dp *dto.BuildFileProgress) { } progressBar := strings.Repeat("━", barWidth) + strings.Repeat(" ", fillerWidth) cell := p.buildTable.GetCell(dp.FileId+1, col) + cell.SetExpansion(p.buildTable.colWeight[col]) cell.Text = fmt.Sprintf("%s |%s|", progressText, progressBar) ui.Draw() } @@ -282,6 +283,7 @@ func (p *BuildPage) updateFileCopyProgress(dp *dto.CopyFileProgress) { } progressBar := strings.Repeat("━", barWidth) + strings.Repeat(" ", fillerWidth) cell := p.copyTable.GetCell(dp.FileId+1, col) + cell.SetExpansion(p.copyTable.colWeight[col]) cell.Text = fmt.Sprintf("%s |%s|", progressText, progressBar) ui.Draw() } @@ -326,6 +328,7 @@ func (p *BuildPage) updateFileUploadProgress(dp *dto.UploadFileProgress) { } progressBar := strings.Repeat("━", barWidth) + strings.Repeat(" ", fillerWidth) cell := p.uploadTable.GetCell(dp.FileId+1, col) + cell.SetExpansion(p.uploadTable.colWeight[col]) cell.Text = fmt.Sprintf("%s |%s|", progressText, progressBar) ui.Draw() } diff --git a/internal/ui/download_page.go b/internal/ui/download_page.go index 4b07966..d50a5eb 100644 --- a/internal/ui/download_page.go +++ b/internal/ui/download_page.go @@ -152,6 +152,7 @@ func (p *DownloadPage) updateFileProgress(dp *dto.DownloadFileProgress) { } progressBar := strings.Repeat("━", barWidth) + strings.Repeat(" ", fillerWidth) cell := p.filesTable.GetCell(dp.FileId+1, col) + cell.SetExpansion(p.filesTable.colWeight[col]) cell.Text = fmt.Sprintf("%s |%s|", progressText, progressBar) ui.Draw() } diff --git a/internal/ui/encoding_page.go b/internal/ui/encoding_page.go index 79dd1ae..075688d 100644 --- a/internal/ui/encoding_page.go +++ b/internal/ui/encoding_page.go @@ -151,6 +151,7 @@ func (p *EncodingPage) updateFileProgress(dp *dto.EncodingFileProgress) { } progressBar := strings.Repeat("━", barWidth) + strings.Repeat(" ", fillerWidth) cell := p.filesTable.GetCell(dp.FileId+1, col) + cell.SetExpansion(p.filesTable.colWeight[col]) cell.Text = fmt.Sprintf("%s |%s|", progressText, progressBar) ui.Draw() } diff --git a/internal/ui/wrappers.go b/internal/ui/wrappers.go index 6734a3f..63100ed 100644 --- a/internal/ui/wrappers.go +++ b/internal/ui/wrappers.go @@ -2,6 +2,7 @@ package ui import ( "fmt" + "math" "strconv" "sync" @@ -126,7 +127,7 @@ type table struct { func newTable() *table { t := &table{} t.Table = tview.NewTable() - // t.Table.SetDrawFunc(t.draw) + t.Table.SetDrawFunc(t.draw) t.Table.SetSelectable(true, false) t.Table.SetSeparator(tview.Borders.Vertical) // t.Table.SetSortClicked(false) @@ -151,10 +152,10 @@ func (t *table) SetMouseDblClickFunc(f func(row, column int)) { }) } -// func (t *table) draw(screen tcell.Screen, x int, y int, width int, height int) (int, int, int, int) { -// t.recalculateColumnWidths() -// return t.Table.GetInnerRect() -// } +func (t *table) draw(screen tcell.Screen, x int, y int, width int, height int) (int, int, int, int) { + t.recalculateColumnWidths() + return t.Table.GetInnerRect() +} func (t *table) setHeaders(headers ...string) { t.headers = headers @@ -170,15 +171,15 @@ func (t *table) setAlign(aligns ...uint) { } func (t *table) showHeader() { - for c, h := range t.headers { + for col, h := range t.headers { cell := tview.NewTableCell(h) cell.SetTextColor(yellow) cell.SetBackgroundColor(blue) cell.SetAlign(tview.AlignCenter) - cell.SetExpansion(t.colWeight[c]) - // cell.SetMaxWidth(t.colWidth[c]) + cell.SetExpansion(t.colWeight[col]) + cell.SetMaxWidth(t.colWidth[col]) cell.NotSelectable = true - t.SetCell(0, c, cell) + t.SetCell(0, col, cell) } t.SetFixed(1, 0) t.Select(1, 0) @@ -190,7 +191,7 @@ func (t *table) appendRow(cols ...string) { cell := tview.NewTableCell(val) cell.SetAlign(int(t.aligns[col])) cell.SetExpansion(t.colWeight[col]) - // cell.SetMaxWidth(t.colWidth[col]) + cell.SetMaxWidth(t.colWidth[col]) t.SetCell(row, col, cell) } } @@ -209,31 +210,31 @@ func (t *table) appendSeparator(cols ...string) { } } -// // TODO - implement more accurate calculation -// func (t *table) recalculateColumnWidths() { -// if len(t.colWeight) == 0 { -// return -// } -// allWeights := 0 -// for _, w := range t.colWeight { -// allWeights += w -// } -// _, _, tw, _ := t.Table.GetInnerRect() // table weight -// m := (float64(tw) / float64(allWeights)) // multiplier - -// t.colWidth = make([]int, len(t.colWeight)) -// for c := range t.colWidth { -// width := int(math.Round(m * float64(t.colWeight[c]))) -// t.colWidth[c] = width -// } -// } - -// func (t *table) getColumnWidth(col int) int { -// if len(t.colWidth) == 0 { -// t.recalculateColumnWidths() -// } -// return t.colWidth[col] -// } +// TODO - implement more accurate calculation +func (t *table) recalculateColumnWidths() { + if len(t.colWeight) == 0 { + return + } + allWeights := 0 + for _, w := range t.colWeight { + allWeights += w + } + _, _, tw, _ := t.Table.GetInnerRect() // table weight + m := (float64(tw) / float64(allWeights)) // multiplier + + t.colWidth = make([]int, len(t.colWeight)) + for c := range t.colWidth { + width := int(math.Round(m * float64(t.colWeight[c]))) + t.colWidth[c] = width + } +} + +func (t *table) getColumnWidth(col int) int { + if len(t.colWidth) == 0 { + t.recalculateColumnWidths() + } + return t.colWidth[col] +} // ////////////////////////////////////////////////////////////// // tview.Table wrapper (vertical layout)