From 20a4a824db348ebd1529fe872bc07eec26259391 Mon Sep 17 00:00:00 2001 From: Topvennie Date: Mon, 6 Jan 2025 23:17:04 +0100 Subject: [PATCH] chore(gamification): center avatars --- tui/view/gamification/gamification.go | 3 ++- tui/view/gamification/styles.go | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tui/view/gamification/gamification.go b/tui/view/gamification/gamification.go index 1ef9d78..27bdc42 100644 --- a/tui/view/gamification/gamification.go +++ b/tui/view/gamification/gamification.go @@ -84,8 +84,9 @@ func (m *Model) View() string { positions[i].Inherit(sName).Render(fmt.Sprintf("%d. %s", i+1, item.item.Name)), sScore.Render(strconv.Itoa(int(item.item.Score))), ) + im := sAvatar.Render(view.ImageToString(item.image, wColumn, sAll.GetHeight()-lipgloss.Height(user))) - column := lipgloss.JoinVertical(lipgloss.Left, view.ImageToString(item.image, wAvatar, sAll.GetHeight()-lipgloss.Height(user)), user) + column := lipgloss.JoinVertical(lipgloss.Left, im, user) columns = append(columns, sColumn.Render(column)) } diff --git a/tui/view/gamification/styles.go b/tui/view/gamification/styles.go index cbc3d5c..0f7bcf0 100644 --- a/tui/view/gamification/styles.go +++ b/tui/view/gamification/styles.go @@ -17,16 +17,17 @@ var ( var base = lipgloss.NewStyle() // All style -var sAll = base.Align(lipgloss.Center) +var sAll = base.Align(lipgloss.Center).AlignVertical(lipgloss.Center) // Styles var ( - wAvatar = 20 // Width of an avatar + wColumn = 20 // Width of an avatar wAmount = 4 // Amount of people that are shown - sColumn = base.Margin(2) + sColumn = base.Margin(0, 1) sName = base.Align(lipgloss.Center) sScore = base.Align(lipgloss.Center) + sAvatar = base.Align(lipgloss.Center) ) // Styles for the positions @@ -42,8 +43,9 @@ func (m *Model) updateStyles() { sAll = sAll.Width(m.width).Height(m.height).MaxHeight(m.height) // Adjust styles - wAvatar = (sAll.GetWidth() - view.GetOuterWidth(sAll) - view.GetOuterWidth(sColumn)*wAmount) / wAmount + wColumn = (sAll.GetWidth() - view.GetOuterWidth(sAll) - view.GetOuterWidth(sColumn)*wAmount) / wAmount - sName = sName.Width(wAvatar).BorderStyle(lipgloss.NormalBorder()).BorderBottom(true).BorderForeground(cBorder) - sScore = sScore.Width(wAvatar) + sName = sName.Width(wColumn).BorderStyle(lipgloss.NormalBorder()).BorderBottom(true).BorderForeground(cBorder) + sScore = sScore.Width(wColumn) + sAvatar = sAvatar.Width(wColumn) }