mirror of
https://github.com/Xevion/glance.git
synced 2025-12-10 16:07:22 -06:00
Change HSL values to floats
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var hslColorFieldPattern = regexp.MustCompile(`^(?:hsla?\()?(\d{1,3})(?: |,)+(\d{1,3})%?(?: |,)+(\d{1,3})%?\)?$`)
|
var hslColorFieldPattern = regexp.MustCompile(`^(?:hsla?\()?([\d\.]+)(?: |,)+([\d\.]+)%?(?: |,)+([\d\.]+)%?\)?$`)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
hslHueMax = 360
|
hslHueMax = 360
|
||||||
@@ -23,13 +23,13 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type hslColorField struct {
|
type hslColorField struct {
|
||||||
Hue uint16
|
Hue float64
|
||||||
Saturation uint8
|
Saturation float64
|
||||||
Lightness uint8
|
Lightness float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *hslColorField) String() string {
|
func (c *hslColorField) String() string {
|
||||||
return fmt.Sprintf("hsl(%d, %d%%, %d%%)", c.Hue, c.Saturation, c.Lightness)
|
return fmt.Sprintf("hsl(%.1f, %.1f%%, %.1f%%)", c.Hue, c.Saturation, c.Lightness)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *hslColorField) UnmarshalYAML(node *yaml.Node) error {
|
func (c *hslColorField) UnmarshalYAML(node *yaml.Node) error {
|
||||||
@@ -45,7 +45,7 @@ func (c *hslColorField) UnmarshalYAML(node *yaml.Node) error {
|
|||||||
return fmt.Errorf("invalid HSL color format: %s", value)
|
return fmt.Errorf("invalid HSL color format: %s", value)
|
||||||
}
|
}
|
||||||
|
|
||||||
hue, err := strconv.ParseUint(matches[1], 10, 16)
|
hue, err := strconv.ParseFloat(matches[1], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ func (c *hslColorField) UnmarshalYAML(node *yaml.Node) error {
|
|||||||
return fmt.Errorf("HSL hue must be between 0 and %d", hslHueMax)
|
return fmt.Errorf("HSL hue must be between 0 and %d", hslHueMax)
|
||||||
}
|
}
|
||||||
|
|
||||||
saturation, err := strconv.ParseUint(matches[2], 10, 8)
|
saturation, err := strconv.ParseFloat(matches[2], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ func (c *hslColorField) UnmarshalYAML(node *yaml.Node) error {
|
|||||||
return fmt.Errorf("HSL saturation must be between 0 and %d", hslSaturationMax)
|
return fmt.Errorf("HSL saturation must be between 0 and %d", hslSaturationMax)
|
||||||
}
|
}
|
||||||
|
|
||||||
lightness, err := strconv.ParseUint(matches[3], 10, 8)
|
lightness, err := strconv.ParseFloat(matches[3], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -72,9 +72,9 @@ func (c *hslColorField) UnmarshalYAML(node *yaml.Node) error {
|
|||||||
return fmt.Errorf("HSL lightness must be between 0 and %d", hslLightnessMax)
|
return fmt.Errorf("HSL lightness must be between 0 and %d", hslLightnessMax)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Hue = uint16(hue)
|
c.Hue = hue
|
||||||
c.Saturation = uint8(saturation)
|
c.Saturation = saturation
|
||||||
c.Lightness = uint8(lightness)
|
c.Lightness = lightness
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user