diff --git a/adafruit_displayio_layout/widgets/__init__.py b/adafruit_displayio_layout/widgets/__init__.py index cbc4f01..d56d8b0 100644 --- a/adafruit_displayio_layout/widgets/__init__.py +++ b/adafruit_displayio_layout/widgets/__init__.py @@ -1,67 +1,3 @@ # SPDX-FileCopyrightText: 2021 Kevin Matocha, Tim C, Jose David M # # SPDX-License-Identifier: MIT - -""" -`adafruit_displayio_layout.widgets` -======================= -""" - -try: - import vectorio -except ImportError: - pass - -try: - import bitmaptools -except ImportError: - pass - - -# pylint: disable=invalid-name, too-many-arguments -def rectangle_helper( - x0: int, - y0: int, - height: int, - width: int, - bitmap, - color_index: int, - palette, - bitmaptool: bool = True, -) -> None: - """rectangle_helper function - Draws a rectangle to the bitmap given using ``bitmapstools.bitmap`` or - ``vectorio.rectangle`` functions - - :param int x0: rectangle lower corner x position - :param int y0: rectangle lower corner y position - - :param int width: rectangle upper corner x position - :param int height: rectangle upper corner y position - - :param int color_index: palette color index to be used - :param palette: palette object to be used to draw the rectangle - - :param bitmap: bitmap for the rectangle to be drawn - :param bool bitmaptool: uses :py:func:`~bitmaptools.draw_line` to draw the rectanlge. - when `False` uses :py:func:`~vectorio.Rectangle` - - :return: None - :rtype: None - - ┌───────────────────────┐ - │ │ - │ │ - (x0,y0) └───────────────────────┘ - - """ - if bitmaptool: - bitmaptools.fill_region(bitmap, x0, y0, x0 + width, y0 + height, color_index) - else: - rect = vectorio.Rectangle(width, height) - vectorio.VectorShape( - shape=rect, - pixel_shader=palette, - x=x0, - y=y0, - ) diff --git a/adafruit_displayio_layout/widgets/cartesian.py b/adafruit_displayio_layout/widgets/cartesian.py index 617f7a3..66790a4 100644 --- a/adafruit_displayio_layout/widgets/cartesian.py +++ b/adafruit_displayio_layout/widgets/cartesian.py @@ -29,7 +29,6 @@ from adafruit_display_text import bitmap_label import vectorio from adafruit_displayio_layout.widgets.widget import Widget -from adafruit_displayio_layout.widgets import rectangle_helper try: import bitmaptools @@ -138,7 +137,7 @@ class Cartesian(Widget): - **range**: ``xrange`` and ``yrange`` This is the range in absolute units. For example, when using (20-90), the X axis will start at 20 finishing at 90. - However the height of the graph is given by the height parameter. The scale + However, the height of the graph is given by the height parameter. The scale is handled internal to provide a 1:1 experience when you update the graph. @@ -269,14 +268,14 @@ def __init__( self._screen_palette[5] = self._background_color self._corner_bitmap = displayio.Bitmap(10, 10, 5) - rectangle_helper( + + bitmaptools.fill_region( + self._corner_bitmap, 0, 0, self._axes_line_thickness, self._axes_line_thickness, - self._corner_bitmap, 2, - self._screen_palette, ) self._corner_tilegrid = displayio.TileGrid( @@ -336,28 +335,23 @@ def _get_font_height(font, scale: int) -> Tuple[int, int]: return font_width, font_height def _draw_axes(self) -> None: - # Draw x axes line - rectangle_helper( + + bitmaptools.fill_region( + self._axesx_bitmap, 0, 0, - self._axes_line_thickness, self.width, - self._axesx_bitmap, + self._axes_line_thickness, 2, - self._screen_palette, - True, ) - # Draw y axes line - rectangle_helper( + bitmaptools.fill_region( + self._axesy_bitmap, self._axesy_width - self._axes_line_thickness, 0, + self._axesy_width, self.height, - self._axes_line_thickness, - self._axesy_bitmap, 2, - self._screen_palette, - True, ) def _draw_ticks(self) -> None: @@ -382,30 +376,28 @@ def _draw_ticks(self) -> None: + 1, ) self.append(tick_text) - rectangle_helper( + + bitmaptools.fill_region( + self._axesx_bitmap, text_dist, self._axes_line_thickness, - self._tick_line_height, - self._tick_line_thickness, - self._axesx_bitmap, + text_dist + self._tick_line_thickness, + self._axes_line_thickness + self._tick_line_height, 1, - self._screen_palette, - True, ) if self._subticks: if i in subticks: # calc subtick_line_height; force min lineheigt to 1. subtick_line_height = max(1, self._tick_line_height // 2) - rectangle_helper( + + bitmaptools.fill_region( + self._axesx_bitmap, text_dist, self._axes_line_thickness, - subtick_line_height, + text_dist + 1, + self._axes_line_thickness + subtick_line_height, 1, - self._axesx_bitmap, - 1, - self._screen_palette, - True, ) # Y axes ticks @@ -425,34 +417,32 @@ def _draw_ticks(self) -> None: y=0 + self.height - text_dist, ) self.append(tick_text) - rectangle_helper( + + bitmaptools.fill_region( + self._axesy_bitmap, self._axesy_width - self._axes_line_thickness - self._tick_line_height - 1, text_dist, - self._tick_line_thickness, - self._tick_line_height, - self._axesy_bitmap, + self._axesy_width - self._axes_line_thickness - 1, + text_dist + self._tick_line_thickness, 1, - self._screen_palette, - True, ) if self._subticks: if i in subticks: - rectangle_helper( + + bitmaptools.fill_region( + self._axesy_bitmap, self._axesy_width - self._axes_line_thickness - self._tick_line_height // 2 - 1, text_dist, + self._axesy_width - self._axes_line_thickness - 1, + text_dist + 1, 1, - self._tick_line_height // 2, - self._axesy_bitmap, - 1, - self._screen_palette, - True, ) def _draw_pointers(self, x: int, y: int) -> None: