Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tui/view/event/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (m *Model) viewToday() string {
if m.today.Poster != nil {
i, _, err := image.Decode(bytes.NewReader(m.today.Poster))
if err == nil {
poster = view.ImagetoString(wTodayPoster, i)
poster = view.ImageToString(i, wTodayPoster, 0)
}
}

Expand Down Expand Up @@ -42,7 +42,7 @@ func (m *Model) viewOverview() string {
if len(m.upcoming) > 0 && m.upcoming[0].Poster != nil {
i, _, err := image.Decode(bytes.NewReader(m.upcoming[0].Poster))
if err == nil {
poster = view.ImagetoString(wOvPoster, i)
poster = view.ImageToString(i, wOvPoster, 0)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tui/view/gamification/gamification.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (m *Model) View() string {
sScore.Render(strconv.Itoa(int(item.item.Score))),
)

column := lipgloss.JoinVertical(lipgloss.Left, view.ImagetoString(wAvatar, item.image), user)
column := lipgloss.JoinVertical(lipgloss.Left, view.ImageToString(item.image, wAvatar, sAll.GetHeight()-lipgloss.Height(user)), user)
columns = append(columns, sColumn.Render(column))
}

Expand Down
5 changes: 4 additions & 1 deletion tui/view/song/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,8 @@ func (m *Model) updateStyles() {
sStatusBar = sStatusBar.Width(m.width - view.GetOuterWidth(sStatusBar))

// Adjust the all styles
sAll = sAll.Height(m.height - view.GetOuterHeight(sAll)).Width(m.width - view.GetOuterWidth(sAll))
sAll = sAll.Height(m.height - view.GetOuterHeight(sAll)).
MaxHeight(m.height - view.GetOuterHeight(sAll)).
Width(m.width - view.GetOuterWidth(sAll)).
MaxWidth(m.width - view.GetOuterWidth(sAll))
}
22 changes: 17 additions & 5 deletions tui/view/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,29 @@ import (
"github.com/lucasb-eyer/go-colorful"
)

// ImagetoString converts an image to a
// The height gets resized according to the aspect ratio
func ImagetoString(width int, img image.Image) string {
img = imaging.Resize(img, width, 0, imaging.Lanczos)
// ImageToString converts an image to a string
// If either widht or height is 0 then the aspect ratio is kept
func ImageToString(img image.Image, width, height int) string {
if width == 0 || height == 0 {
return imageToString(imaging.Resize(img, width, height, imaging.Lanczos))
}

imgW := imaging.Resize(img, width, 0, imaging.Lanczos)
if imgW.Bounds().Dy() <= height {
return imageToString(imgW)
}

return imageToString(imaging.Resize(img, 0, height, imaging.Lanczos))
}

func imageToString(img image.Image) string {
b := img.Bounds()
imageWidth := b.Max.X
h := b.Max.Y
str := strings.Builder{}

for heightCounter := 0; heightCounter < h; heightCounter += 2 {
for x := imageWidth; x < width; x += 2 {
for x := imageWidth; x < img.Bounds().Dx(); x += 2 {
str.WriteString(" ")
}

Expand Down
2 changes: 1 addition & 1 deletion tui/view/zess/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (m *Model) viewStats() string {
rows := make([]string, 0, len(m.scans))

for _, scan := range m.scans {
week := sStatDate.Render(fmt.Sprintf("W%d - %s", scan.time.week, scan.start))
week := sStatDate.Render(fmt.Sprintf("W%02d - %s", scan.time.week, scan.start))

var amount string
if scan.amount == m.maxWeekScans {
Expand Down
Loading