Skip to content

Commit

Permalink
Allow disabling fields (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGroundZero authored Feb 2, 2025
1 parent 39d4bd6 commit 49506ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion example/default.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ title:
maxWidth: 946
lineSpacing: 10
category:
enabled: true
start:
px: 126
py: 119
fgHexColor: "#8D8D8D"
fontSize: 42
fontStyle: Regular
info:
enabled: true
start:
px: 227
py: 441
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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)

Expand All @@ -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}
}
Expand All @@ -137,3 +146,7 @@ func setArgsAsDefaultTextOption(to *TextOption, dto *TextOption) {
func ptrInt(x int) *int {
return &x
}

func ptrBool(b bool) *bool {
return &b
}

0 comments on commit 49506ed

Please sign in to comment.