Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab width top border #1068

Open
manus-ko opened this issue Jul 29, 2024 · 2 comments
Open

Tab width top border #1068

manus-ko opened this issue Jul 29, 2024 · 2 comments

Comments

@manus-ko
Copy link

Following the tabs example, If a fixed width is used with less tabs

doc.WriteString(windowStyle.Width(100).Render(m.TabContent[m.activeTab]))

image

The top border is missing. How to fix this?

@semihbkgr
Copy link

Hi @cksc123

You can fix it by adding some vertical lines to the row variable, which is created by row := lipgloss.JoinHorizontal(lipgloss.Top, renderedTabs...).

Here’s a fix for your case, where WIDTH is the desired value.

func (m model) View() string {
	doc := strings.Builder{}

	var renderedTabs []string

	for i, t := range m.Tabs {
		var style lipgloss.Style
		isFirst, isLast, isActive := i == 0, i == len(m.Tabs)-1, i == m.activeTab
		if isActive {
			style = activeTabStyle
		} else {
			style = inactiveTabStyle
		}
		border, _, _, _, _ := style.GetBorder()
		if isFirst && isActive {
			border.BottomLeft = "│"
		} else if isFirst && !isActive {
			border.BottomLeft = "├"
		} else if isLast && isActive {
			border.BottomRight = "└"
		} else if isLast && !isActive {
			border.BottomRight = "┴"
		}
		style = style.Border(border)
		renderedTabs = append(renderedTabs, style.Render(t))
	}

	extend := WIDTH - lipgloss.Width(lipgloss.JoinHorizontal(lipgloss.Top, renderedTabs...))
	if extend > 0 {
		complementaryRow := lipgloss.NewStyle().Foreground(highlightColor).Render("\n\n" + strings.Repeat("─", extend-1) + "┐")
		renderedTabs = append(renderedTabs, complementaryRow)
	}
	row := lipgloss.JoinHorizontal(lipgloss.Top, renderedTabs...)
	doc.WriteString(row)
	doc.WriteString("\n")
	doc.WriteString(windowStyle.Width((lipgloss.Width(row) - windowStyle.GetHorizontalFrameSize())).Render(m.TabContent[m.activeTab]))
	return docStyle.Render(doc.String())
}

@dawkrish
Copy link

Shouldn't this issue be closed ?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants