diff options
author | Benjamin Chausse <benjamin@chausse.xyz> | 2024-11-23 18:12:03 -0500 |
---|---|---|
committer | Benjamin Chausse <benjamin@chausse.xyz> | 2024-11-23 18:12:03 -0500 |
commit | 89094fecf4cb1c018f15c976641cd18c255eac28 (patch) | |
tree | 9f6e32c38013bc526399ab324891e0b3269e50dc /internal/slider/evaluation.go |
Semi-working POC
Diffstat (limited to 'internal/slider/evaluation.go')
-rw-r--r-- | internal/slider/evaluation.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/internal/slider/evaluation.go b/internal/slider/evaluation.go new file mode 100644 index 0000000..363efe7 --- /dev/null +++ b/internal/slider/evaluation.go @@ -0,0 +1,46 @@ +package slider + +func (m Model) Val() int { return m.current } + +func (m *Model) Set(v int) { + m.current = v + m.fixRange() +} + +func (m *Model) Inc(v int) { + m.current += v + m.fixRange() +} + +func (m *Model) Dec(v int) { + m.current -= v + m.fixRange() +} + +func (m *Model) Pcnt() float64 { + return float64(m.current) / float64(m.max) +} + +func (m *Model) SetPcnt(p float64) { + m.current = int(float64(m.max) * p) + m.fixRange() +} + +func (m *Model) IncPcnt(p float64) { + m.current += int(float64(m.max) * p) + m.fixRange() +} + +func (m *Model) DecPcnt(p float64) { + m.current -= int(float64(m.max) * p) + m.fixRange() +} + +func (m *Model) fixRange() { + if m.current > m.max { + m.current = m.max + } + if m.current < 0 { + m.current = 0 + } +} |