mirror of https://github.com/gizak/termui.git
48 lines
906 B
Go
48 lines
906 B
Go
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
|
// Use of this source code is governed by a MIT license that can
|
|
// be found in the LICENSE file.
|
|
|
|
package widgets
|
|
|
|
import (
|
|
"image"
|
|
|
|
. "github.com/gizak/termui"
|
|
)
|
|
|
|
type Paragraph struct {
|
|
Block
|
|
Text string
|
|
TextStyle Style
|
|
WrapText bool
|
|
}
|
|
|
|
func NewParagraph() *Paragraph {
|
|
return &Paragraph{
|
|
Block: *NewBlock(),
|
|
TextStyle: Theme.Paragraph.Text,
|
|
WrapText: true,
|
|
}
|
|
}
|
|
|
|
func (self *Paragraph) Draw(buf *Buffer) {
|
|
self.Block.Draw(buf)
|
|
|
|
cells := ParseText(self.Text, self.TextStyle)
|
|
if self.WrapText {
|
|
cells = WrapCells(cells, uint(self.Inner.Dx()))
|
|
}
|
|
|
|
rows := SplitCells(cells, '\n')
|
|
|
|
for y, row := range rows {
|
|
if y+self.Inner.Min.Y >= self.Inner.Max.Y {
|
|
break
|
|
}
|
|
row = TrimCells(row, self.Inner.Dx())
|
|
for x, cell := range row {
|
|
buf.SetCell(cell, image.Pt(x, y).Add(self.Inner.Min))
|
|
}
|
|
}
|
|
}
|