Fix tabstrip over-drawing when not enough space

Tabstrip didn't take into account the width of the context. Now, it just
shows as many tabs as can fit and truncates the last one if necessary.

In future it probably would be best to ensure that the selected tab is
rendered on the screen.
This commit is contained in:
Jeffas 2019-07-26 09:46:15 +01:00 committed by Drew DeVault
parent cded067bc3
commit 7a3765a36b

View file

@ -167,8 +167,15 @@ func (strip *TabStrip) Draw(ctx *Context) {
if strip.Selected == i { if strip.Selected == i {
style = tcell.StyleDefault style = tcell.StyleDefault
} }
trunc := runewidth.Truncate(tab.Name, 32, "…") tabWidth := 32
if ctx.Width()-x < tabWidth {
tabWidth = ctx.Width() - x - 2
}
trunc := runewidth.Truncate(tab.Name, tabWidth, "…")
x += ctx.Printf(x, 0, style, " %s ", trunc) x += ctx.Printf(x, 0, style, " %s ", trunc)
if x >= ctx.Width() {
break
}
} }
style := tcell.StyleDefault.Reverse(true) style := tcell.StyleDefault.Reverse(true)
ctx.Fill(x, 0, ctx.Width()-x, 1, ' ', style) ctx.Fill(x, 0, ctx.Width()-x, 1, ' ', style)