mirror of
https://github.com/gizak/termui.git
synced 2025-04-24 13:48:50 +08:00
fix tabs (tabpane) overflow on TabName length > max width
change VERTICAL_LINE to VERTICAL_DASH because of unexpected pixel
This commit is contained in:
parent
2b8f0c7960
commit
c4be16a0ef
@ -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
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user