Update Block comments

This commit is contained in:
Caleb Bassi 2019-01-24 04:02:18 -08:00
parent 33e8d71b32
commit 20d8f73c36

View File

@ -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
}