From 20d8f73c36440287fd2f1cf3ca35ce22f06d4433 Mon Sep 17 00:00:00 2001 From: Caleb Bassi Date: Thu, 24 Jan 2019 04:02:18 -0800 Subject: [PATCH] Update Block comments --- block.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/block.go b/block.go index bc11746..8ebbd85 100644 --- a/block.go +++ b/block.go @@ -8,9 +8,10 @@ import ( "image" ) -// Block is the base struct inherited by all widgets. -// Block manages size, border, and title. -// It implements 2 of the 3 methods needed for `Drawable` interface: `GetRect` and `SetRect`. +// Block is the base struct inherited by most widgets. +// Block manages size, position, border, and title. +// It implements all 3 of the methods needed for the `Drawable` interface. +// Custom widgets will override the Draw method. type Block struct { Border bool BorderStyle Style @@ -40,10 +41,6 @@ func NewBlock() *Block { } func (self *Block) drawBorder(buf *Buffer) { - if !self.Border { - return - } - verticalCell := Cell{VERTICAL_LINE, self.BorderStyle} horizontalCell := Cell{HORIZONTAL_LINE, self.BorderStyle} @@ -76,8 +73,11 @@ func (self *Block) drawBorder(buf *Buffer) { } } +// Draw implements the Drawable interface. func (self *Block) Draw(buf *Buffer) { - self.drawBorder(buf) + if self.Border { + self.drawBorder(buf) + } buf.SetString( self.Title, self.TitleStyle, @@ -85,11 +85,13 @@ func (self *Block) Draw(buf *Buffer) { ) } +// SetRect implements the Drawable interface. func (self *Block) SetRect(x1, y1, x2, y2 int) { self.Rectangle = image.Rect(x1, y1, x2, y2) self.Inner = image.Rect(self.Min.X+1, self.Min.Y+1, self.Max.X-1, self.Max.Y-1) } +// GetRect implements the Drawable interface. func (self *Block) GetRect() image.Rectangle { return self.Rectangle }