Skip to content

Commit

Permalink
feat: tabs carousel (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
prgres committed Jun 4, 2024
1 parent 3747c39 commit e12b304
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
54 changes: 37 additions & 17 deletions ui/components/views-tabs/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,19 @@ func (m Model) View() string {
Width(m.size.Width - borderMargin).
MaxWidth(m.size.Width + borderMargin)

moreTabsIcon := " + "
prefix := " Views |"
moreTabsIcon := "+"
tabSeperatorIcon := "|"
suffix := ""
prefix := " Views "
if len(m.tabs) == 0 {
prefix += tabSeperatorIcon + " "
}

availableWidth := m.size.Width - borderMargin

if m.Path != "" {
suffixMaxWidth := int(float32(m.size.Width-borderMargin) * 0.4)
pathMaxWidth := suffixMaxWidth - lipgloss.Width(" "+"|"+" "+""+" ")
suffixMaxWidth := int(float32(availableWidth) * 0.4)
pathMaxWidth := suffixMaxWidth - lipgloss.Width(" "+tabSeperatorIcon+" "+""+" ")
path := m.Path

if lipgloss.Width(m.Path) > pathMaxWidth {
Expand All @@ -132,32 +138,46 @@ func (m Model) View() string {
path = strings.Join(pathParts, "/")
}

suffix = " " + "|" + " " + path + " "
suffix = " " + tabSeperatorIcon + " " + path + " "
}

availableWidth -= lipgloss.Width(prefix + suffix)

selectedIdx := 0
for i := range m.tabs {
if m.Selected == m.tabs[i].Id {
selectedIdx = i
break
}
}

var s []string
for _, tab := range m.tabs {
t := ""
tabContent := " " + tab.Name + " "

for i, tab := range m.tabs {
style := inactiveTabStyle
if m.Hovered() == tab.Id {
if i == selectedIdx {
style = activeTabStyle
}
t = style.Render(tabContent)
content := style.Render(" " + tab.Name + " ")

content := " " + t + " "
if lipgloss.Width(strings.Join(append(s, tabSeperatorIcon+" "+content), " ")) >= availableWidth {
if i <= selectedIdx {
s = append(s, tabSeperatorIcon+" "+content)
s = s[1:]
continue
}

if lipgloss.Width(prefix+strings.Join(s, "")+content+moreTabsIcon+suffix) >= m.size.Width-borderMargin {
s = append(s, moreTabsIcon)
s = append(s, tabSeperatorIcon+" "+moreTabsIcon)
break
}
s = append(s, content)
s = append(s, "|")

s = append(s, tabSeperatorIcon+" "+content)

}
content := strings.Join(s, "")

dividerWidth := m.size.Width - borderMargin - lipgloss.Width(prefix+content+moreTabsIcon+suffix)
content := strings.Join(s, " ")

dividerWidth := availableWidth - lipgloss.Width(content)
if dividerWidth < 0 {
dividerWidth = 0
}
Expand Down
1 change: 0 additions & 1 deletion ui/views/compact/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func (m *Model) handleKeys(msg tea.KeyMsg) tea.Cmd {
}
}

// m.getActiveElement().
switch m.state {
case m.widgetNavigator.Id():
cmd = m.widgetNavigator.Update(msg)
Expand Down

0 comments on commit e12b304

Please sign in to comment.