Skip to content

Commit

Permalink
Some leaderboard visual changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DaltonSW committed Aug 10, 2024
1 parent 0ce5a19 commit 6b4099d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 42 deletions.
15 changes: 0 additions & 15 deletions internal/resources/Puzzle.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,6 @@ func wrapText(line string, width int) string {
return result
}

// type PuzzlePart struct {
// starObtained bool
// example string
// isPartB bool
// submissions []*Submission
// CorrectAnswer Value
// }
//
// type Submission struct {
// submissionVal Value
// correct bool
// timeSubmitted time.Time
// feedback string
// }

type Value struct {
number int
string string
Expand Down
18 changes: 3 additions & 15 deletions internal/tui/leaderboard_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ func (m LeaderboardModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

headerHeight := lipgloss.Height(m.headerView())
footerHeight := lipgloss.Height(m.footerView())
verticalMarginHeight := headerHeight + footerHeight

m.viewport = viewport.New(min(ViewportWidth, width), height-verticalMarginHeight)
m.viewport = viewport.New(min(ViewportWidth, width), height-headerHeight)
m.viewport.YPosition = headerHeight
m.viewport.HighPerformanceRendering = useHighPerformanceRenderer
m.viewport.SetContent(m.content)
Expand All @@ -68,11 +66,9 @@ func (m LeaderboardModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

case tea.WindowSizeMsg:
headerHeight := lipgloss.Height(m.headerView())
footerHeight := lipgloss.Height(m.footerView())
verticalMarginHeight := headerHeight + footerHeight

m.viewport.Width = min(ViewportWidth, msg.Width)
m.viewport.Height = msg.Height - verticalMarginHeight
m.viewport.Height = msg.Height - headerHeight

if useHighPerformanceRenderer {
cmds = append(cmds, viewport.Sync(m.viewport))
Expand All @@ -87,19 +83,11 @@ func (m LeaderboardModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m LeaderboardModel) View() string {
return fmt.Sprintf("%s\n%s\n%s", m.headerView(), m.viewport.View(), m.footerView())
return fmt.Sprintf("%s\n%s", m.headerView(), m.viewport.View())
}

func (m LeaderboardModel) headerView() string {
title := titleStyle.Render(m.title)
line := strings.Repeat("─", max(0, m.viewport.Width-lipgloss.Width(title)))
return lipgloss.JoinHorizontal(lipgloss.Center, title, line)
}

func (m LeaderboardModel) footerView() string {
info := infoStyle.Render(fmt.Sprintf("%3.f%%", m.viewport.ScrollPercent()*100))
line := strings.Repeat("─", max(0, m.viewport.Width-lipgloss.Width(info)))
sOut := lipgloss.JoinHorizontal(lipgloss.Center, line, info)

return sOut
}
24 changes: 12 additions & 12 deletions internal/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ var (
titleStyle = func() lipgloss.Style {
b := lipgloss.RoundedBorder()
b.Right = "├"
return lipgloss.NewStyle().BorderStyle(b).Padding(0, 1)
return lipgloss.NewStyle().BorderStyle(b).Padding(0, 1).Foreground(lipgloss.Color("#FFFF00")).Underline(true)
}()

infoStyle = func() lipgloss.Style {
b := lipgloss.RoundedBorder()
b.Left = "┤"
return titleStyle.BorderStyle(b)
return lipgloss.NewStyle().BorderStyle(b).Padding(0, 1)
}()
)

Expand All @@ -29,20 +29,20 @@ type helpKeymap struct {
Up key.Binding
Down key.Binding
Browser key.Binding
Refresh key.Binding
Submit key.Binding
Input key.Binding
Quit key.Binding
// Refresh key.Binding
// Submit key.Binding
Input key.Binding
Quit key.Binding
}

func (k helpKeymap) ShortHelp() []key.Binding {
return []key.Binding{k.Input, k.Browser, k.Refresh, k.Quit}
return []key.Binding{k.Input, k.Browser, k.Quit}
}

func (k helpKeymap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.Up, k.Down, k.Quit},
{k.Input, k.Browser, k.Refresh},
{k.Input, k.Browser},
}
}

Expand All @@ -59,10 +59,10 @@ var helpKeys = helpKeymap{
key.WithKeys("b"),
key.WithHelp("b", "[B]rowser"),
),
Refresh: key.NewBinding(
key.WithKeys("r"),
key.WithHelp("r", "[R]efresh Page"),
),
// Refresh: key.NewBinding(
// key.WithKeys("r"),
// key.WithHelp("r", "[R]efresh Page"),
// ),
// Submit: key.NewBinding(
// key.WithKeys("a"),
// key.WithHelp("a", "[A]nswer Puzzle"),
Expand Down

0 comments on commit 6b4099d

Please sign in to comment.