dynamo-browse/internal/dynamo-browse/ui/teamodels/frame/frame.go
Leon Mika f65c5778a9
issue-50: fixed package name (#52)
Changed package name from github.com/lmika/audax to github.com/lmika/dynamo-browse
2023-04-17 08:31:03 +10:00

60 lines
1.2 KiB
Go

package frame
import (
"strings"
"github.com/charmbracelet/lipgloss"
"github.com/lmika/dynamo-browse/internal/dynamo-browse/ui/teamodels/utils"
)
var (
inactiveHeaderStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#000000")).
Background(lipgloss.Color("#d1d1d1"))
)
// Frame is a frame that appears in the
type FrameTitle struct {
header string
active bool
style Style
width int
}
type Style struct {
ActiveTitle lipgloss.Style
InactiveTitle lipgloss.Style
}
func NewFrameTitle(header string, active bool, style Style) FrameTitle {
return FrameTitle{header, active, style, 0}
}
func (f *FrameTitle) SetTitle(title string) {
f.header = title
}
func (f FrameTitle) View() string {
return f.headerView()
}
func (f *FrameTitle) Resize(w, h int) {
f.width = w
}
func (f FrameTitle) HeaderHeight() int {
return lipgloss.Height(f.headerView())
}
func (f FrameTitle) headerView() string {
style := f.style.InactiveTitle
if f.active {
style = f.style.ActiveTitle
}
titleText := f.header
title := style.Render(titleText)
line := style.Render(strings.Repeat(" ", utils.Max(0, f.width-lipgloss.Width(title))))
return lipgloss.JoinHorizontal(lipgloss.Left, title, line)
}