gizak / termui

Golang terminal dashboard
MIT License
13.11k stars 786 forks source link

add feature to support SetActiveByIndex to switch tab #165

Closed stephencheng closed 5 years ago

stephencheng commented 6 years ago

Unfortunately due to the fields are not exported, I couldn't do it in my App to make this work

Is it possible to add below to extra/tabpane.go, please

func (tp *Tabpane) SetActiveIndex(x int) {

tp.activeTabIndex = x
if tp.posTabText[tp.activeTabIndex] < tp.offTabText {
    tp.offTabText = tp.posTabText[tp.activeTabIndex]
}
endOffset := tp.posTabText[tp.activeTabIndex] + tp.Tabs[tp.activeTabIndex].RuneLen
if endOffset+tp.offTabText > tp.InnerWidth() {
    tp.offTabText = endOffset - tp.InnerWidth()
}

}

cjbassi commented 5 years ago

Hi, this was just added to master in 958a28575d7411492d25e42da3ad5a6e5947d9a4. You can change the tab index by setting the ActiveTabIndex field. Do note that termui has been heavily reworked in that commit, so there's a lot of breaking changes.