@@ -1,6 +1,7 @@
1package lipgloss
1package lipgloss
@@ -94,17 +95,14 @@ type Layer struct {
94 zIndex int
95 zIndex int
95 children []*Layer
96 children []*Layer
97− content string
98+ content uv.Drawable
100// NewLayer creates a new Layer with the given content. It calculates the size
101// NewLayer creates a new Layer with the given content. It calculates the size
101// based on the widest line and the number of lines in the content.
102// based on the widest line and the number of lines in the content.
102−func NewLayer(content string) (l *Layer) {
103+func NewLayer(content any) (l *Layer) {
103 l = new(Layer)
104 l = new(Layer)
105− height := Height(content)
106− width := Width(content)
105+ l.SetContent(content)
107− l.rect = image.Rect(0, 0, width, height)
@@ -216,23 +214,56 @@ func (l *Layer) AddLayers(layers ...*Layer) *Layer {
218// SetContent sets the content of the Layer.
216// SetContent sets the content of the Layer.
219−func (l *Layer) SetContent(content string) *Layer {
217+func (l *Layer) SetContent(content any) *Layer {
218+ var drawable uv.Drawable
219+ var rect image.Rectangle
220+ switch c := content.(type) {
223+ switch c := c.(type) {
224+ case interface{ Bounds() image.Rectangle }:
225+ rect.Max.X = c.Bounds().Dx()
226+ rect.Max.Y = c.Bounds().Dy()
231+ rect.Max.X = c.Width()
232+ rect.Max.Y = c.Height()
236+ drawable = uv.NewStyledString(s)
237+ rect = image.Rect(0, 0, Width(s), Height(s))
239+ drawable = uv.NewStyledString(c)
240+ rect = image.Rect(0, 0, Width(c), Height(c))
242+ s := fmt.Sprint(content)
243+ drawable = uv.NewStyledString(s)
244+ rect = image.Rect(0, 0, Width(s), Height(s))
220− l.content = content
246+ l.content = drawable
224// Content returns the content of the Layer.
251// Content returns the content of the Layer.
225−func (l *Layer) Content() string {
252+func (l *Layer) Content() any {
226 return l.content
253 return l.content
229// Draw draws the Layer onto the given screen buffer.
256// Draw draws the Layer onto the given screen buffer.
230−func (l *Layer) Draw(scr uv.Screen, _ image.Rectangle) {
257+func (l *Layer) Draw(scr uv.Screen, area image.Rectangle) {
231− ss := uv.NewStyledString(l.content)
258+ if l.content == nil {
232− ss.Draw(scr, l.Bounds())
261+ l.content.Draw(scr, area.Intersect(l.Bounds()))
233 for _, child := range l.children {
262 for _, child := range l.children {
234− ss := uv.NewStyledString(child.content)
263+ if child.content == nil {
235− ss.Draw(scr, child.Bounds())
266+ child.content.Draw(scr, area.Intersect(child.Bounds()))