// Draw displays the styled text in a given grid. It returns the smallest grid
// slice containing the drawn part. Note that the grid is not cleared with
// spaces beforehand by this function, not even the returned one, you should
// use the styled text with a label for this.
Draw displays the styled text in a given grid. It returns the smallest grid
slice containing the drawn part. Note that the grid is not cleared with
spaces beforehand by this function, not even the returned one, you should
use the styled text with a label for this.
// Draw displays the styled text in a given grid . It returns the smallest grid // slice containing the drawn part . Note that the grid is not cleared with // spaces beforehand by this function not even the returned one you should // use the styled text with a label for this .
func (stt StyledText) Draw(gd gruid.Grid) gruid.Grid {
	it := gd.Iterator()
	if !it.Next() {
		return gd
	}
	x, y := 0, 0
	xmax := 0
	c := gruid.Cell{Style: stt.style}
	markup := stt.markups != nil 
	procm := false               
	for _, r := range stt.text {
		if markup {
			if procMarkup(procm, r) {
				if procm {
					c.Style = stt.markupStyle(r)
				}
				procm = !procm
				continue
			}
			procm = false
		}
		p := it.P()
		if r == '\n' {
			if x > xmax {
				xmax = x
			}
			x = 0
			y++
			if p.Y < y {
				it.SetP(gruid.Point{x, y})
				if it.P().Y != y {
					break
				}
			}
			continue
		}
		x++
		if p.Y > y {
			continue
		}
		c.Rune = r
		it.SetCell(c)
		if !it.Next() {
			break
		}
	}
	if x > xmax {
		xmax = x
	}
	if xmax > 0 || y > 0 {
		y++ 
	}
	return gd.Slice(gruid.NewRange(0, 0, xmax, y))
}
func ( stt StyledText ) Draw ( gd gruid . Grid ) gruid . Grid { it := gd . Iterator ( ) if ! it . Next ( ) { return gd } x , y := 0 , 0 xmax := 0 c := gruid . Cell { Style : stt . style } markup := stt . markups != nil procm := false for _ , r := range stt . text { if markup { if procMarkup ( procm , r ) { if procm { c . Style = stt . markupStyle ( r ) } procm = ! procm continue } procm = false } p := it . P ( ) if r == '\n' { if x > xmax { xmax = x } x = 0 y ++ if p . Y < y { it . SetP ( gruid . Point { x , y } ) if it . P ( ) . Y != y { break } } continue } x ++ if p . Y > y { continue } c . Rune = r it . SetCell ( c ) if ! it . Next ( ) { break } } if x > xmax { xmax = x } if xmax > 0 || y > 0 { y ++ } return gd . Slice ( gruid . NewRange ( 0 , 0 , xmax , y ) ) }
Draw displays the styled text in a given grid.
Draw displays the styled text in a given grid .
// whether markup is activated // processing markup // at least one line