1
0
mirror of https://github.com/gizak/termui.git synced 2025-04-24 13:48:50 +08:00

Merge c4be16a0ef8e70163172b4fa1c0a4d031569c08f into 2b8f0c7960e9553acea6d579a740713066da5e13

This commit is contained in:
keet 2024-08-25 23:12:03 -04:00 committed by GitHub
commit 36afac1e92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 3 deletions

View File

@ -37,7 +37,7 @@ func main() {
bc.SetRect(5, 5, 35, 10)
bc.Labels = []string{"S0", "S1", "S2", "S3", "S4", "S5"}
tabpane := widgets.NewTabPane("pierwszy", "drugi", "trzeci", "żółw", "four", "five")
tabpane := widgets.NewTabPane("pierwszy", "drugi", "trzeci", "żółw", "four", "five", "glozzom", "equilstirax", "refellibal", "inkinda", "sitiallure", "mattomer")
tabpane.SetRect(0, 1, 50, 4)
tabpane.Border = true

View File

@ -33,12 +33,16 @@ func NewTabPane(names ...string) *TabPane {
func (self *TabPane) FocusLeft() {
if self.ActiveTabIndex > 0 {
self.ActiveTabIndex--
} else if self.ActiveTabIndex == 0 && len(self.TabNames) > 1 {
self.ActiveTabIndex = 0
}
}
func (self *TabPane) FocusRight() {
if self.ActiveTabIndex < len(self.TabNames)-1 {
self.ActiveTabIndex++
} else if self.ActiveTabIndex >= len(self.TabNames)-1 {
self.ActiveTabIndex = len(self.TabNames) - 1
}
}
@ -46,7 +50,20 @@ func (self *TabPane) Draw(buf *Buffer) {
self.Block.Draw(buf)
xCoordinate := self.Inner.Min.X
for i, name := range self.TabNames {
startIndex := 0
totalLength := 0
for i := self.ActiveTabIndex; i >= 0; i-- {
name := self.TabNames[i]
totalLength += len(name) + 3
if totalLength > self.Inner.Max.X-self.Inner.Min.X {
startIndex = i + 1
break
}
}
for i := startIndex; i < len(self.TabNames); i++ {
name := self.TabNames[i]
ColorPair := self.InactiveTabStyle
if i == self.ActiveTabIndex {
ColorPair = self.ActiveTabStyle
@ -61,11 +78,15 @@ func (self *TabPane) Draw(buf *Buffer) {
if i < len(self.TabNames)-1 && xCoordinate < self.Inner.Max.X {
buf.SetCell(
NewCell(VERTICAL_LINE, NewStyle(ColorWhite)),
NewCell(VERTICAL_DASH, NewStyle(ColorWhite)),
image.Pt(xCoordinate, self.Inner.Min.Y),
)
}
xCoordinate += 2
if xCoordinate > self.Inner.Max.X {
break
}
}
}