// Draw draws a rectangular box in a grid, taking the whole grid. It does not
// draw anything in the interior region. It returns the grid slice that was
// drawn, which usually is the whole grid, except if the grid was too small to
// draw a box.
Draw draws a rectangular box in a grid, taking the whole grid. It does not
draw anything in the interior region. It returns the grid slice that was
drawn, which usually is the whole grid, except if the grid was too small to
draw a box.
// Draw draws a rectangular box in a grid taking the whole grid . It does not // draw anything in the interior region . It returns the grid slice that was // drawn which usually is the whole grid except if the grid was too small to // draw a box .
func (b Box) Draw(gd gruid.Grid) gruid.Grid {
	rg := gd.Range()
	max := rg.Size()
	if max.X < 2 || max.Y < 2 {
		return gd.Slice(gruid.Range{})
	}
	cgrid := gd.Slice(rg.Shift(1, 0, -1, 0))
	crg := cgrid.Range()
	cell := gruid.Cell{Style: b.Style}
	cell.Rune = '─'
	max = crg.Size()
	line := cgrid.Slice(crg.Line(0))
	line.Fill(cell)
	if b.Title.Text() != "" {
		b.Title.drawTextLine(line, b.AlignTitle)
	}
	line = cgrid.Slice(crg.Line(max.Y - 1))
	line.Fill(cell)
	if b.Footer.Text() != "" {
		b.Footer.drawTextLine(line, b.AlignFooter)
	}
	max = rg.Size()
	gd.Set(rg.Min, cell.WithRune('┌'))
	gd.Set(gruid.Point{X: max.X - 1}, cell.WithRune('┐'))
	gd.Set(gruid.Point{Y: max.Y - 1}, cell.WithRune('└'))
	gd.Set(rg.Max.Shift(-1, -1), cell.WithRune('┘'))
	cell.Rune = '│'
	col := gd.Slice(rg.Shift(0, 1, 0, -1).Column(0))
	col.Fill(cell)
	col = gd.Slice(rg.Shift(0, 1, 0, -1).Column(max.X - 1))
	col.Fill(cell)
	return gd
}
func ( b Box ) Draw ( gd gruid . Grid ) gruid . Grid { rg := gd . Range ( ) max := rg . Size ( ) if max . X < 2 || max . Y < 2 { return gd . Slice ( gruid . Range { } ) } cgrid := gd . Slice ( rg . Shift ( 1 , 0 , - 1 , 0 ) ) crg := cgrid . Range ( ) cell := gruid . Cell { Style : b . Style } cell . Rune = '─' max = crg . Size ( ) line := cgrid . Slice ( crg . Line ( 0 ) ) line . Fill ( cell ) if b . Title . Text ( ) != " " { b . Title . drawTextLine ( line , b . AlignTitle ) } line = cgrid . Slice ( crg . Line ( max . Y - 1 ) ) line . Fill ( cell ) if b . Footer . Text ( ) != " " { b . Footer . drawTextLine ( line , b . AlignFooter ) } max = rg . Size ( ) gd . Set ( rg . Min , cell . WithRune ( '┌')) gd . Set ( gruid . Point { X : max . X - 1 } , cell . WithRune ( '┐')) gd . Set ( gruid . Point { Y : max . Y - 1 } , cell . WithRune ( '└')) gd . Set ( rg . Max . Shift ( - 1 , - 1 ) , cell . WithRune ( '┘')) cell . Rune = '│' col := gd . Slice ( rg . Shift ( 0 , 1 , 0 , - 1 ) . Column ( 0 ) ) col . Fill ( cell ) col = gd . Slice ( rg . Shift ( 0 , 1 , 0 , - 1 ) . Column ( max . X - 1 ) ) col . Fill ( cell ) return gd }
Draw draws a rectangular box in a grid, taking the whole grid.
Draw draws a rectangular box in a grid taking the whole grid .