Browse Source

Make printWithStyle public and rename as PrintStyle

tablepad
Trevor Slocum 2 years ago
parent
commit
c3391c3c3b
  1. 1
      CHANGELOG
  2. 4
      table.go
  3. 2
      treeview.go
  4. 16
      util.go

1
CHANGELOG

@ -8,6 +8,7 @@ v1.5.1 (WIP) @@ -8,6 +8,7 @@ v1.5.1 (WIP)
- Fix List dividers allowing selection
- Allow modification of scroll bar render text
- Allow scrolling List horizontally
- Make printWithStyle public and rename as PrintStyle
- Optimize TextView (writing is 90% faster, drawing is 50% faster)
- Remove return values from methods which return their primitive (breaks chaining)
- Remove Application.ForceDraw (Application.Draw may be called anywhere)

4
table.go

@ -1070,10 +1070,10 @@ ColumnLoop: @@ -1070,10 +1070,10 @@ ColumnLoop:
finalWidth = width - columnX - 1
}
cell.x, cell.y, cell.width = x+columnX+1, y+rowY, finalWidth
_, printed := printWithStyle(screen, cell.Text, x+columnX+1, y+rowY, finalWidth, cell.Align, SetAttributes(tcell.StyleDefault.Foreground(cell.Color), cell.Attributes))
_, printed := PrintStyle(screen, cell.Text, x+columnX+1, y+rowY, finalWidth, cell.Align, SetAttributes(tcell.StyleDefault.Foreground(cell.Color), cell.Attributes))
if TaggedTextWidth(cell.Text)-printed > 0 && printed > 0 {
_, _, style, _ := screen.GetContent(x+columnX+finalWidth, y+rowY)
printWithStyle(screen, []byte(string(SemigraphicsHorizontalEllipsis)), x+columnX+finalWidth, y+rowY, 1, AlignLeft, style)
PrintStyle(screen, []byte(string(SemigraphicsHorizontalEllipsis)), x+columnX+finalWidth, y+rowY, 1, AlignLeft, style)
}
}

2
treeview.go

@ -852,7 +852,7 @@ func (t *TreeView) Draw(screen tcell.Screen) { @@ -852,7 +852,7 @@ func (t *TreeView) Draw(screen tcell.Screen) {
}
style = tcell.StyleDefault.Background(backgroundColor).Foreground(foregroundColor)
}
printWithStyle(screen, []byte(node.text), x+node.textX+prefixWidth, posY, width-node.textX-prefixWidth, AlignLeft, style)
PrintStyle(screen, []byte(node.text), x+node.textX+prefixWidth, posY, width-node.textX-prefixWidth, AlignLeft, style)
}
}

16
util.go

@ -277,12 +277,12 @@ func decomposeText(text []byte, findColors, findRegions bool) (colorIndices [][] @@ -277,12 +277,12 @@ func decomposeText(text []byte, findColors, findRegions bool) (colorIndices [][]
// Returns the number of actual bytes of the text printed (including color tags)
// and the actual width used for the printed runes.
func Print(screen tcell.Screen, text []byte, x, y, maxWidth, align int, color tcell.Color) (int, int) {
return printWithStyle(screen, text, x, y, maxWidth, align, tcell.StyleDefault.Foreground(color))
return PrintStyle(screen, text, x, y, maxWidth, align, tcell.StyleDefault.Foreground(color))
}
// printWithStyle works like Print() but it takes a style instead of just a
// PrintStyle works like Print() but it takes a style instead of just a
// foreground color.
func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int, style tcell.Style) (int, int) {
func PrintStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int, style tcell.Style) (int, int) {
if maxWidth <= 0 || len(text) == 0 {
return 0, 0
}
@ -294,7 +294,7 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int, @@ -294,7 +294,7 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int,
if align == AlignRight {
if strippedWidth <= maxWidth {
// There's enough space for the entire text.
return printWithStyle(screen, text, x+maxWidth-strippedWidth, y, maxWidth, AlignLeft, style)
return PrintStyle(screen, text, x+maxWidth-strippedWidth, y, maxWidth, AlignLeft, style)
}
// Trim characters off the beginning.
var (
@ -322,7 +322,7 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int, @@ -322,7 +322,7 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int,
text = append(text[:escapeCharPos], text[escapeCharPos+1:]...)
}
// Print and return.
bytes, width = printWithStyle(screen, text[textPos+tagOffset:], x, y, maxWidth, AlignLeft, style)
bytes, width = PrintStyle(screen, text[textPos+tagOffset:], x, y, maxWidth, AlignLeft, style)
return true
}
return false
@ -331,11 +331,11 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int, @@ -331,11 +331,11 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int,
} else if align == AlignCenter {
if strippedWidth == maxWidth {
// Use the exact space.
return printWithStyle(screen, text, x, y, maxWidth, AlignLeft, style)
return PrintStyle(screen, text, x, y, maxWidth, AlignLeft, style)
} else if strippedWidth < maxWidth {
// We have more space than we need.
half := (maxWidth - strippedWidth) / 2
return printWithStyle(screen, text, x+half, y, maxWidth-half, AlignLeft, style)
return PrintStyle(screen, text, x+half, y, maxWidth-half, AlignLeft, style)
} else {
// Chop off runes until we have a perfect fit.
var choppedLeft, choppedRight, leftIndex, rightIndex int
@ -390,7 +390,7 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int, @@ -390,7 +390,7 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int,
escapePos++
}
}
return printWithStyle(screen, text[leftIndex+tagOffset:], x, y, maxWidth, AlignLeft, style)
return PrintStyle(screen, text[leftIndex+tagOffset:], x, y, maxWidth, AlignLeft, style)
}
}

Loading…
Cancel
Save