jhanarato / uposatha-inky

Display the uposatha on a Pimoroni Inky display
MIT License
0 stars 0 forks source link

Change components' `draw()` to take an `ImageDraw` #17

Closed jhanarato closed 1 year ago

jhanarato commented 1 year ago

The best (?) way to get rid of the many draw objects I'm passing around is to pass the draw object when calling the draw method. Like this:

def draw(self, drawing: ImageDraw, x: int, y: int) -> None: 
    ...

Then we don't need to pass it in when constructing the objects and our tests don't need to pass None all the time.

jhanarato commented 1 year ago

Starting with layout.py:

Instead of calling draw() on every component, just yield the x/y coordinates via __iter__ or another function. Only height() and width() so perhaps draw() can be removed from ImageComponent.

jhanarato commented 1 year ago

Changing components, including Countdown does not look like it will cause any difficulties.

jhanarato commented 1 year ago

In compose.py we should replace the call to layout.draw() with a zip() of x/y and the component list we already have, then loop and call draw() on each component.

jhanarato commented 1 year ago

In our tests:

jhanarato commented 1 year ago

In order to work in baby steps, create a new method draw_xxx(), change everything over then rename back to draw(). Thanks Mr Fowler.

jhanarato commented 1 year ago

Done, and it wasn't hard.