mirror of
https://github.com/Maks1mS/bubbles.git
synced 2025-01-11 14:38:10 +03:00
Clamp scroll percentage
This commit is contained in:
parent
5255143e87
commit
0c1781fbb3
@ -1,6 +1,7 @@
|
||||
package viewport
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
@ -32,6 +33,7 @@ type Model struct {
|
||||
lines []string
|
||||
}
|
||||
|
||||
// TODO: do we really need this?
|
||||
func NewModel(width, height int) Model {
|
||||
return Model{
|
||||
Width: width,
|
||||
@ -63,7 +65,8 @@ func (m Model) ScrollPercent() float64 {
|
||||
y := float64(m.YOffset)
|
||||
h := float64(m.Height)
|
||||
t := float64(len(m.lines))
|
||||
return y / (t - h)
|
||||
v := y / (t - h)
|
||||
return math.Max(0.0, math.Min(1.0, v))
|
||||
}
|
||||
|
||||
// SetContent set the pager's text content. For high performance rendering the
|
||||
|
Loading…
Reference in New Issue
Block a user