v.0.4.6 screen_text param display

This commit is contained in:
tiijay
2025-10-25 13:25:28 +02:00
parent a1ac556a8e
commit b0081feda6
5 changed files with 25 additions and 16 deletions

View File

@@ -2,6 +2,6 @@ from .font_3x5 import font_3x5
from .font_5x7 import font_5x7
from .font_8x8 import font_8x8
from .font_16x16 import font_16x16
from .fonts_utils import *
from .fonts_utils import char_width
__all__ = ['font_3x5', 'font_5x7', 'font_8x8', 'font_16x16']
__all__ = ['font_3x5', 'font_5x7', 'font_8x8', 'font_16x16', 'char_width']

View File

@@ -1,5 +1,9 @@
import app.utils as utils
# FIXME: der Import klappt nicht !!!
# from app.display.neopixel_64x64 import NeoPixel_64x64
# from ...display.neopixel_64x64 import NeoPixel_64x64
def char_width(char_matrix) -> int:
"""Berechnung der Bits für die Zeichenbreite
@@ -85,7 +89,7 @@ def align_font(font, debug=False):
return f'#keys: {len(font)}'
def screen_text(text: str, font, screen_height: int, screen_width: int):
def screen_text(text: str, display: NeoPixel_64x64):
"""Text für einen Screen anpassen,
Anzahl der Zeichen je Zeile begrenzen,
ebenso wird die Höhe des Screen brücksichtigt
@@ -102,17 +106,16 @@ def screen_text(text: str, font, screen_height: int, screen_width: int):
pixs = 0
visible_text = ''
for a in txt:
pixs += char_width(font[a]) + 1
if pixs > screen_width:
pixs += char_width(display.selected_font[a]) + 1
if pixs > display.MATRIX_WIDTH:
# Zeilenende erreicht
break
visible_text += a
return visible_text
f_height: int = font_height(font)
# Ganzzahl Division
max_visible_rows = screen_height // f_height
max_visible_rows = display.MATRIX_HEIGHT // display.font_height
print(f'rows_visible: {max_visible_rows}')
text_left = text

View File

@@ -1,6 +1,6 @@
from machine import Pin, RTC
from neopixel import NeoPixel
from .fonts.fonts_utils import char_width as charwidth
from machine import Pin, RTC # type: ignore
from neopixel import NeoPixel # type: ignore
from .fonts import char_width as charwidth
from .fonts.font_5x7 import font_5x7
from ..utils.colors import GRAY, RAINBOW, BLACK, WHITE, LIME
@@ -104,7 +104,9 @@ class NeoPixel_64x64(NeoPixel):
[
# print(xpos, ypos)
self.set_pixel(xpos, ypos, GRAY)
for xpos in range(x, x + char_width) # 8 because full with of character representation
for xpos in range(
x, x + char_width
) # 8 because full with of character representation
for ypos in range(y, y + self.font_height)
]
@@ -149,7 +151,9 @@ class NeoPixel_64x64(NeoPixel):
self.write()
def vertical_floating_text(self, text, x, color=RAINBOW[0], float_range=3, speed=0.2, duration=10):
def vertical_floating_text(
self, text, x, color=RAINBOW[0], float_range=3, speed=0.2, duration=10
):
"""
Vertical floating text animation
@@ -180,7 +184,9 @@ class NeoPixel_64x64(NeoPixel):
self.write()
time.sleep(0.05)
def horizontal_floating_text(self, text, y, color=RAINBOW[0], float_range=3, speed=0.2, duration=10):
def horizontal_floating_text(
self, text, y, color=RAINBOW[0], float_range=3, speed=0.2, duration=10
):
"""
Horizontal floating text animation

View File

@@ -19,7 +19,7 @@ def fonts_check(display: NeoPixel_64x64, font, pretty=False) -> None:
text_left = alphanum
while text_left:
# Text entsprechend des Display splitten
scr_txt_dict = screen_text(text=text_left, screen_width=display.MATRIX_WIDTH, screen_height=display.MATRIX_HEIGHT, font=font)
scr_txt_dict = screen_text(text=text_left, display=display)
print(f'scr_txt: {scr_txt_dict}')
display.clear()

View File

@@ -1,4 +1,4 @@
# from machine import Pin, ADC # type: ignore
from machine import Pin, ADC # type: ignore
from app.display.neopixel_64x64 import NeoPixel_64x64
import app.display.fonts as fonts
import app.utils as utils
@@ -8,6 +8,6 @@ if __name__ == '__main__':
display = NeoPixel_64x64()
# tryout.emojis_check(display)
# tryout.fonts_check(display, fonts.font_8x8, pretty=False)
tryout.fonts_check(display, fonts.font_8x8, pretty=False)
tryout.weather_check(display, test_mode=False)
utils.show_system_load()