hatmill/attribute/step.go

33 lines
656 B
Go
Raw Normal View History

2019-04-23 14:15:17 +00:00
package attribute
import "strconv"
import "gitlab.codemonkeysoftware.net/b/hatmill"
2019-08-31 19:07:18 +00:00
type StepValue float32
2019-04-23 14:15:17 +00:00
2019-08-31 19:07:18 +00:00
func (v *StepValue) String() string {
if v == nil {
return "any"
}
return strconv.FormatFloat(float64(*v), 'G', -1, 32)
}
func StepAny() *StepValue {
2019-04-23 14:15:17 +00:00
return nil
}
2019-08-31 19:07:18 +00:00
func StepFloat(value float32) *StepValue {
return (*StepValue)(&(value))
2019-04-23 14:15:17 +00:00
}
// Step indicates the minimum allowed change to a number input.
2019-08-31 19:07:18 +00:00
func Step(value *StepValue) hatmill.Attrib {
2019-04-23 14:15:17 +00:00
var attr = hatmill.Attrib{Key: "step"}
if value == nil {
attr.Value = String("any")
2019-04-23 14:15:17 +00:00
} else {
attr.Value = String(strconv.FormatFloat(float64(*value), 'G', -1, 32))
2019-04-23 14:15:17 +00:00
}
return attr
}