Add WithSpringOptions to customize spring in NewModel

This commit is contained in:
Christian Rocha 2021-07-26 12:13:59 -04:00
parent 90d8eaffeb
commit e723cfd15e

View File

@ -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. // FrameMsg indicates that an animation step should occur.
type FrameMsg struct { type FrameMsg struct {
id int id int
@ -131,6 +138,7 @@ type Model struct {
// Members for animated transitons. // Members for animated transitons.
spring harmonica.Spring spring harmonica.Spring
springCustomized bool
percent float64 percent float64
targetPercent float64 targetPercent float64
velocity float64 velocity float64
@ -158,7 +166,9 @@ func NewModel(opts ...Option) Model {
ShowPercentage: true, ShowPercentage: true,
PercentFormat: " %3.0f%%", PercentFormat: " %3.0f%%",
} }
if !m.springCustomized {
m.SetSpringOptions(defaultFrequency, defaultDamping) m.SetSpringOptions(defaultFrequency, defaultDamping)
}
for _, opt := range opts { for _, opt := range opts {
opt(&m) opt(&m)