// Draw implements gruid.Model.Draw for Pager. It returns the grid slice that
// was drawn, or the whole grid if it is used as main model.
Draw implements gruid.Model.Draw for Pager. It returns the grid slice that
was drawn, or the whole grid if it is used as main model.
// Draw implements gruid . Model . Draw for Pager . It returns the grid slice that // was drawn or the whole grid if it is used as main model .
func (pg *Pager) Draw() gruid.Grid {
	if !pg.dirty {
		if pg.init {
			return pg.drawn.Slice(gruid.Range{})
		}
		return pg.drawn
	}
	h, bh := pg.height()
	grid := pg.grid.Slice(pg.grid.Range().Lines(0, h))
	if pg.init {
		pg.grid.Fill(gruid.Cell{Rune: ' '})
	}
	cgrid := grid
	if pg.box != nil {
		var lnumtext string
		if pg.x > 0 {
			lnumtext = fmt.Sprintf("%d-%d/%d+%d", pg.index, pg.index+h-bh-1, len(pg.lines)-1, pg.x)
		} else {
			lnumtext = fmt.Sprintf("%d-%d/%d", pg.index, pg.index+h-bh-1, len(pg.lines)-1)
		}
		foot := pg.box.Footer
		if pg.box.Footer.Text() == "" && h == pg.grid.Size().Y {
			pg.box.Footer = NewStyledText(lnumtext, pg.style.LineNum)
		}
		pg.box.Draw(grid)
		pg.box.Footer = foot
		rg := grid.Range()
		cgrid = grid.Slice(rg.Shift(1, 1, -1, -1))
	}
	rg := cgrid.Range()
	for i := 0; i < h-bh; i++ {
		line := cgrid.Slice(rg.Line(i))
		stt := pg.lines[i+pg.index]
		line.Fill(gruid.Cell{Rune: ' ', Style: stt.Style()})
		stt.Iter(func(p gruid.Point, c gruid.Cell) {
			p = p.Shift(-pg.x, 0)
			if p.X >= 0 {
				line.Set(p, c)
			}
		})
	}
	pg.dirty = false
	pg.drawn = grid
	if pg.init {
		pg.drawn = pg.grid
	}
	return pg.drawn
}
func ( pg * Pager ) Draw ( ) gruid . Grid { if ! pg . dirty { if pg . init { return pg . drawn . Slice ( gruid . Range { } ) } return pg . drawn } h , bh := pg . height ( ) grid := pg . grid . Slice ( pg . grid . Range ( ) . Lines ( 0 , h ) ) if pg . init { pg . grid . Fill ( gruid . Cell { Rune : ' ' } ) } cgrid := grid if pg . box != nil { var lnumtext string if pg . x > 0 { lnumtext = fmt . Sprintf ( " " , pg . index , pg . index + h - bh - 1 , len ( pg . lines ) - 1 , pg . x ) } else { lnumtext = fmt . Sprintf ( " " , pg . index , pg . index + h - bh - 1 , len ( pg . lines ) - 1 ) } foot := pg . box . Footer if pg . box . Footer . Text ( ) == " " && h == pg . grid . Size ( ) . Y { pg . box . Footer = NewStyledText ( lnumtext , pg . style . LineNum ) } pg . box . Draw ( grid ) pg . box . Footer = foot rg := grid . Range ( ) cgrid = grid . Slice ( rg . Shift ( 1 , 1 , - 1 , - 1 ) ) } rg := cgrid . Range ( ) for i := 0 ; i < h - bh ; i ++ { line := cgrid . Slice ( rg . Line ( i ) ) stt := pg . lines [ i + pg . index ] line . Fill ( gruid . Cell { Rune : ' ' , Style : stt . Style ( ) } ) stt . Iter ( func ( p gruid . Point , c gruid . Cell ) { p = p . Shift ( - pg . x , 0 ) if p . X >= 0 { line . Set ( p , c ) } } ) } pg . dirty = false pg . drawn = grid if pg . init { pg . drawn = pg . grid } return pg . drawn }
Draw implements gruid.Model.Draw for Pager.
Draw implements gruid . Model . Draw for Pager .