Made buffer's dot private

This commit is contained in:
Sasha Koshka 2022-11-15 17:41:08 -05:00
parent 77cf88b856
commit 85994112cf
3 changed files with 13 additions and 14 deletions

View File

@ -61,9 +61,9 @@ type Buffer struct {
width int width int
height int height int
Dot struct { dot struct {
X int x int
Y int y int
} }
} }
@ -83,11 +83,11 @@ func (buffer *Buffer) Size () (width, height int) {
return return
} }
// ResetDot is a convenience method to reset the dot to the buffer origin point // SetDot sets the buffer's text insertion position relative to the buffer
// (0, 0). // origin point (0, 0).
func (buffer *Buffer) ResetDot () { func (buffer *Buffer) SetDot (x, y int) {
buffer.Dot.X = 0 buffer.dot.x = x
buffer.Dot.Y = 0 buffer.dot.y = y
} }
// Cell returns the cell at the specified x and y coordinates. If the // Cell returns the cell at the specified x and y coordinates. If the
@ -142,9 +142,9 @@ func (buffer *Buffer) Write (bytes []byte) (bytesWritten int, err error) {
bytesWritten = len(bytes) bytesWritten = len(bytes)
for _, character := range text { for _, character := range text {
buffer.SetRune(buffer.Dot.X, buffer.Dot.Y, character) buffer.SetRune(buffer.dot.x, buffer.dot.y, character)
buffer.Dot.X ++ buffer.dot.x ++
if buffer.Dot.X > buffer.width { break } if buffer.dot.x > buffer.width { break }
} }
return return

View File

@ -47,8 +47,7 @@ func redraw () {
text := "RAINBOW :D" text := "RAINBOW :D"
width, height := application.Size() width, height := application.Size()
application.Dot.X = (width - len(text)) / 2 application.SetDot((width - len(text)) / 2, height / 2)
application.Dot.Y = height / 2
fmt.Fprintln(application, text) fmt.Fprintln(application, text)
application.SetColor(0, 0, stone.ColorYellow) application.SetColor(0, 0, stone.ColorYellow)

View File

@ -55,7 +55,7 @@ func main () {
func redraw () { func redraw () {
currentTime = time.Now() currentTime = time.Now()
application.ResetDot() application.SetDot(0, 0)
fmt.Fprintln(application, "hellorld!") fmt.Fprintln(application, "hellorld!")
hour := currentTime.Hour() hour := currentTime.Hour()