diff --git a/CHANGELOG.md b/CHANGELOG.md index f40ff12..7371a55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Added ViewSeq add ViewCount methods to ParentView interface * Added ToBoundsProperty method to Bounds struct * Added ColorPair type +* In ViewBorder structure: the type of Color field is replaced by ColorPair and added CurrentColor method # v0.20.0 diff --git a/border.go b/border.go index 7b0316e..8c0e3b6 100644 --- a/border.go +++ b/border.go @@ -772,23 +772,18 @@ func (border *borderProperty) ViewBorders(session Session) ViewBorders { getBorder := func(prefix PropertyName) ViewBorder { var result ViewBorder var ok bool + if result.Style, ok = valueToEnum(border.getRaw(prefix+Style), BorderStyle, session, NoneLine); !ok { result.Style = defaultStyle } + if result.Width, ok = sizeProperty(border, prefix+Width, session); !ok { result.Width = defaultWidth } - lightColor, darkColor, ok := colorProperty(border, prefix+ColorTag, session) - if !ok { - lightColor = defaultLightColor - darkColor = defaultDarkColor - } - - if session.DarkTheme() { - result.Color = darkColor - } else { - result.Color = lightColor + if result.Color.Light, result.Color.Dark, ok = colorProperty(border, prefix+ColorTag, session); !ok { + result.Color.Light = defaultLightColor + result.Color.Dark = defaultDarkColor } return result @@ -837,12 +832,15 @@ func (border *borderProperty) cssColor(builder cssBuilder, session Session) { if borders.Top.Color == borders.Right.Color && borders.Top.Color == borders.Left.Color && borders.Top.Color == borders.Bottom.Color { - if borders.Top.Color != 0 { - builder.add("border-color", borders.Top.Color.cssString()) + if borders.Top.Color.Light != 0 || borders.Top.Color.Dark != 0 { + builder.add("border-color", borders.Top.Color.cssString(session)) } } else { - builder.addValues("border-color", " ", borders.Top.Color.cssString(), - borders.Right.Color.cssString(), borders.Bottom.Color.cssString(), borders.Left.Color.cssString()) + builder.addValues("border-color", " ", + borders.Top.Color.cssString(session), + borders.Right.Color.cssString(session), + borders.Bottom.Color.cssString(session), + borders.Left.Color.cssString(session)) } } @@ -870,7 +868,7 @@ type ViewBorder struct { Style int // Color of the border line - Color Color + Color ColorPair // Width of the border line Width SizeUnit @@ -881,6 +879,14 @@ type ViewBorders struct { Top, Right, Bottom, Left ViewBorder } +// CurrentColor returns the border color used in the current theme. +func (border *ViewBorder) CurrentColor(session Session) Color { + if session.DarkTheme() { + return border.Color.Dark + } + return border.Color.Light +} + // AllTheSame returns true if all borders are the same func (border *ViewBorders) AllTheSame() bool { return border.Top.Style == border.Right.Style && diff --git a/color.go b/color.go index e87ab68..cf8bd71 100644 --- a/color.go +++ b/color.go @@ -255,3 +255,18 @@ func parseColorPair(obj DataObject) (ColorPair, bool) { func (pair ColorPair) String() string { return fmt.Sprintf("_{ light = %s, dark = %s }", pair.Light.String(), pair.Dark.String()) } + +func (pair ColorPair) cssString(session Session) string { + + if session.lightDarkSupport() { + buffer := allocStringBuilder() + defer freeStringBuilder(buffer) + writeColorCSS(buffer, pair.Light, pair.Dark, session) + return buffer.String() + } + + if session.DarkTheme() { + return pair.Dark.cssString() + } + return pair.Light.cssString() +} diff --git a/columnLayout.go b/columnLayout.go index 5ad864a..d9455bb 100644 --- a/columnLayout.go +++ b/columnLayout.go @@ -244,7 +244,7 @@ func GetColumnSeparatorWidth(view View, subviewID ...string) SizeUnit { // If the second argument (subviewID) is not specified or it is "" then a top position of the first argument (view) is returned func GetColumnSeparatorColor(view View, subviewID ...string) Color { border := getColumnSeparator(view, subviewID) - return border.Color + return border.CurrentColor(view.Session()) } // GetColumnFill returns a "column-fill" property value of the subview. diff --git a/columnSeparator.go b/columnSeparator.go index 4037764..5ed3a12 100644 --- a/columnSeparator.go +++ b/columnSeparator.go @@ -129,15 +129,12 @@ func getColumnSeparatorProperty(properties Properties) ColumnSeparatorProperty { func (separator *columnSeparatorProperty) ViewBorder(session Session) ViewBorder { style, _ := valueToEnum(separator.getRaw(Style), BorderStyle, session, NoneLine) width, _ := sizeProperty(separator, Width, session) - color, darkColor, _ := colorProperty(separator, ColorTag, session) - if session.DarkTheme() { - color = darkColor - } + lightColor, darkColor, _ := colorProperty(separator, ColorTag, session) return ViewBorder{ Style: style, Width: width, - Color: color, + Color: ColorPair{Light: lightColor, Dark: darkColor}, } }