Skip to content

Commit

Permalink
Display rendering improved
Browse files Browse the repository at this point in the history
  • Loading branch information
vpoluyaktov committed Dec 14, 2023
1 parent b885dae commit 1361a0c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
3 changes: 3 additions & 0 deletions internal/ui/build_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down
1 change: 1 addition & 0 deletions internal/ui/download_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
1 change: 1 addition & 0 deletions internal/ui/encoding_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
71 changes: 36 additions & 35 deletions internal/ui/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ui

import (
"fmt"
"math"
"strconv"
"sync"

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
}
}
Expand All @@ -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)
Expand Down

0 comments on commit 1361a0c

Please sign in to comment.