mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-05 04:36:07 +00:00
Problem: can't determine if the progress bar stopped updating
This would be useful to know to stop displaying it after the user was shown the progress bar to render to its end. Solution: expose `IsComplete` method is based on what's been drawn
This commit is contained in:
committed by
Christian Rocha
parent
afd7868712
commit
fe31dc0a97
@@ -211,8 +211,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
// If we've more or less reached equilibrium, stop updating.
|
||||
dist := math.Abs(m.percentShown - m.targetPercent)
|
||||
if dist < 0.001 && m.velocity < 0.01 {
|
||||
if !m.IsAnimating() {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@@ -362,6 +361,12 @@ func max(a, b int) int {
|
||||
return b
|
||||
}
|
||||
|
||||
// IsAnimating returns false if the progress bar reached equilibrium and is no longer animating.
|
||||
func (m *Model) IsAnimating() bool {
|
||||
dist := math.Abs(m.percentShown - m.targetPercent)
|
||||
return !(dist < 0.001 && m.velocity < 0.01)
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
|
||||
Reference in New Issue
Block a user