Skip to content

Commit

Permalink
chore(gamification): center avatars
Browse files Browse the repository at this point in the history
  • Loading branch information
Topvennie committed Jan 6, 2025
1 parent 3a8156b commit 20a4a82
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion tui/view/gamification/gamification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
14 changes: 8 additions & 6 deletions tui/view/gamification/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

0 comments on commit 20a4a82

Please sign in to comment.