hatmill/attribute/step.go

36 lines
653 B
Go

package attribute
import (
"strconv"
"git.codemonkeysoftware.net/b/hatmill"
)
type StepValue float32
func (v *StepValue) String() string {
if v == nil {
return "any"
}
return strconv.FormatFloat(float64(*v), 'G', -1, 32)
}
func StepAny() *StepValue {
return nil
}
func StepFloat(value float32) *StepValue {
return (*StepValue)(&(value))
}
// Step indicates the minimum allowed change to a number input.
func Step(value *StepValue) hatmill.Attrib {
var attr = hatmill.Attrib{Key: "step"}
if value == nil {
attr.Value = String("any")
} else {
attr.Value = String(strconv.FormatFloat(float64(*value), 'G', -1, 32))
}
return attr
}