panel: add end margin option

parent 269c5d7a
...@@ -75,6 +75,14 @@ Module spacing: ...@@ -75,6 +75,14 @@ Module spacing:
} }
``` ```
End margins for floating and island panels:
```json
{
"end_margin": 8
}
```
## Module Resolution ## Module Resolution
The config stores logical module names. At generation time, the panel merges The config stores logical module names. At generation time, the panel merges
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
"type": "panel", "type": "panel",
"output": [], "output": [],
"spacing": 10, "spacing": 10,
"end_margin": 8,
"modules_left": [ "modules_left": [
"image#menu", "image#menu",
"tray" "tray"
......
...@@ -22,6 +22,7 @@ type Config struct { ...@@ -22,6 +22,7 @@ type Config struct {
Type string `json:"type"` Type string `json:"type"`
Output []string `json:"output"` Output []string `json:"output"`
Spacing int `json:"spacing"` Spacing int `json:"spacing"`
EndMargin int `json:"end_margin"`
ModulesLeft []string `json:"modules_left"` ModulesLeft []string `json:"modules_left"`
ModulesCenter []string `json:"modules_center"` ModulesCenter []string `json:"modules_center"`
ModulesRight []string `json:"modules_right"` ModulesRight []string `json:"modules_right"`
...@@ -88,6 +89,10 @@ func (c Config) Validate() error { ...@@ -88,6 +89,10 @@ func (c Config) Validate() error {
return errors.New("spacing cannot be negative") return errors.New("spacing cannot be negative")
} }
if c.EndMargin < 0 {
return errors.New("end margin cannot be negative")
}
for _, name := range append(append([]string{}, c.ModulesLeft...), append(c.ModulesCenter, c.ModulesRight...)...) { for _, name := range append(append([]string{}, c.ModulesLeft...), append(c.ModulesCenter, c.ModulesRight...)...) {
if strings.TrimSpace(name) == "" { if strings.TrimSpace(name) == "" {
return errors.New("module name cannot be empty") return errors.New("module name cannot be empty")
......
...@@ -35,7 +35,7 @@ func GenerateConfig(cfg Config, registry Registry) ([]byte, error) { ...@@ -35,7 +35,7 @@ func GenerateConfig(cfg Config, registry Registry) ([]byte, error) {
} }
if cfg.Type == "floating" || cfg.Type == "islands" { if cfg.Type == "floating" || cfg.Type == "islands" {
applyFloatingMargins(out, cfg.Position) applyFloatingMargins(out, cfg.Position, cfg.EndMargin)
} }
left, err := resolveModuleList(cfg.ModulesLeft, cfg.Position, registry) left, err := resolveModuleList(cfg.ModulesLeft, cfg.Position, registry)
...@@ -62,24 +62,26 @@ func GenerateConfig(cfg Config, registry Registry) ([]byte, error) { ...@@ -62,24 +62,26 @@ func GenerateConfig(cfg Config, registry Registry) ([]byte, error) {
return append(data, '\n'), nil return append(data, '\n'), nil
} }
func applyFloatingMargins(out map[string]any, position string) { func applyFloatingMargins(out map[string]any, position string, endMargin int) {
const edgeMargin = 8
switch position { switch position {
case "top": case "top":
out["margin-top"] = 8 out["margin-top"] = edgeMargin
out["margin-left"] = 8 out["margin-left"] = endMargin
out["margin-right"] = 8 out["margin-right"] = endMargin
case "bottom": case "bottom":
out["margin-bottom"] = 8 out["margin-bottom"] = edgeMargin
out["margin-left"] = 8 out["margin-left"] = endMargin
out["margin-right"] = 8 out["margin-right"] = endMargin
case "left": case "left":
out["margin-top"] = 8 out["margin-left"] = edgeMargin
out["margin-bottom"] = 8 out["margin-top"] = endMargin
out["margin-left"] = 8 out["margin-bottom"] = endMargin
case "right": case "right":
out["margin-top"] = 8 out["margin-right"] = edgeMargin
out["margin-bottom"] = 8 out["margin-top"] = endMargin
out["margin-right"] = 8 out["margin-bottom"] = endMargin
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment