In ViewBorder structure: the type of Color field is replaced by ColorPair and added CurrentColor method

This commit is contained in:
Alexei Anoshenko 2026-07-10 18:44:36 +03:00
parent 1bce3fea36
commit bd0e918f88
5 changed files with 40 additions and 21 deletions

View File

@ -11,6 +11,7 @@
* Added ViewSeq add ViewCount methods to ParentView interface * Added ViewSeq add ViewCount methods to ParentView interface
* Added ToBoundsProperty method to Bounds struct * Added ToBoundsProperty method to Bounds struct
* Added ColorPair type * Added ColorPair type
* In ViewBorder structure: the type of Color field is replaced by ColorPair and added CurrentColor method
# v0.20.0 # v0.20.0

View File

@ -772,23 +772,18 @@ func (border *borderProperty) ViewBorders(session Session) ViewBorders {
getBorder := func(prefix PropertyName) ViewBorder { getBorder := func(prefix PropertyName) ViewBorder {
var result ViewBorder var result ViewBorder
var ok bool var ok bool
if result.Style, ok = valueToEnum(border.getRaw(prefix+Style), BorderStyle, session, NoneLine); !ok { if result.Style, ok = valueToEnum(border.getRaw(prefix+Style), BorderStyle, session, NoneLine); !ok {
result.Style = defaultStyle result.Style = defaultStyle
} }
if result.Width, ok = sizeProperty(border, prefix+Width, session); !ok { if result.Width, ok = sizeProperty(border, prefix+Width, session); !ok {
result.Width = defaultWidth result.Width = defaultWidth
} }
lightColor, darkColor, ok := colorProperty(border, prefix+ColorTag, session) if result.Color.Light, result.Color.Dark, ok = colorProperty(border, prefix+ColorTag, session); !ok {
if !ok { result.Color.Light = defaultLightColor
lightColor = defaultLightColor result.Color.Dark = defaultDarkColor
darkColor = defaultDarkColor
}
if session.DarkTheme() {
result.Color = darkColor
} else {
result.Color = lightColor
} }
return result return result
@ -837,12 +832,15 @@ func (border *borderProperty) cssColor(builder cssBuilder, session Session) {
if borders.Top.Color == borders.Right.Color && if borders.Top.Color == borders.Right.Color &&
borders.Top.Color == borders.Left.Color && borders.Top.Color == borders.Left.Color &&
borders.Top.Color == borders.Bottom.Color { borders.Top.Color == borders.Bottom.Color {
if borders.Top.Color != 0 { if borders.Top.Color.Light != 0 || borders.Top.Color.Dark != 0 {
builder.add("border-color", borders.Top.Color.cssString()) builder.add("border-color", borders.Top.Color.cssString(session))
} }
} else { } else {
builder.addValues("border-color", " ", borders.Top.Color.cssString(), builder.addValues("border-color", " ",
borders.Right.Color.cssString(), borders.Bottom.Color.cssString(), borders.Left.Color.cssString()) 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 Style int
// Color of the border line // Color of the border line
Color Color Color ColorPair
// Width of the border line // Width of the border line
Width SizeUnit Width SizeUnit
@ -881,6 +879,14 @@ type ViewBorders struct {
Top, Right, Bottom, Left ViewBorder 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 // AllTheSame returns true if all borders are the same
func (border *ViewBorders) AllTheSame() bool { func (border *ViewBorders) AllTheSame() bool {
return border.Top.Style == border.Right.Style && return border.Top.Style == border.Right.Style &&

View File

@ -255,3 +255,18 @@ func parseColorPair(obj DataObject) (ColorPair, bool) {
func (pair ColorPair) String() string { func (pair ColorPair) String() string {
return fmt.Sprintf("_{ light = %s, dark = %s }", pair.Light.String(), pair.Dark.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()
}

View File

@ -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 // 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 { func GetColumnSeparatorColor(view View, subviewID ...string) Color {
border := getColumnSeparator(view, subviewID) border := getColumnSeparator(view, subviewID)
return border.Color return border.CurrentColor(view.Session())
} }
// GetColumnFill returns a "column-fill" property value of the subview. // GetColumnFill returns a "column-fill" property value of the subview.

View File

@ -129,15 +129,12 @@ func getColumnSeparatorProperty(properties Properties) ColumnSeparatorProperty {
func (separator *columnSeparatorProperty) ViewBorder(session Session) ViewBorder { func (separator *columnSeparatorProperty) ViewBorder(session Session) ViewBorder {
style, _ := valueToEnum(separator.getRaw(Style), BorderStyle, session, NoneLine) style, _ := valueToEnum(separator.getRaw(Style), BorderStyle, session, NoneLine)
width, _ := sizeProperty(separator, Width, session) width, _ := sizeProperty(separator, Width, session)
color, darkColor, _ := colorProperty(separator, ColorTag, session) lightColor, darkColor, _ := colorProperty(separator, ColorTag, session)
if session.DarkTheme() {
color = darkColor
}
return ViewBorder{ return ViewBorder{
Style: style, Style: style,
Width: width, Width: width,
Color: color, Color: ColorPair{Light: lightColor, Dark: darkColor},
} }
} }