mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
parent
07c1031887
commit
dcfacd9510
@ -11,6 +11,8 @@ const checkWidth = 4
|
|||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
widget.View.Clear()
|
widget.View.Clear()
|
||||||
|
|
||||||
|
maxLen := widget.longestLineLen(widget.list.Items)
|
||||||
|
|
||||||
str := ""
|
str := ""
|
||||||
for idx, item := range widget.list.Items {
|
for idx, item := range widget.list.Items {
|
||||||
foreColor, backColor := "white", "black"
|
foreColor, backColor := "white", "black"
|
||||||
@ -32,8 +34,21 @@ func (widget *Widget) display() {
|
|||||||
item.Text,
|
item.Text,
|
||||||
)
|
)
|
||||||
|
|
||||||
str = str + wtf.PadRow((4+len(item.Text)), widget.View) + "\n"
|
str = str + wtf.PadRow((4+len(item.Text)), (4+maxLen)) + "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(widget.View, "%s", str)
|
fmt.Fprintf(widget.View, "%s", str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// longestLineLen returns the length of the longest todo item line
|
||||||
|
func (widget *Widget) longestLineLen(items []*Item) int {
|
||||||
|
maxLen := 0
|
||||||
|
|
||||||
|
for _, item := range items {
|
||||||
|
if len(item.Text) > maxLen {
|
||||||
|
maxLen = len(item.Text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxLen
|
||||||
|
}
|
||||||
|
@ -83,10 +83,8 @@ func OpenFile(path string) {
|
|||||||
// PadRow returns a padding for a row to make it the full width of the containing widget.
|
// PadRow returns a padding for a row to make it the full width of the containing widget.
|
||||||
// Useful for ensurig row highlighting spans the full width (I suspect tcell has a better
|
// Useful for ensurig row highlighting spans the full width (I suspect tcell has a better
|
||||||
// way to do this, but I haven't yet found it)
|
// way to do this, but I haven't yet found it)
|
||||||
func PadRow(offset int, view *tview.TextView) string {
|
func PadRow(offset int, max int) string {
|
||||||
_, _, w, _ := view.GetInnerRect()
|
padSize := max - offset
|
||||||
|
|
||||||
padSize := w - offset
|
|
||||||
if padSize < 0 {
|
if padSize < 0 {
|
||||||
padSize = 0
|
padSize = 0
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user