forked from tslocum/cview
Display TextView scroll bar automatically by default
parent
0e9e75f3f8
commit
28e366bbce
|
@ -12,6 +12,7 @@ v1.5.1 (WIP)
|
|||
- Allow modification of scroll bar render text
|
||||
- Allow scrolling List horizontally
|
||||
- Clarify that Table rows must each have the same number of columns
|
||||
- Display TextView scroll bar automatically by default
|
||||
- Generalize tag stripping as StripTags
|
||||
- Make printWithStyle public and rename as PrintStyle
|
||||
- Optimize TextView (writing is 90% faster, drawing is 50% faster)
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
const logo = `
|
||||
======= === === === ======== === === ===
|
||||
=== === === === === === === ===
|
||||
=== === === === ====== === === ===
|
||||
=== === === === ====== === === ===
|
||||
=== ====== === === ===========
|
||||
======= == === ======== ==== ====
|
||||
`
|
||||
|
|
|
@ -33,7 +33,6 @@ const textView1 = `[green]func[white] [yellow]main[white]() {
|
|||
func TextView1(nextSlide func()) (title string, content cview.Primitive) {
|
||||
textView := cview.NewTextView()
|
||||
textView.SetTextColor(tcell.ColorYellow.TrueColor())
|
||||
textView.SetScrollable(false)
|
||||
textView.SetDoneFunc(func(key tcell.Key) {
|
||||
nextSlide()
|
||||
})
|
||||
|
@ -52,7 +51,7 @@ func TextView1(nextSlide func()) (title string, content cview.Primitive) {
|
|||
}
|
||||
|
||||
fmt.Fprintf(textView, "%d ", n)
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
time.Sleep(75 * time.Millisecond)
|
||||
}
|
||||
}()
|
||||
textView.SetBorder(true)
|
||||
|
@ -153,6 +152,7 @@ func TextView2(nextSlide func()) (title string, content cview.Primitive) {
|
|||
fmt.Fprint(textView, textView2)
|
||||
textView.SetBorder(true)
|
||||
textView.SetTitle("TextView output")
|
||||
textView.SetScrollBarVisibility(cview.ScrollBarAuto)
|
||||
|
||||
flex := cview.NewFlex()
|
||||
flex.AddItem(textView, 0, 1, true)
|
||||
|
|
|
@ -161,5 +161,5 @@ func TreeView(nextSlide func()) (title string, content cview.Primitive) {
|
|||
flex.AddItem(tree, 0, 1, true)
|
||||
flex.AddItem(treeCode, codeWidth, 1, false)
|
||||
|
||||
return "Tree", flex
|
||||
return "TreeView", flex
|
||||
}
|
||||
|
|
3
doc.go
3
doc.go
|
@ -180,8 +180,7 @@ Scroll Bars
|
|||
|
||||
Scroll bars are supported by the following widgets: List, Table, TextView and
|
||||
TreeView. Each widget will display scroll bars automatically when there are
|
||||
additional items offscreen, except TextView. See Widget.SetScrollBarColor and
|
||||
Widget.SetScrollBarVisibility.
|
||||
additional items offscreen. See SetScrollBarColor and SetScrollBarVisibility.
|
||||
|
||||
Hello World
|
||||
|
||||
|
|
38
textview.go
38
textview.go
|
@ -206,15 +206,16 @@ type TextView struct {
|
|||
// NewTextView returns a new text view.
|
||||
func NewTextView() *TextView {
|
||||
return &TextView{
|
||||
Box: NewBox(),
|
||||
highlights: make(map[string]struct{}),
|
||||
lineOffset: -1,
|
||||
reindex: true,
|
||||
scrollable: true,
|
||||
align: AlignLeft,
|
||||
wrap: true,
|
||||
textColor: Styles.PrimaryTextColor,
|
||||
scrollBarColor: Styles.ScrollBarColor,
|
||||
Box: NewBox(),
|
||||
highlights: make(map[string]struct{}),
|
||||
lineOffset: -1,
|
||||
reindex: true,
|
||||
scrollable: true,
|
||||
scrollBarVisibility: ScrollBarAuto,
|
||||
scrollBarColor: Styles.ScrollBarColor,
|
||||
align: AlignLeft,
|
||||
wrap: true,
|
||||
textColor: Styles.PrimaryTextColor,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -964,10 +965,13 @@ func (t *TextView) Draw(screen tcell.Screen) {
|
|||
|
||||
// Get the available size.
|
||||
x, y, width, height := t.GetInnerRect()
|
||||
if height == 0 {
|
||||
return
|
||||
}
|
||||
t.pageSize = height
|
||||
|
||||
t.reindexBuffer(width)
|
||||
showVerticalScrollBar := t.scrollBarVisibility == ScrollBarAlways || (t.scrollBarVisibility == ScrollBarAuto && len(t.index) >= height)
|
||||
showVerticalScrollBar := t.scrollBarVisibility == ScrollBarAlways || (t.scrollBarVisibility == ScrollBarAuto && len(t.index) > height)
|
||||
if showVerticalScrollBar {
|
||||
width-- // Subtract space for scroll bar.
|
||||
if t.wrap {
|
||||
|
@ -1285,12 +1289,16 @@ func (t *TextView) MouseHandler() func(action MouseAction, event *tcell.EventMou
|
|||
consumed = true
|
||||
setFocus(t)
|
||||
case MouseScrollUp:
|
||||
t.trackEnd = false
|
||||
t.lineOffset--
|
||||
consumed = true
|
||||
if t.scrollable {
|
||||
t.trackEnd = false
|
||||
t.lineOffset--
|
||||
consumed = true
|
||||
}
|
||||
case MouseScrollDown:
|
||||
t.lineOffset++
|
||||
consumed = true
|
||||
if t.scrollable {
|
||||
t.lineOffset++
|
||||
consumed = true
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue