From e723cfd15ee95f921c5ffd64d1f09d713ea467f4 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Mon, 26 Jul 2021 12:13:59 -0400 Subject: [PATCH] Add WithSpringOptions to customize spring in NewModel --- progress/progress.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/progress/progress.go b/progress/progress.go index 66f2a8b..421e146 100644 --- a/progress/progress.go +++ b/progress/progress.go @@ -98,6 +98,13 @@ func WithWidth(w int) Option { } } +func WithSpringOptions(frequency, damping float64) Option { + return func(m *Model) { + m.SetSpringOptions(frequency, damping) + m.springCustomized = true + } +} + // FrameMsg indicates that an animation step should occur. type FrameMsg struct { id int @@ -130,10 +137,11 @@ type Model struct { PercentageStyle lipgloss.Style // Members for animated transitons. - spring harmonica.Spring - percent float64 - targetPercent float64 - velocity float64 + spring harmonica.Spring + springCustomized bool + percent float64 + targetPercent float64 + velocity float64 // Gradient settings useRamp bool @@ -158,7 +166,9 @@ func NewModel(opts ...Option) Model { ShowPercentage: true, PercentFormat: " %3.0f%%", } - m.SetSpringOptions(defaultFrequency, defaultDamping) + if !m.springCustomized { + m.SetSpringOptions(defaultFrequency, defaultDamping) + } for _, opt := range opts { opt(&m)