-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow the scrollbar to hide if the data fits in the space available.
This is a new option provided to the scrollbar widget. If enabled, the scrollbar will simply render its data widget if the data available would fit in the space provided to the scrollbar. Note that this adjusts the focus path of certain elements in the UI... This is fragile. I really need a better way e.g. labelling widgets within containers like columns or piles, rather than using a numeric index.
- Loading branch information
Showing
3 changed files
with
148 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package withscrollbar | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/gcla/gowid" | ||
"github.com/gcla/gowid/gwtest" | ||
"github.com/gcla/gowid/widgets/button" | ||
"github.com/gcla/gowid/widgets/list" | ||
"github.com/gcla/gowid/widgets/text" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type scrollingListBox struct { | ||
*list.Widget | ||
} | ||
|
||
func (t *scrollingListBox) Up(lines int, size gowid.IRenderSize, app gowid.IApp) {} | ||
func (t *scrollingListBox) Down(lines int, size gowid.IRenderSize, app gowid.IApp) {} | ||
func (t *scrollingListBox) UpPage(num int, size gowid.IRenderSize, app gowid.IApp) {} | ||
func (t *scrollingListBox) DownPage(num int, size gowid.IRenderSize, app gowid.IApp) {} | ||
|
||
func (t *scrollingListBox) ScrollLength() int { | ||
return 8 | ||
} | ||
|
||
func (t *scrollingListBox) ScrollPosition() int { | ||
return 0 | ||
} | ||
|
||
func Test1(t *testing.T) { | ||
bws := make([]gowid.IWidget, 8) | ||
for i := 0; i < len(bws); i++ { | ||
bws[i] = button.NewBare(text.New(fmt.Sprintf("%03d", i))) | ||
} | ||
|
||
walker := list.NewSimpleListWalker(bws) | ||
lbox := &scrollingListBox{Widget: list.New(walker)} | ||
sbox := New(lbox) | ||
|
||
canvas1 := sbox.Render(gowid.MakeRenderBox(4, 8), gowid.NotSelected, gwtest.D) | ||
res := strings.Join([]string{ | ||
"000▲", | ||
"001█", | ||
"002 ", | ||
"003 ", | ||
"004 ", | ||
"005 ", | ||
"006 ", | ||
"007▼", | ||
}, "\n") | ||
assert.Equal(t, res, canvas1.String()) | ||
|
||
sbox = New(lbox, Options{ | ||
HideIfContentFits: true, | ||
}) | ||
|
||
canvas1 = sbox.Render(gowid.MakeRenderBox(4, 8), gowid.NotSelected, gwtest.D) | ||
res = strings.Join([]string{ | ||
"000 ", | ||
"001 ", | ||
"002 ", | ||
"003 ", | ||
"004 ", | ||
"005 ", | ||
"006 ", | ||
"007 ", | ||
}, "\n") | ||
assert.Equal(t, res, canvas1.String()) | ||
|
||
canvas1 = sbox.Render(gowid.MakeRenderBox(4, 5), gowid.NotSelected, gwtest.D) | ||
res = strings.Join([]string{ | ||
"000▲", | ||
"001█", | ||
"002 ", | ||
"003 ", | ||
"004▼", | ||
}, "\n") | ||
assert.Equal(t, res, canvas1.String()) | ||
} |