28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
from collections import defaultdict
|
|
|
|
from engine.render.ui_draw import draw_panel, draw_text, glyph_texture_path, panel_texture_path, text_width
|
|
|
|
|
|
def test_glyph_texture_path_uses_char_code():
|
|
assert glyph_texture_path("A") == f"ui/font/{ord('A')}.png"
|
|
|
|
|
|
def test_glyph_texture_path_falls_back_for_non_printable_chars():
|
|
assert glyph_texture_path("\n") == glyph_texture_path("?")
|
|
|
|
|
|
def test_draw_text_skips_spaces_but_still_advances():
|
|
buckets: dict[str, list[float]] = defaultdict(list)
|
|
width = draw_text(buckets, "a b", x=0, y=0, char_advance=10)
|
|
a_path, b_path = glyph_texture_path("a"), glyph_texture_path("b")
|
|
assert buckets[a_path] == [0, 0, 16.0, 16.0]
|
|
assert buckets[b_path] == [20, 0, 16.0, 16.0] # index 2 * advance 10
|
|
assert " " not in "".join(buckets.keys())
|
|
assert width == text_width("a b", 10)
|
|
|
|
|
|
def test_draw_panel_emits_one_instance():
|
|
buckets: dict[str, list[float]] = defaultdict(list)
|
|
draw_panel(buckets, "background", 5, 6, 100, 40)
|
|
assert buckets[panel_texture_path("background")] == [5, 6, 100, 40]
|