From 2438954728f18b665262d89c04794be2c12d9b23 Mon Sep 17 00:00:00 2001 From: Topvennie Date: Mon, 6 Jan 2025 22:01:05 +0100 Subject: [PATCH 1/3] fix(song): add max height for smaller screens --- tui/view/song/style.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tui/view/song/style.go b/tui/view/song/style.go index 67f987b..062d8f2 100644 --- a/tui/view/song/style.go +++ b/tui/view/song/style.go @@ -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)) } From 9aebc4ff796d2231dd2e3659c511e068ffa23fe7 Mon Sep 17 00:00:00 2001 From: Topvennie Date: Mon, 6 Jan 2025 22:06:30 +0100 Subject: [PATCH 2/3] fix(zess): add leading zero to week number --- tui/view/zess/view.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tui/view/zess/view.go b/tui/view/zess/view.go index 54e0938..5b2f811 100644 --- a/tui/view/zess/view.go +++ b/tui/view/zess/view.go @@ -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 { From 29bcf6ffaf3a3f916e05b28a39ebeceb038a8c6c Mon Sep 17 00:00:00 2001 From: Topvennie Date: Mon, 6 Jan 2025 22:47:12 +0100 Subject: [PATCH 3/3] fix(gamification): properly resize avatar --- tui/view/event/view.go | 4 ++-- tui/view/gamification/gamification.go | 2 +- tui/view/util.go | 22 +++++++++++++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tui/view/event/view.go b/tui/view/event/view.go index 94e3816..c6edcb9 100644 --- a/tui/view/event/view.go +++ b/tui/view/event/view.go @@ -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) } } @@ -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) } } diff --git a/tui/view/gamification/gamification.go b/tui/view/gamification/gamification.go index c19afb0..1ef9d78 100644 --- a/tui/view/gamification/gamification.go +++ b/tui/view/gamification/gamification.go @@ -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)) } diff --git a/tui/view/util.go b/tui/view/util.go index d3fb57e..3b78a04 100644 --- a/tui/view/util.go +++ b/tui/view/util.go @@ -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(" ") }