ref: ca48e9e5646b85bad81bfa9706a7cc221996f9f4
parent: 62eb07e1cb10966e0d7e7a001e615ad26c616160
author: Philip Silva <[email protected]>
date: Wed Jan 20 18:19:40 EST 2021
css length handling vh, vw
--- a/style/stylesheets.go
+++ b/style/stylesheets.go
@@ -32,6 +32,8 @@
var rMaxWidth = regexp.MustCompile(`max-width: (\d+)px`)
const FontBaseSize = 11.0
+var WindowWidth = 1280
+var WindowHeight = 1080
const AddOnCSS = `
a, span, i, tt, b {
@@ -530,13 +532,15 @@
func length(l string) (f float64, unit string, err error) {
var s string
- if l == "auto" {
+ if l == "auto" || l == "inherit" {
return 0, "px", nil
}
- for _, suffix := range []string{"px", "%", "rem", "em"} {
+ for _, suffix := range []string{"px", "%", "rem", "em", "vw", "vh"} {
if strings.HasSuffix(l, suffix) {
- s = strings.TrimSuffix(l, suffix)
+ if s = strings.TrimSuffix(l, suffix); s != "" {
+ f, err = strconv.ParseFloat(s, 64)
+ }
unit = suffix
break
}
@@ -543,14 +547,17 @@
}
switch unit {
- case "":
- return f, unit, fmt.Errorf("unknown suffix: %v", l)
- case "px", "em":
- f, err = strconv.ParseFloat(s, 64)
- }
-
- if unit == "em" {
+ case "px":
+ case "em":
f *= FontBaseSize
+ case "vw":
+ f *= float64(WindowWidth) / 100.0
+ case "vh":
+ f *= float64(WindowHeight) / 100.0
+ case "%", "rem":
+ f = 0
+ default:
+ return f, unit, fmt.Errorf("unknown suffix: %v", l)
}
f = float64(dui.Scale(int(f)))