panel: add end margin option

parent 269c5d7a
......@@ -75,6 +75,14 @@ Module spacing:
}
```
End margins for floating and island panels:
```json
{
"end_margin": 8
}
```
## Module Resolution
The config stores logical module names. At generation time, the panel merges
......
......@@ -3,6 +3,7 @@
"type": "panel",
"output": [],
"spacing": 10,
"end_margin": 8,
"modules_left": [
"image#menu",
"tray"
......
......@@ -22,6 +22,7 @@ type Config struct {
Type string `json:"type"`
Output []string `json:"output"`
Spacing int `json:"spacing"`
EndMargin int `json:"end_margin"`
ModulesLeft []string `json:"modules_left"`
ModulesCenter []string `json:"modules_center"`
ModulesRight []string `json:"modules_right"`
......@@ -88,6 +89,10 @@ func (c Config) Validate() error {
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...)...) {
if strings.TrimSpace(name) == "" {
return errors.New("module name cannot be empty")
......
......@@ -35,7 +35,7 @@ func GenerateConfig(cfg Config, registry Registry) ([]byte, error) {
}
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)
......@@ -62,24 +62,26 @@ func GenerateConfig(cfg Config, registry Registry) ([]byte, error) {
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 {
case "top":
out["margin-top"] = 8
out["margin-left"] = 8
out["margin-right"] = 8
out["margin-top"] = edgeMargin
out["margin-left"] = endMargin
out["margin-right"] = endMargin
case "bottom":
out["margin-bottom"] = 8
out["margin-left"] = 8
out["margin-right"] = 8
out["margin-bottom"] = edgeMargin
out["margin-left"] = endMargin
out["margin-right"] = endMargin
case "left":
out["margin-top"] = 8
out["margin-bottom"] = 8
out["margin-left"] = 8
out["margin-left"] = edgeMargin
out["margin-top"] = endMargin
out["margin-bottom"] = endMargin
case "right":
out["margin-top"] = 8
out["margin-bottom"] = 8
out["margin-right"] = 8
out["margin-right"] = edgeMargin
out["margin-top"] = endMargin
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