2022-03-27 00:01:24 +00:00
|
|
|
package frame
|
|
|
|
|
|
|
|
import (
|
2022-03-27 21:58:41 +00:00
|
|
|
"strings"
|
|
|
|
|
2022-03-27 00:01:24 +00:00
|
|
|
"github.com/charmbracelet/lipgloss"
|
2023-04-16 22:31:03 +00:00
|
|
|
"github.com/lmika/dynamo-browse/internal/dynamo-browse/ui/teamodels/utils"
|
2022-03-27 00:01:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-03-27 00:40:32 +00:00
|
|
|
inactiveHeaderStyle = lipgloss.NewStyle().
|
2022-03-30 11:52:26 +00:00
|
|
|
Foreground(lipgloss.Color("#000000")).
|
|
|
|
Background(lipgloss.Color("#d1d1d1"))
|
2022-03-27 00:01:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Frame is a frame that appears in the
|
2022-03-27 21:58:41 +00:00
|
|
|
type FrameTitle struct {
|
2022-06-22 01:57:12 +00:00
|
|
|
header string
|
|
|
|
active bool
|
|
|
|
style Style
|
|
|
|
width int
|
2022-03-27 00:01:24 +00:00
|
|
|
}
|
|
|
|
|
2022-06-22 01:57:12 +00:00
|
|
|
type Style struct {
|
|
|
|
ActiveTitle lipgloss.Style
|
|
|
|
InactiveTitle lipgloss.Style
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFrameTitle(header string, active bool, style Style) FrameTitle {
|
|
|
|
return FrameTitle{header, active, style, 0}
|
2022-03-27 00:01:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 21:58:41 +00:00
|
|
|
func (f *FrameTitle) SetTitle(title string) {
|
|
|
|
f.header = title
|
2022-03-27 00:01:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 21:58:41 +00:00
|
|
|
func (f FrameTitle) View() string {
|
|
|
|
return f.headerView()
|
2022-03-27 00:01:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 21:58:41 +00:00
|
|
|
func (f *FrameTitle) Resize(w, h int) {
|
|
|
|
f.width = w
|
2022-03-27 00:01:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 21:58:41 +00:00
|
|
|
func (f FrameTitle) HeaderHeight() int {
|
|
|
|
return lipgloss.Height(f.headerView())
|
2022-03-27 00:01:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 21:58:41 +00:00
|
|
|
func (f FrameTitle) headerView() string {
|
2022-06-22 01:57:12 +00:00
|
|
|
style := f.style.InactiveTitle
|
2022-03-27 00:40:32 +00:00
|
|
|
if f.active {
|
2022-06-22 01:57:12 +00:00
|
|
|
style = f.style.ActiveTitle
|
2022-03-27 00:40:32 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 00:01:24 +00:00
|
|
|
titleText := f.header
|
2022-03-27 00:40:32 +00:00
|
|
|
title := style.Render(titleText)
|
|
|
|
line := style.Render(strings.Repeat(" ", utils.Max(0, f.width-lipgloss.Width(title))))
|
2022-03-27 00:01:24 +00:00
|
|
|
return lipgloss.JoinHorizontal(lipgloss.Left, title, line)
|
|
|
|
}
|