Skip to content

Commit

Permalink
ssd1306: add FillRectangle() and SetScroll() functions to satisfy tin…
Browse files Browse the repository at this point in the history
…yterm.Displayer interface

Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram authored and conejoninja committed Oct 27, 2024
1 parent 30f540c commit 829ae09
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ssd1306/ssd1306.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,31 @@ func (d *Device) Sleep(sleepEnabled bool) error {
}
return nil
}

// FillRectangle fills a rectangle at a given coordinates with a color
func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error {
dw, dh := d.Size()

if x < 0 || y < 0 || width <= 0 || height <= 0 ||
x >= d.width || (x+width) > dw || y >= dh || (y+height) > dh {
return errOutOfRange
}

if x+width == dw && y+height == dh && c.R == 0 && c.G == 0 && c.B == 0 {
d.ClearDisplay()
return nil
}

for i := x; i < x+width; i++ {
for j := y; j < y+height; j++ {
d.SetPixel(i, j, c)
}
}

return nil
}

// SetScroll sets the vertical scrolling for the display, which is a NOP for this display.
func (d *Device) SetScroll(line int16) {
return
}

0 comments on commit 829ae09

Please sign in to comment.