Skip to content

Commit 8c688b3

Browse files
committed
add font property and font default
1 parent 2fe8fa1 commit 8c688b3

File tree

1 file changed

+30
-12
lines changed
  • src/MicroPython/picoware/gui

1 file changed

+30
-12
lines changed

src/MicroPython/picoware/gui/draw.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def __init__(
6868
self._foreground = foreground
6969

7070
self._size = Vector(0, 0)
71-
default_font = FontSize(FONT_DEFAULT)
72-
self._font_size = Vector(default_font.width, default_font.height)
71+
self._font_default = FontSize(FONT_DEFAULT)
72+
self._font_size = Vector(self._font_default.width, self._font_default.height)
7373

7474
self._use_lvgl = False
7575

@@ -115,6 +115,22 @@ def board_id(self) -> int:
115115
"""Get the current board ID"""
116116
return self._current_board_id
117117

118+
@property
119+
def font(self) -> int:
120+
"""Get the default font size"""
121+
return self._font_default.size
122+
123+
@font.setter
124+
def font(self, font_size: int):
125+
"""Set the default font size"""
126+
from picoware.system.font import FontSize
127+
128+
self._font_default = FontSize(font_size)
129+
self._font_size.x, self._font_size.y = (
130+
self._font_default.width,
131+
self._font_default.height,
132+
)
133+
118134
@property
119135
def font_size(self) -> Vector:
120136
"""Get the font size"""
@@ -167,10 +183,11 @@ def __del__(self):
167183
):
168184
deinit()
169185

170-
def char(self, position: Vector, char: str, color=None, font_size: int = 0):
186+
def char(self, position: Vector, char: str, color=None, font_size: int = -1):
171187
"""Draw a single character on the display"""
172188
_color = color if color is not None else self._foreground
173-
draw_char(position.x, position.y, ord(char), _color, font_size)
189+
_font_size = font_size if font_size >= 0 else self._font_default.size
190+
draw_char(position.x, position.y, ord(char), _color, _font_size)
174191

175192
def circle(self, position: Vector, radius: int, color: int = None):
176193
"""Draw a circle outline"""
@@ -533,12 +550,6 @@ def reset(self):
533550
"""Reset the display by clearing the framebuffer"""
534551
self.fill_screen(self._background)
535552

536-
def swap(self):
537-
"""
538-
Swap the front and back buffers - convert 8-bit framebuffer to display
539-
"""
540-
swap()
541-
542553
def set_mode(self, mode: int) -> None:
543554
"""
544555
Set the LCD framebuffer mode
@@ -554,10 +565,17 @@ def set_mode(self, mode: int) -> None:
554565
# MODE_PSRAM = 0, MODE_HEAP = 1
555566
set_mode(mode)
556567

557-
def text(self, position: Vector, text: str, color=None, font_size: int = 0):
568+
def swap(self):
569+
"""
570+
Swap the front and back buffers - convert 8-bit framebuffer to display
571+
"""
572+
swap()
573+
574+
def text(self, position: Vector, text: str, color=None, font_size: int = -1):
558575
"""Draw text on the display"""
559576
_color = color if color is not None else self._foreground
560-
draw_text(position.x, position.y, text, _color, font_size)
577+
_font_size = font_size if font_size >= 0 else self._font_default.size
578+
draw_text(position.x, position.y, text, _color, _font_size)
561579

562580
def triangle(self, point1: Vector, point2: Vector, point3: Vector, color=None):
563581
"""Draw a triangle outline"""

0 commit comments

Comments
 (0)