MCPcopy
hub / github.com/mathaou/termdbms / updatePagination

Method updatePagination

list/list.go:641–674  ·  view source on GitHub ↗

Update pagination according to the amount of items for the current state.

()

Source from the content-addressed store, hash-verified

639
640// Update pagination according to the amount of items for the current state.
641func (m *Model) updatePagination() {
642 index := m.Index()
643 availHeight := m.height
644
645 if m.showTitle || (m.showFilter && m.filteringEnabled) {
646 availHeight -= lipgloss.Height(m.titleView())
647 }
648 if m.showStatusBar {
649 availHeight -= lipgloss.Height(m.statusView())
650 }
651 if m.showPagination {
652 availHeight -= lipgloss.Height(m.paginationView())
653 }
654 if m.showHelp {
655 availHeight -= lipgloss.Height(m.helpView())
656 }
657
658 m.Paginator.PerPage = max(1, availHeight/(m.delegate.Height()+m.delegate.Spacing()))
659
660 if pages := len(m.VisibleItems()); pages < 1 {
661 m.Paginator.SetTotalPages(1)
662 } else {
663 m.Paginator.SetTotalPages(pages)
664 }
665
666 // Restore index
667 m.Paginator.Page = index / m.Paginator.PerPage
668 m.cursor = index % m.Paginator.PerPage
669
670 // Make sure the page stays in bounds
671 if m.Paginator.Page >= m.Paginator.TotalPages-1 {
672 m.Paginator.Page = max(0, m.Paginator.TotalPages-1)
673 }
674}
675
676func (m *Model) hideStatusMessage() {
677 m.statusMessage = ""

Callers 15

NewModelFunction · 0.95
SetShowTitleMethod · 0.95
SetShowFilterMethod · 0.95
SetShowStatusBarMethod · 0.95
SetShowPaginationMethod · 0.95
SetShowHelpMethod · 0.95
SetItemsMethod · 0.95
SetItemMethod · 0.95
InsertItemMethod · 0.95
RemoveItemMethod · 0.95
SetDelegateMethod · 0.95
setSizeMethod · 0.95

Calls 9

IndexMethod · 0.95
titleViewMethod · 0.95
statusViewMethod · 0.95
paginationViewMethod · 0.95
helpViewMethod · 0.95
VisibleItemsMethod · 0.95
maxFunction · 0.70
HeightMethod · 0.65
SpacingMethod · 0.65

Tested by

no test coverage detected