2019-04-23 14:15:17 +00:00
|
|
|
package attribute
|
|
|
|
|
2023-12-20 22:35:09 +00:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"git.codemonkeysoftware.net/b/hatmill"
|
|
|
|
)
|
2019-04-23 14:15:17 +00:00
|
|
|
|
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 {
|
2019-08-31 15:05:43 +00:00
|
|
|
attr.Value = String("any")
|
2019-04-23 14:15:17 +00:00
|
|
|
} else {
|
2019-08-31 15:05:43 +00:00
|
|
|
attr.Value = String(strconv.FormatFloat(float64(*value), 'G', -1, 32))
|
2019-04-23 14:15:17 +00:00
|
|
|
}
|
|
|
|
return attr
|
|
|
|
}
|