mini-arcade-native-backend 0.4.3__cp39-cp39-win_amd64.whl → 0.4.5__cp39-cp39-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -80,6 +80,33 @@ class NativeBackend(Backend):
80
80
  self._font_path = font_path
81
81
  self._font_size = font_size
82
82
  self._default_font_id: int | None = None
83
+ self._fonts_by_size: dict[int, int] = {}
84
+
85
+ def _get_font_id(self, font_size: int | None) -> int:
86
+ # No font loaded -> keep current “no-op” behavior
87
+ if self._font_path is None:
88
+ return -1
89
+
90
+ # Default font
91
+ if font_size is None:
92
+ return (
93
+ self._default_font_id
94
+ if self._default_font_id is not None
95
+ else -1
96
+ )
97
+
98
+ if font_size <= 0:
99
+ raise ValueError(f"font_size must be > 0, got {font_size}")
100
+
101
+ # Cached
102
+ cached = self._fonts_by_size.get(font_size)
103
+ if cached is not None:
104
+ return cached
105
+
106
+ # Lazily load and cache
107
+ font_id = self._engine.load_font(self._font_path, int(font_size))
108
+ self._fonts_by_size[font_size] = font_id
109
+ return font_id
83
110
 
84
111
  def init(self, width: int, height: int, title: str):
85
112
  """
@@ -101,6 +128,7 @@ class NativeBackend(Backend):
101
128
  self._default_font_id = self._engine.load_font(
102
129
  self._font_path, self._font_size
103
130
  )
131
+ self._fonts_by_size[self._font_size] = self._default_font_id
104
132
 
105
133
  def set_clear_color(self, r: int, g: int, b: int):
106
134
  """
@@ -277,14 +305,13 @@ class NativeBackend(Backend):
277
305
  r, g, b, a = self._get_color_values(color)
278
306
  self._engine.draw_rect(x, y, w, h, r, g, b, a)
279
307
 
280
- # pylint: enable=too-many-arguments,too-many-positional-arguments
281
-
282
308
  def draw_text(
283
309
  self,
284
310
  x: int,
285
311
  y: int,
286
312
  text: str,
287
313
  color: tuple[int, int, int] = (255, 255, 255),
314
+ font_size: int | None = None,
288
315
  ):
289
316
  """
290
317
  Draw text at the given position using the loaded font.
@@ -303,13 +330,13 @@ class NativeBackend(Backend):
303
330
  :type color: tuple[int, int, int]
304
331
  """
305
332
  r, g, b, a = self._get_color_values(color)
306
- font_id = (
307
- self._default_font_id if self._default_font_id is not None else -1
308
- )
333
+ font_id = self._get_font_id(font_size)
309
334
  self._engine.draw_text(
310
335
  text, x, y, int(r), int(g), int(b), int(a), font_id
311
336
  )
312
337
 
338
+ # pylint: enable=too-many-arguments,too-many-positional-arguments
339
+
313
340
  def capture_frame(self, path: str | None = None) -> bool:
314
341
  """
315
342
  Capture the current frame.
@@ -324,3 +351,15 @@ class NativeBackend(Backend):
324
351
  if path is None:
325
352
  raise ValueError("Path must be provided to capture frame.")
326
353
  return self._engine.capture_frame(path)
354
+
355
+ def measure_text(
356
+ self, text: str, font_size: int | None = None
357
+ ) -> tuple[int, int]:
358
+ """
359
+ Measure text size (width, height) in pixels for the active font.
360
+
361
+ Returns (0,0) if no font is loaded (matches draw_text no-op behavior).
362
+ """
363
+ font_id = self._get_font_id(font_size)
364
+ w, h = self._engine.measure_text(text, font_id)
365
+ return int(w), int(h)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mini-arcade-native-backend
3
- Version: 0.4.3
3
+ Version: 0.4.5
4
4
  Summary: Native SDL2 backend for mini-arcade-core using SDL2 + pybind11.
5
5
  Author-Email: Santiago Rincon <rincores@gmail.com>
6
6
  License: Copyright (c) 2025 Santiago Rincón
@@ -0,0 +1,6 @@
1
+ mini_arcade_native_backend/__init__.py,sha256=CeWzMbCkL2W4TFCqWtxBixiF5G2rurklJNtc_gSCaSw,11997
2
+ mini_arcade_native_backend/_native.cp39-win_amd64.pyd,sha256=xFYfXul88i2rNXEworptnITNVQDO151AhDZOp5o7S9s,225280
3
+ mini_arcade_native_backend-0.4.5.dist-info/METADATA,sha256=tQXwTCO3E-bfFCLD66R-GR0_WXm-d6PHvkYoRa7AC2c,10517
4
+ mini_arcade_native_backend-0.4.5.dist-info/WHEEL,sha256=9tsL4JT94eZPTkcS3bNng2riasYJMxXndrO9CxUfJHs,104
5
+ mini_arcade_native_backend-0.4.5.dist-info/licenses/LICENSE,sha256=cZRgTdRJ3YASekMxkGAvylB2nROh4ov228DxAogK3yY,1115
6
+ mini_arcade_native_backend-0.4.5.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- mini_arcade_native_backend/__init__.py,sha256=WqN_5T1kSebFrH3JXrx1JjXO0xxRNOA_kHZjddpfuEs,10658
2
- mini_arcade_native_backend/_native.cp39-win_amd64.pyd,sha256=m9LXOZrgpDC03hIaNd6HnhJT3bi-plsiOfGB0FE4Xy0,222720
3
- mini_arcade_native_backend-0.4.3.dist-info/METADATA,sha256=QyzQk63DFSOd3Bf1HVqVJHx40JnJFB1OlYIxsL9y2PA,10517
4
- mini_arcade_native_backend-0.4.3.dist-info/WHEEL,sha256=9tsL4JT94eZPTkcS3bNng2riasYJMxXndrO9CxUfJHs,104
5
- mini_arcade_native_backend-0.4.3.dist-info/licenses/LICENSE,sha256=cZRgTdRJ3YASekMxkGAvylB2nROh4ov228DxAogK3yY,1115
6
- mini_arcade_native_backend-0.4.3.dist-info/RECORD,,