From 49506ed99e9f58cfc0db9aedbb4ca7422d637060 Mon Sep 17 00:00:00 2001 From: TheGroundZero <2406013+TheGroundZero@users.noreply.github.com> Date: Sun, 2 Feb 2025 03:31:16 +0100 Subject: [PATCH] Allow disabling fields (#35) --- example/default.config.yaml | 5 ++++- pkg/config/config.go | 7 +++++-- pkg/config/default.go | 13 +++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/example/default.config.yaml b/example/default.config.yaml index a634e51..4ba9b15 100644 --- a/example/default.config.yaml +++ b/example/default.config.yaml @@ -9,6 +9,7 @@ title: maxWidth: 946 lineSpacing: 10 category: + enabled: true start: px: 126 py: 119 @@ -16,6 +17,7 @@ category: fontSize: 42 fontStyle: Regular info: + enabled: true start: px: 227 py: 441 @@ -25,11 +27,12 @@ info: separator: "・" timeFormat: "Jan 2" tags: + enabled: true start: px: 1025 py: 451 fgHexColor: "#FFFFFF" - bgHexColor: "#7F7776" + bgHexColor: "#60BCE0" fontSize: 22 fontStyle: Medium boxAlign: Right diff --git a/pkg/config/config.go b/pkg/config/config.go index 836f776..2717428 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -20,12 +20,14 @@ type TextOption struct { FontStyle fontfamily.Style `json:"fontStyle,omitempty"` Separator string `json:"separator,omitempty"` TimeFormat string `json:"timeFormat,omitempty"` + Enabled *bool `json:"enabled,omitempty"` } type MultiLineTextOption struct { TextOption - MaxWidth int `json:"maxWidth,omitempty"` - LineSpacing *int `json:"lineSpacing,omitempty"` + MaxWidth int `json:"maxWidth,omitempty"` + LineSpacing *int `json:"lineSpacing,omitempty"` + Enabled *bool `json:"enabled,omitempty"` } type BoxTextsOption struct { @@ -34,6 +36,7 @@ type BoxTextsOption struct { BoxPadding *Padding `json:"boxPadding,omitempty"` BoxSpacing *int `json:"boxSpacing,omitempty"` BoxAlign box.Align `json:"boxAlign,omitempty"` + Enabled *bool `json:"enabled,omitempty"` } type Point struct { diff --git a/pkg/config/default.go b/pkg/config/default.go index 8a23872..ca710f0 100644 --- a/pkg/config/default.go +++ b/pkg/config/default.go @@ -19,12 +19,14 @@ var defaultCnf = DrawingConfig{ LineSpacing: ptrInt(10), }, Category: &TextOption{ + Enabled: ptrBool(true), Start: &Point{X: 126, Y: 119}, FgHexColor: "#8D8D8D", FontSize: 42, FontStyle: fontfamily.Regular, }, Info: &TextOption{ + Enabled: ptrBool(true), Start: &Point{X: 227, Y: 441}, FgHexColor: "#8D8D8D", FontSize: 38, @@ -33,6 +35,7 @@ var defaultCnf = DrawingConfig{ TimeFormat: "Jan 2", }, Tags: &BoxTextsOption{ + Enabled: ptrBool(true), TextOption: TextOption{ Start: &Point{X: 1025, Y: 451}, FgHexColor: "#FFFFFF", @@ -96,6 +99,9 @@ func defaultTags(bto *BoxTextsOption) { if bto == nil { bto = &BoxTextsOption{} } + if bto.Enabled == nil { + bto.Enabled = defaultCnf.Tags.Enabled + } setArgsAsDefaultTextOption(&bto.TextOption, &defaultCnf.Tags.TextOption) @@ -114,6 +120,9 @@ func defaultTags(bto *BoxTextsOption) { } func setArgsAsDefaultTextOption(to *TextOption, dto *TextOption) { + if to.Enabled == nil { + to.Enabled = dto.Enabled + } if to.Start == nil { to.Start = &Point{X: dto.Start.X, Y: dto.Start.Y} } @@ -137,3 +146,7 @@ func setArgsAsDefaultTextOption(to *TextOption, dto *TextOption) { func ptrInt(x int) *int { return &x } + +func ptrBool(b bool) *bool { + return &b +}