chore: rework layout primitives

This commit is contained in:
adamdottv 2025-06-28 06:04:01 -05:00
parent d090c08ef0
commit 9f3ba03965
No known key found for this signature in database
GPG key ID: 9CB48779AF150E75
7 changed files with 298 additions and 589 deletions

View file

@ -1,11 +1,7 @@
package layout
import (
"reflect"
"github.com/charmbracelet/bubbles/v2/key"
tea "github.com/charmbracelet/bubbletea/v2"
"github.com/charmbracelet/lipgloss/v2"
)
var Current *LayoutInfo
@ -34,33 +30,3 @@ type Modal interface {
Render(background string) string
Close() tea.Cmd
}
type Focusable interface {
Focus() tea.Cmd
Blur() tea.Cmd
IsFocused() bool
}
type Sizeable interface {
SetSize(width, height int) tea.Cmd
GetSize() (int, int)
}
type Alignable interface {
MaxWidth() int
Alignment() lipgloss.Position
SetPosition(x, y int)
GetPosition() (x, y int)
}
func KeyMapToSlice(t any) (bindings []key.Binding) {
typ := reflect.TypeOf(t)
if typ.Kind() != reflect.Struct {
return nil
}
for i := range typ.NumField() {
v := reflect.ValueOf(t).Field(i)
bindings = append(bindings, v.Interface().(key.Binding))
}
return
}