|
|
@ -1,6 +1,7 @@
|
|
|
|
package cointop
|
|
|
|
package cointop
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
"math"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -45,7 +46,7 @@ func (ct *Cointop) SetPage(page int) int {
|
|
|
|
// CursorDown moves the cursor one row down
|
|
|
|
// CursorDown moves the cursor one row down
|
|
|
|
func (ct *Cointop) CursorDown() error {
|
|
|
|
func (ct *Cointop) CursorDown() error {
|
|
|
|
ct.debuglog("cursorDown()")
|
|
|
|
ct.debuglog("cursorDown()")
|
|
|
|
// NOTE: return if already at the bottom
|
|
|
|
// return if already at the bottom
|
|
|
|
if ct.IsLastRow() {
|
|
|
|
if ct.IsLastRow() {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -65,7 +66,7 @@ func (ct *Cointop) CursorDown() error {
|
|
|
|
// CursorUp moves the cursor one row up
|
|
|
|
// CursorUp moves the cursor one row up
|
|
|
|
func (ct *Cointop) CursorUp() error {
|
|
|
|
func (ct *Cointop) CursorUp() error {
|
|
|
|
ct.debuglog("cursorUp()")
|
|
|
|
ct.debuglog("cursorUp()")
|
|
|
|
// NOTE: return if already at the top
|
|
|
|
// return if already at the top
|
|
|
|
if ct.IsFirstRow() {
|
|
|
|
if ct.IsFirstRow() {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -86,7 +87,7 @@ func (ct *Cointop) CursorUp() error {
|
|
|
|
// PageDown moves the cursor one page down
|
|
|
|
// PageDown moves the cursor one page down
|
|
|
|
func (ct *Cointop) PageDown() error {
|
|
|
|
func (ct *Cointop) PageDown() error {
|
|
|
|
ct.debuglog("pageDown()")
|
|
|
|
ct.debuglog("pageDown()")
|
|
|
|
// NOTE: return if already at the bottom
|
|
|
|
// return if already at the bottom
|
|
|
|
if ct.IsLastRow() {
|
|
|
|
if ct.IsLastRow() {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -94,24 +95,24 @@ func (ct *Cointop) PageDown() error {
|
|
|
|
ox, oy := ct.Views.Table.Origin() // this is prev origin position
|
|
|
|
ox, oy := ct.Views.Table.Origin() // this is prev origin position
|
|
|
|
cx := ct.Views.Table.CursorX() // relative cursor position
|
|
|
|
cx := ct.Views.Table.CursorX() // relative cursor position
|
|
|
|
sy := ct.Views.Table.Height() // rows in visible view
|
|
|
|
sy := ct.Views.Table.Height() // rows in visible view
|
|
|
|
k := oy + sy
|
|
|
|
y := oy + sy
|
|
|
|
l := ct.TableRowsLen()
|
|
|
|
l := ct.TableRowsLen()
|
|
|
|
// end of table
|
|
|
|
// end of table
|
|
|
|
if (oy + sy + sy) > l {
|
|
|
|
if (oy + sy + sy) > l {
|
|
|
|
k = l - sy
|
|
|
|
y = l - sy
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// select last row if next jump is out of bounds
|
|
|
|
// select last row if next jump is out of bounds
|
|
|
|
if k < 0 {
|
|
|
|
if y < 0 {
|
|
|
|
k = 0
|
|
|
|
y = 0
|
|
|
|
sy = l
|
|
|
|
sy = l
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := ct.Views.Table.SetOrigin(ox, k); err != nil {
|
|
|
|
if err := ct.Views.Table.SetOrigin(ox, y); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// move cursor to last line if can't scroll further
|
|
|
|
// move cursor to last line if can't scroll further
|
|
|
|
if k == oy {
|
|
|
|
if y == oy {
|
|
|
|
if err := ct.Views.Table.SetCursor(cx, sy-1); err != nil {
|
|
|
|
if err := ct.Views.Table.SetCursor(cx, sy-1); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -123,7 +124,7 @@ func (ct *Cointop) PageDown() error {
|
|
|
|
// PageUp moves the cursor one page up
|
|
|
|
// PageUp moves the cursor one page up
|
|
|
|
func (ct *Cointop) PageUp() error {
|
|
|
|
func (ct *Cointop) PageUp() error {
|
|
|
|
ct.debuglog("pageUp()")
|
|
|
|
ct.debuglog("pageUp()")
|
|
|
|
// NOTE: return if already at the top
|
|
|
|
// return if already at the top
|
|
|
|
if ct.IsFirstRow() {
|
|
|
|
if ct.IsFirstRow() {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -151,7 +152,7 @@ func (ct *Cointop) PageUp() error {
|
|
|
|
// NavigateFirstLine moves the cursor to the first row of the table
|
|
|
|
// NavigateFirstLine moves the cursor to the first row of the table
|
|
|
|
func (ct *Cointop) NavigateFirstLine() error {
|
|
|
|
func (ct *Cointop) NavigateFirstLine() error {
|
|
|
|
ct.debuglog("navigateFirstLine()")
|
|
|
|
ct.debuglog("navigateFirstLine()")
|
|
|
|
// NOTE: return if already at the top
|
|
|
|
// return if already at the top
|
|
|
|
if ct.IsFirstRow() {
|
|
|
|
if ct.IsFirstRow() {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -172,7 +173,7 @@ func (ct *Cointop) NavigateFirstLine() error {
|
|
|
|
// NavigateLastLine moves the cursor to the last row of the table
|
|
|
|
// NavigateLastLine moves the cursor to the last row of the table
|
|
|
|
func (ct *Cointop) NavigateLastLine() error {
|
|
|
|
func (ct *Cointop) NavigateLastLine() error {
|
|
|
|
ct.debuglog("navigateLastLine()")
|
|
|
|
ct.debuglog("navigateLastLine()")
|
|
|
|
// NOTE: return if already at the bottom
|
|
|
|
// return if already at the bottom
|
|
|
|
if ct.IsLastRow() {
|
|
|
|
if ct.IsLastRow() {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -196,7 +197,7 @@ func (ct *Cointop) NavigateLastLine() error {
|
|
|
|
// NavigatePageFirstLine moves the cursor to the visible first row of the table
|
|
|
|
// NavigatePageFirstLine moves the cursor to the visible first row of the table
|
|
|
|
func (ct *Cointop) NavigatePageFirstLine() error {
|
|
|
|
func (ct *Cointop) NavigatePageFirstLine() error {
|
|
|
|
ct.debuglog("navigatePageFirstLine()")
|
|
|
|
ct.debuglog("navigatePageFirstLine()")
|
|
|
|
// NOTE: return if already at the correct line
|
|
|
|
// return if already at the correct line
|
|
|
|
if ct.IsPageFirstLine() {
|
|
|
|
if ct.IsPageFirstLine() {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -212,7 +213,7 @@ func (ct *Cointop) NavigatePageFirstLine() error {
|
|
|
|
// NavigatePageMiddleLine moves the cursor to the visible middle row of the table
|
|
|
|
// NavigatePageMiddleLine moves the cursor to the visible middle row of the table
|
|
|
|
func (ct *Cointop) NavigatePageMiddleLine() error {
|
|
|
|
func (ct *Cointop) NavigatePageMiddleLine() error {
|
|
|
|
ct.debuglog("navigatePageMiddleLine()")
|
|
|
|
ct.debuglog("navigatePageMiddleLine()")
|
|
|
|
// NOTE: return if already at the correct line
|
|
|
|
// return if already at the correct line
|
|
|
|
if ct.IsPageMiddleLine() {
|
|
|
|
if ct.IsPageMiddleLine() {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -229,7 +230,7 @@ func (ct *Cointop) NavigatePageMiddleLine() error {
|
|
|
|
// NavigatePageLastLine moves the cursor to the visible last row of the table
|
|
|
|
// NavigatePageLastLine moves the cursor to the visible last row of the table
|
|
|
|
func (ct *Cointop) navigatePageLastLine() error {
|
|
|
|
func (ct *Cointop) navigatePageLastLine() error {
|
|
|
|
ct.debuglog("navigatePageLastLine()")
|
|
|
|
ct.debuglog("navigatePageLastLine()")
|
|
|
|
// NOTE: return if already at the correct line
|
|
|
|
// return if already at the correct line
|
|
|
|
if ct.IsPageLastLine() {
|
|
|
|
if ct.IsPageLastLine() {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -247,7 +248,7 @@ func (ct *Cointop) navigatePageLastLine() error {
|
|
|
|
func (ct *Cointop) NextPage() error {
|
|
|
|
func (ct *Cointop) NextPage() error {
|
|
|
|
ct.debuglog("nextPage()")
|
|
|
|
ct.debuglog("nextPage()")
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the last page
|
|
|
|
// return if already at the last page
|
|
|
|
if ct.IsLastPage() {
|
|
|
|
if ct.IsLastPage() {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -262,7 +263,7 @@ func (ct *Cointop) NextPage() error {
|
|
|
|
func (ct *Cointop) PrevPage() error {
|
|
|
|
func (ct *Cointop) PrevPage() error {
|
|
|
|
ct.debuglog("prevPage()")
|
|
|
|
ct.debuglog("prevPage()")
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the first page
|
|
|
|
// return if already at the first page
|
|
|
|
if ct.IsFirstPage() {
|
|
|
|
if ct.IsFirstPage() {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -297,7 +298,7 @@ func (ct *Cointop) PrevPageTop() error {
|
|
|
|
func (ct *Cointop) FirstPage() error {
|
|
|
|
func (ct *Cointop) FirstPage() error {
|
|
|
|
ct.debuglog("firstPage()")
|
|
|
|
ct.debuglog("firstPage()")
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the first page
|
|
|
|
// return if already at the first page
|
|
|
|
if ct.IsFirstPage() {
|
|
|
|
if ct.IsFirstPage() {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -312,7 +313,7 @@ func (ct *Cointop) FirstPage() error {
|
|
|
|
func (ct *Cointop) LastPage() error {
|
|
|
|
func (ct *Cointop) LastPage() error {
|
|
|
|
ct.debuglog("lastPage()")
|
|
|
|
ct.debuglog("lastPage()")
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: return if already at the last page
|
|
|
|
// return if already at the last page
|
|
|
|
if ct.IsLastPage() {
|
|
|
|
if ct.IsLastPage() {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -402,26 +403,57 @@ func (ct *Cointop) GoToGlobalIndex(idx int) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// HighlightRow highlights the row at index
|
|
|
|
// HighlightRow highlights the row at index within page
|
|
|
|
func (ct *Cointop) HighlightRow(idx int) error {
|
|
|
|
func (ct *Cointop) HighlightRow(pageRowIndex int) error {
|
|
|
|
ct.debuglog("highlightRow()")
|
|
|
|
ct.debuglog("highlightRow()")
|
|
|
|
ct.Views.Table.SetOrigin(0, 0)
|
|
|
|
ct.Views.Table.SetOrigin(0, 0)
|
|
|
|
ct.Views.Table.SetCursor(0, 0)
|
|
|
|
ct.Views.Table.SetCursor(0, 0)
|
|
|
|
ox := ct.Views.Table.OriginX()
|
|
|
|
ox := ct.Views.Table.OriginX()
|
|
|
|
cx := ct.Views.Table.CursorX()
|
|
|
|
cx := ct.Views.Table.CursorX()
|
|
|
|
sy := ct.Views.Table.Height()
|
|
|
|
h := ct.Views.Table.Height()
|
|
|
|
perpage := ct.TotalPerPage()
|
|
|
|
perpage := ct.TotalPerPage()
|
|
|
|
p := idx % perpage
|
|
|
|
oy := 0
|
|
|
|
oy := (p / sy) * sy
|
|
|
|
cy := 0
|
|
|
|
cy := p % sy
|
|
|
|
if h > 0 {
|
|
|
|
|
|
|
|
_ = perpage
|
|
|
|
|
|
|
|
cy = pageRowIndex % h
|
|
|
|
|
|
|
|
oy = pageRowIndex - cy
|
|
|
|
|
|
|
|
// end of page
|
|
|
|
|
|
|
|
if pageRowIndex >= perpage-h {
|
|
|
|
|
|
|
|
oy = perpage - h
|
|
|
|
|
|
|
|
cy = h - (perpage - pageRowIndex)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ct.debuglog(fmt.Sprintf("highlightRow idx:%v h:%v cy:%v oy:%v", pageRowIndex, h, cy, oy))
|
|
|
|
if oy > 0 {
|
|
|
|
if oy > 0 {
|
|
|
|
ct.Views.Table.SetOrigin(ox, oy)
|
|
|
|
ct.Views.Table.SetOrigin(ox, oy)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ct.Views.Table.SetCursor(cx, cy)
|
|
|
|
ct.Views.Table.SetCursor(cx, cy)
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GoToCoinRow navigates to the row of the matched coin
|
|
|
|
|
|
|
|
func (ct *Cointop) GoToCoinRow(coin *Coin) error {
|
|
|
|
|
|
|
|
ct.debuglog("goToCoinRow()")
|
|
|
|
|
|
|
|
if coin == nil {
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
idx := ct.GetGlobalCoinIndex(coin)
|
|
|
|
|
|
|
|
return ct.GoToGlobalIndex(idx)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetGlobalCoinIndex returns the index of the coin in from the coins list
|
|
|
|
|
|
|
|
func (ct *Cointop) GetGlobalCoinIndex(coin *Coin) int {
|
|
|
|
|
|
|
|
var idx int
|
|
|
|
|
|
|
|
for i, v := range ct.State.allCoins {
|
|
|
|
|
|
|
|
if v == coin {
|
|
|
|
|
|
|
|
idx = i
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return idx
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// CursorDownOrNextPage moves the cursor down one row or goes to the next page if cursor is on the last row
|
|
|
|
// CursorDownOrNextPage moves the cursor down one row or goes to the next page if cursor is on the last row
|
|
|
|
func (ct *Cointop) CursorDownOrNextPage() error {
|
|
|
|
func (ct *Cointop) CursorDownOrNextPage() error {
|
|
|
|
ct.debuglog("CursorDownOrNextPage()")
|
|
|
|
ct.debuglog("CursorDownOrNextPage()")
|
|
|
|