Add convenience constructors for attributes

This commit is contained in:
Sasha Koshka 2024-07-21 00:19:16 -04:00
parent 4b56306bd2
commit ba31748b2e

View File

@ -77,6 +77,47 @@ type AttrFace struct { font.Face }
// AttrAlign sets the alignment, if the box is a ContentBox.
type AttrAlign struct { X, Y Align }
// AColor is a convenience constructor for the color attribute.
func AColor (col color.Color) AttrColor {
return AttrColor { Color: col }
}
// ATexture is a convenience constructor for the texture attribute.
func ATexture (texture canvas.Texture) AttrTexture {
return AttrTexture { Texture: texture }
}
// ABorder is a convenience constructor for the border attribute.
func ABorder (borders ...Border) AttrBorder {
return AttrBorder(borders)
}
// AMinimumSize is a convenience constructor for the minimum size attribute.
func AMinimumSize (x, y int) AttrMinimumSize {
return AttrMinimumSize(image.Pt(x, y))
}
// APadding is a convenience constructor for the padding attribute.
func APadding (sides ...int) AttrPadding {
return AttrPadding(I(sides...))
}
// AGap is a convenience constructor for the gap attribute.
func AGap (x, y int) AttrGap {
return AttrGap(image.Pt(x, y))
}
// ATextColor is a convenience constructor for the text color attribute.
func ATextColor (col color.Color) AttrTextColor {
return AttrTextColor { Color: col }
}
// ADotColor is a convenience constructor for the dot color attribute.
func ADotColor (col color.Color) AttrDotColor {
return AttrDotColor { Color: col }
}
// AFace is a convenience constructor for the face attribute.
func AFace (face font.Face) AttrFace {
return AttrFace { Face: face }
}
// AAlign is a convenience constructor for the align attribute.
func AAlign (x, y Align) AttrAlign {
return AttrAlign { X: x, Y: y }
}
func (AttrColor) attr () int { return 0 }
func (AttrTexture) attr () int { return 1 }
func (AttrBorder) attr () int { return 2 }