Make text wrapping an attribute

This commit is contained in:
2024-07-25 04:01:46 -04:00
parent 3bd9de9110
commit 13e318253b
2 changed files with 19 additions and 10 deletions

View File

@@ -72,6 +72,8 @@ type AttrTextColor struct { color.Color }
type AttrDotColor struct { color.Color }
// AttrFace sets the font face, if the box is a TextBox.
type AttrFace struct { font.Face }
// AttrWrap sets if the text wraps, if the box is a TextBox.
type AttrWrap bool
// AttrAlign sets the alignment, if the box is a ContentBox.
type AttrAlign struct { X, Y Align }
// AttrOverflow sets the overflow, if the box is a ContentBox.
@@ -119,6 +121,10 @@ func ADotColor (col color.Color) AttrDotColor {
func AFace (face font.Face) AttrFace {
return AttrFace { Face: face }
}
// AWrap is a convenience constructor for the wrap attribute.
func AWrap (wrap bool) AttrWrap {
return AttrWrap(wrap)
}
// AAlign is a convenience constructor for the align attribute.
func AAlign (x, y Align) AttrAlign {
return AttrAlign { X: x, Y: y }
@@ -210,7 +216,6 @@ func (this AttrDotColor) Equals (other Attr) bool {
return false
}
}
// Equals returns true if both attributes can reasonably be declared equal.
func (this AttrFace) Equals (other Attr) bool {
if other, ok := other.(AttrFace); ok {
@@ -219,7 +224,14 @@ func (this AttrFace) Equals (other Attr) bool {
return false
}
}
// Equals returns true if both attributes can reasonably be declared equal.
func (this AttrWrap) Equals (other Attr) bool {
if other, ok := other.(AttrWrap); ok {
return this == other
} else {
return false
}
}
// Equals returns true if both attributes can reasonably be declared equal.
func (this AttrAlign) Equals (other Attr) bool {
if other, ok := other.(AttrAlign); ok {
@@ -228,7 +240,6 @@ func (this AttrAlign) Equals (other Attr) bool {
return false
}
}
// Equals returns true if both attributes can reasonably be declared equal.
func (this AttrOverflow) Equals (other Attr) bool {
if other, ok := other.(AttrOverflow); ok {
@@ -237,7 +248,6 @@ func (this AttrOverflow) Equals (other Attr) bool {
return false
}
}
// Equals returns true if both attributes can reasonably be declared equal.
func (this AttrLayout) Equals (other Attr) bool {
if other, ok := other.(AttrLayout); ok {
@@ -264,6 +274,7 @@ func (AttrGap) attr () int { return 6 }
func (AttrTextColor) attr () int { return 7 }
func (AttrDotColor) attr () int { return 8 }
func (AttrFace) attr () int { return 9 }
func (AttrAlign) attr () int { return 10 }
func (AttrOverflow) attr () int { return 11 }
func (AttrLayout) attr () int { return 12 }
func (AttrWrap) attr () int { return 10 }
func (AttrAlign) attr () int { return 11 }
func (AttrOverflow) attr () int { return 12 }
func (AttrLayout) attr () int { return 13 }

View File

@@ -169,9 +169,7 @@ type TextBox interface {
// SetText sets the text content of the Box.
SetText (string)
// SetWrap sets whether or not the text wraps.
SetWrap (bool)
// SetSelectable sets whether or not the text content can be
// highlighted/selected.
SetSelectable (bool)