|
|
|
@ -1,18 +1,22 @@
|
|
|
|
|
package cointop
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) currentPage() int {
|
|
|
|
|
ct.debuglog("currentPage()")
|
|
|
|
|
return ct.State.page + 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) currentDisplayPage() int {
|
|
|
|
|
ct.debuglog("currentDisplayPage()")
|
|
|
|
|
return ct.State.page + 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) totalPages() int {
|
|
|
|
|
ct.debuglog("totalPages()")
|
|
|
|
|
return ct.getListCount() / ct.State.perPage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) totalPagesDisplay() int {
|
|
|
|
|
ct.debuglog("totalPagesDisplay()")
|
|
|
|
|
return ct.totalPages() + 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -21,6 +25,7 @@ func (ct *Cointop) totalPerPage() int {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) setPage(page int) int {
|
|
|
|
|
ct.debuglog("setPage()")
|
|
|
|
|
if (page*ct.State.perPage) < ct.getListCount() && page >= 0 {
|
|
|
|
|
ct.State.page = page
|
|
|
|
|
}
|
|
|
|
@ -28,15 +33,18 @@ func (ct *Cointop) setPage(page int) int {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) cursorDown() error {
|
|
|
|
|
ct.debuglog("cursorDown()")
|
|
|
|
|
if ct.Views.Table.Backing() == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
_, y := ct.Views.Table.Backing().Origin()
|
|
|
|
|
cx, cy := ct.Views.Table.Backing().Cursor()
|
|
|
|
|
numRows := len(ct.State.coins) - 1
|
|
|
|
|
if (cy + y + 1) > numRows {
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the bottom
|
|
|
|
|
if ct.isLastRow() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cx, cy := ct.Views.Table.Backing().Cursor()
|
|
|
|
|
|
|
|
|
|
if err := ct.Views.Table.Backing().SetCursor(cx, cy+1); err != nil {
|
|
|
|
|
ox, oy := ct.Views.Table.Backing().Origin()
|
|
|
|
|
// set origin scrolls
|
|
|
|
@ -49,11 +57,19 @@ func (ct *Cointop) cursorDown() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) cursorUp() error {
|
|
|
|
|
ct.debuglog("cursorUp()")
|
|
|
|
|
if ct.Views.Table.Backing() == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the top
|
|
|
|
|
if ct.isFirstRow() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ox, oy := ct.Views.Table.Backing().Origin()
|
|
|
|
|
cx, cy := ct.Views.Table.Backing().Cursor()
|
|
|
|
|
|
|
|
|
|
if err := ct.Views.Table.Backing().SetCursor(cx, cy-1); err != nil && oy > 0 {
|
|
|
|
|
// set origin scrolls
|
|
|
|
|
if err := ct.Views.Table.Backing().SetOrigin(ox, oy-1); err != nil {
|
|
|
|
@ -65,9 +81,16 @@ func (ct *Cointop) cursorUp() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) pageDown() error {
|
|
|
|
|
ct.debuglog("pageDown()")
|
|
|
|
|
if ct.Views.Table.Backing() == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the bottom
|
|
|
|
|
if ct.isLastRow() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ox, oy := ct.Views.Table.Backing().Origin() // this is prev origin position
|
|
|
|
|
cx, _ := ct.Views.Table.Backing().Cursor() // relative cursor position
|
|
|
|
|
_, sy := ct.Views.Table.Backing().Size() // rows in visible view
|
|
|
|
@ -97,9 +120,16 @@ func (ct *Cointop) pageDown() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) pageUp() error {
|
|
|
|
|
ct.debuglog("pageUp()")
|
|
|
|
|
if ct.Views.Table.Backing() == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the top
|
|
|
|
|
if ct.isFirstRow() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ox, oy := ct.Views.Table.Backing().Origin()
|
|
|
|
|
cx, _ := ct.Views.Table.Backing().Cursor() // relative cursor position
|
|
|
|
|
_, sy := ct.Views.Table.Backing().Size() // rows in visible view
|
|
|
|
@ -121,9 +151,16 @@ func (ct *Cointop) pageUp() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) navigateFirstLine() error {
|
|
|
|
|
ct.debuglog("navigateFirstLine()")
|
|
|
|
|
if ct.Views.Table.Backing() == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the top
|
|
|
|
|
if ct.isFirstRow() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ox, _ := ct.Views.Table.Backing().Origin()
|
|
|
|
|
cx, _ := ct.Views.Table.Backing().Cursor()
|
|
|
|
|
if err := ct.Views.Table.Backing().SetOrigin(ox, 0); err != nil {
|
|
|
|
@ -137,9 +174,16 @@ func (ct *Cointop) navigateFirstLine() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) navigateLastLine() error {
|
|
|
|
|
ct.debuglog("navigateLastLine()")
|
|
|
|
|
if ct.Views.Table.Backing() == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the bottom
|
|
|
|
|
if ct.isLastRow() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ox, _ := ct.Views.Table.Backing().Origin()
|
|
|
|
|
cx, _ := ct.Views.Table.Backing().Cursor()
|
|
|
|
|
_, sy := ct.Views.Table.Backing().Size()
|
|
|
|
@ -156,9 +200,16 @@ func (ct *Cointop) navigateLastLine() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) navigatePageFirstLine() error {
|
|
|
|
|
ct.debuglog("navigatePageFirstLine()")
|
|
|
|
|
if ct.Views.Table.Backing() == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the correct line
|
|
|
|
|
if ct.isPageFirstLine() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cx, _ := ct.Views.Table.Backing().Cursor()
|
|
|
|
|
if err := ct.Views.Table.Backing().SetCursor(cx, 0); err != nil {
|
|
|
|
|
return err
|
|
|
|
@ -168,9 +219,16 @@ func (ct *Cointop) navigatePageFirstLine() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) navigatePageMiddleLine() error {
|
|
|
|
|
ct.debuglog("navigatePageMiddleLine()")
|
|
|
|
|
if ct.Views.Table.Backing() == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the correct line
|
|
|
|
|
if ct.isPageMiddleLine() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cx, _ := ct.Views.Table.Backing().Cursor()
|
|
|
|
|
_, sy := ct.Views.Table.Backing().Size()
|
|
|
|
|
if err := ct.Views.Table.Backing().SetCursor(cx, (sy/2)-1); err != nil {
|
|
|
|
@ -181,9 +239,16 @@ func (ct *Cointop) navigatePageMiddleLine() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) navigatePageLastLine() error {
|
|
|
|
|
ct.debuglog("navigatePageLastLine()")
|
|
|
|
|
if ct.Views.Table.Backing() == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the correct line
|
|
|
|
|
if ct.isPageLastLine() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cx, _ := ct.Views.Table.Backing().Cursor()
|
|
|
|
|
_, sy := ct.Views.Table.Backing().Size()
|
|
|
|
|
if err := ct.Views.Table.Backing().SetCursor(cx, sy-1); err != nil {
|
|
|
|
@ -194,9 +259,13 @@ func (ct *Cointop) navigatePageLastLine() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) prevPage() error {
|
|
|
|
|
ct.debuglog("prevPage()")
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the first page
|
|
|
|
|
if ct.isFirstPage() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ct.setPage(ct.State.page - 1)
|
|
|
|
|
ct.updateTable()
|
|
|
|
|
ct.rowChanged()
|
|
|
|
@ -204,6 +273,13 @@ func (ct *Cointop) prevPage() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) nextPage() error {
|
|
|
|
|
ct.debuglog("nextPage()")
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the last page
|
|
|
|
|
if ct.isLastPage() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ct.setPage(ct.State.page + 1)
|
|
|
|
|
ct.updateTable()
|
|
|
|
|
ct.rowChanged()
|
|
|
|
@ -211,17 +287,79 @@ func (ct *Cointop) nextPage() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) firstPage() error {
|
|
|
|
|
ct.debuglog("firstPage()")
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the first page
|
|
|
|
|
if ct.isFirstPage() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ct.State.page = 0
|
|
|
|
|
ct.updateTable()
|
|
|
|
|
ct.rowChanged()
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) isFirstRow() bool {
|
|
|
|
|
ct.debuglog("isFirstRow()")
|
|
|
|
|
|
|
|
|
|
_, y := ct.Views.Table.Backing().Origin()
|
|
|
|
|
_, cy := ct.Views.Table.Backing().Cursor()
|
|
|
|
|
|
|
|
|
|
return (cy + y) == 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) isLastRow() bool {
|
|
|
|
|
ct.debuglog("isLastRow()")
|
|
|
|
|
|
|
|
|
|
_, y := ct.Views.Table.Backing().Origin()
|
|
|
|
|
_, cy := ct.Views.Table.Backing().Cursor()
|
|
|
|
|
numRows := len(ct.State.coins) - 1
|
|
|
|
|
|
|
|
|
|
return (cy + y + 1) > numRows
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) isFirstPage() bool {
|
|
|
|
|
ct.debuglog("isFirstPage()")
|
|
|
|
|
return ct.State.page == 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) isLastPage() bool {
|
|
|
|
|
ct.debuglog("isLastPage()")
|
|
|
|
|
return ct.State.page == ct.totalPages()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) isPageFirstLine() bool {
|
|
|
|
|
ct.debuglog("isPageFirstLine()")
|
|
|
|
|
|
|
|
|
|
_, cy := ct.Views.Table.Backing().Cursor()
|
|
|
|
|
return cy == 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) isPageMiddleLine() bool {
|
|
|
|
|
ct.debuglog("isPageMiddleLine()")
|
|
|
|
|
|
|
|
|
|
_, cy := ct.Views.Table.Backing().Cursor()
|
|
|
|
|
_, sy := ct.Views.Table.Backing().Size()
|
|
|
|
|
return (sy/2)-1 == cy
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) isPageLastLine() bool {
|
|
|
|
|
ct.debuglog("isPageLastLine()")
|
|
|
|
|
|
|
|
|
|
_, cy := ct.Views.Table.Backing().Cursor()
|
|
|
|
|
_, sy := ct.Views.Table.Backing().Size()
|
|
|
|
|
return cy+1 == sy
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) lastPage() error {
|
|
|
|
|
ct.debuglog("lastPage()")
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the last page
|
|
|
|
|
if ct.isLastPage() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ct.State.page = ct.getListCount() / ct.State.perPage
|
|
|
|
|
ct.updateTable()
|
|
|
|
|
ct.rowChanged()
|
|
|
|
@ -229,6 +367,7 @@ func (ct *Cointop) lastPage() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) goToPageRowIndex(idx int) error {
|
|
|
|
|
ct.debuglog("goToPageRowIndex()")
|
|
|
|
|
if ct.Views.Table.Backing() == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
@ -241,6 +380,7 @@ func (ct *Cointop) goToPageRowIndex(idx int) error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) goToGlobalIndex(idx int) error {
|
|
|
|
|
ct.debuglog("goToGlobalIndex()")
|
|
|
|
|
perpage := ct.totalPerPage()
|
|
|
|
|
atpage := idx / perpage
|
|
|
|
|
ct.setPage(atpage)
|
|
|
|
@ -251,6 +391,7 @@ func (ct *Cointop) goToGlobalIndex(idx int) error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ct *Cointop) highlightRow(idx int) error {
|
|
|
|
|
ct.debuglog("highlightRow()")
|
|
|
|
|
ct.Views.Table.Backing().SetOrigin(0, 0)
|
|
|
|
|
ct.Views.Table.Backing().SetCursor(0, 0)
|
|
|
|
|
ox, _ := ct.Views.Table.Backing().Origin()
|
|
|
|
|