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
height int
Dot struct {
X int
Y int
dot struct {
x int
y int
}
}
@ -83,11 +83,11 @@ func (buffer *Buffer) Size () (width, height int) {
return
}
// ResetDot is a convenience method to reset the dot to the buffer origin point
// (0, 0).
func (buffer *Buffer) ResetDot () {
buffer.Dot.X = 0
buffer.Dot.Y = 0
// SetDot sets the buffer's text insertion position relative to the buffer
// origin point (0, 0).
func (buffer *Buffer) SetDot (x, y int) {
buffer.dot.x = x
buffer.dot.y = y
}
// 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)
for _, character := range text {
buffer.SetRune(buffer.Dot.X, buffer.Dot.Y, character)
buffer.Dot.X ++
if buffer.Dot.X > buffer.width { break }
buffer.SetRune(buffer.dot.x, buffer.dot.y, character)
buffer.dot.x ++
if buffer.dot.x > buffer.width { break }
}
return

View File

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

View File

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