Skip to content

Commit 8171411

Browse files
engalarako
authored andcommitted
fix(tui): improve selection visual hierarchy with custom delegate
1 parent 7773101 commit 8171411

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

tui/panels/elements.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type ElementsPanel struct {
1616
}
1717

1818
func NewElementsPanel(width, height int) ElementsPanel {
19-
delegate := list.NewDefaultDelegate()
19+
delegate := newCustomDelegate(false)
2020
delegate.ShowDescription = true
2121
l := list.New(nil, delegate, width, height)
2222
l.Title = "Elements"
@@ -59,7 +59,10 @@ func (p *ElementsPanel) SetSize(w, h int) {
5959
p.list.SetHeight(h)
6060
}
6161

62-
func (p *ElementsPanel) SetFocused(f bool) { p.focused = f }
62+
func (p *ElementsPanel) SetFocused(f bool) {
63+
p.focused = f
64+
p.list.SetDelegate(newCustomDelegate(f))
65+
}
6366

6467
func (p ElementsPanel) Update(msg tea.Msg) (ElementsPanel, tea.Cmd) {
6568
var cmd tea.Cmd

tui/panels/modules.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ type ModulesPanel struct {
3333
}
3434

3535
func NewModulesPanel(width, height int) ModulesPanel {
36-
delegate := list.NewDefaultDelegate()
36+
delegate := newCustomDelegate(false)
3737
delegate.ShowDescription = false
3838
l := list.New(nil, delegate, width, height)
3939
l.SetShowTitle(true)
40-
l.Title = "Modules"
40+
l.Title = "Project"
4141
l.SetShowStatusBar(false)
4242
l.SetFilteringEnabled(true)
4343
return ModulesPanel{list: l, width: width, height: height}
@@ -82,7 +82,10 @@ func (p *ModulesPanel) SetSize(w, h int) {
8282
p.list.SetHeight(h)
8383
}
8484

85-
func (p *ModulesPanel) SetFocused(f bool) { p.focused = f }
85+
func (p *ModulesPanel) SetFocused(f bool) {
86+
p.focused = f
87+
p.list.SetDelegate(newCustomDelegate(f))
88+
}
8689

8790
func (p ModulesPanel) Update(msg tea.Msg) (ModulesPanel, tea.Cmd) {
8891
var cmd tea.Cmd
@@ -97,6 +100,29 @@ func (p ModulesPanel) View() string {
97100
return border.Render(p.list.View())
98101
}
99102

103+
func newCustomDelegate(focused bool) list.DefaultDelegate {
104+
d := list.NewDefaultDelegate()
105+
if focused {
106+
d.Styles.SelectedTitle = lipgloss.NewStyle().
107+
Border(lipgloss.NormalBorder(), false, false, false, true).
108+
BorderForeground(lipgloss.Color("63")).
109+
Foreground(lipgloss.Color("255")).
110+
Bold(true).
111+
Padding(0, 0, 0, 1)
112+
d.Styles.SelectedDesc = d.Styles.SelectedTitle.
113+
Foreground(lipgloss.Color("63"))
114+
} else {
115+
d.Styles.SelectedTitle = lipgloss.NewStyle().
116+
Border(lipgloss.NormalBorder(), false, false, false, true).
117+
BorderForeground(lipgloss.Color("240")).
118+
Foreground(lipgloss.Color("245")).
119+
Padding(0, 0, 0, 1)
120+
d.Styles.SelectedDesc = d.Styles.SelectedTitle.
121+
Foreground(lipgloss.Color("240"))
122+
}
123+
return d
124+
}
125+
100126
func borderColor(focused bool) lipgloss.Color {
101127
if focused {
102128
return lipgloss.Color("63")

0 commit comments

Comments
 (0)