Skip to content

Commit 829ae09

Browse files
deadprogramconejoninja
authored andcommitted
ssd1306: add FillRectangle() and SetScroll() functions to satisfy tinyterm.Displayer interface
Signed-off-by: deadprogram <[email protected]>
1 parent 30f540c commit 829ae09

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

ssd1306/ssd1306.go

+28
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,31 @@ func (d *Device) Sleep(sleepEnabled bool) error {
396396
}
397397
return nil
398398
}
399+
400+
// FillRectangle fills a rectangle at a given coordinates with a color
401+
func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error {
402+
dw, dh := d.Size()
403+
404+
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
405+
x >= d.width || (x+width) > dw || y >= dh || (y+height) > dh {
406+
return errOutOfRange
407+
}
408+
409+
if x+width == dw && y+height == dh && c.R == 0 && c.G == 0 && c.B == 0 {
410+
d.ClearDisplay()
411+
return nil
412+
}
413+
414+
for i := x; i < x+width; i++ {
415+
for j := y; j < y+height; j++ {
416+
d.SetPixel(i, j, c)
417+
}
418+
}
419+
420+
return nil
421+
}
422+
423+
// SetScroll sets the vertical scrolling for the display, which is a NOP for this display.
424+
func (d *Device) SetScroll(line int16) {
425+
return
426+
}

0 commit comments

Comments
 (0)