simvx.core.nodes_2d.text¶
Text2D – screen-pinned text drawn through the one 2D text builder.
Module Contents¶
Classes¶
Screen-pinned text for HUD / UI. Works in both 2D and 3D modes. |
API¶
- class simvx.core.nodes_2d.text.Text2D(**kwargs)[source]¶
Bases:
simvx.core.nodes_2d.node2d.Node2DScreen-pinned text for HUD / UI. Works in both 2D and 3D modes.
Text2D draws through the ONE 2D text builder (
renderer.draw_text): the item path emits a native kerned MSDFGLYPHitem, and theDraw2D_draw_recursivewalk (editor play-mode / web) appends a matchingTEXTop – both from the same layout, so they render identically.The text is screen-pinned: it draws in screen space (
screen_space=True) so it stays fixed while a Camera2D pans the world – the usual HUD behaviour. It draws at its :attr:~Node2D.world_positionand at its- Attr:
~Node2D.world_scale, so a label parented under a moving, scaled node is carried and resized by that node; parented at the root (the common HUD case) world equals local,positionis the screen coordinate directly andfont_scaleis the only size input.
Sizing:
font_scaleis a multiplier on the 16px logical em (font_scale=1-> 16 logical px) and the node’s world scale multiplies on top of it, the same way a Sprite2D’s draw size is its texture size times its world scale. A world scale of 0 on either axis hides the label, as it hides a sprite.Three properties of the 2D text builder shape what an ancestor transform can do to the glyphs:
One glyph size, not two. A glyph run is laid out from a single scalar size, so a non-uniform world scale is reduced to the geometric mean
sqrt(|sx * sy|): exact for a uniform scale, area-preserving otherwise, and never silently favouring one axis. Arectbox keeps its per-axis extent (w * |sx|,h * |sy|) because a box can express both axes. A negative (mirrored) scale contributes its magnitude only; glyph runs are not mirrored.Axis-aligned runs. The builder emits upright glyph quads and takes no rotation, so a rotated ancestor moves the anchor (via
world_position) but leaves the text upright. Arectbox cannot follow the rotation either, so it is placed by its CENTRE: the authored centre lands exactly where the ancestor puts it and the upright extent is rebuilt around it, which is the closest an axis-aligned box can sit to the region meant.A readable-pixel floor the builder applies by default, clamping tiny text up to ~10px. A world-scaled label opts out of it, so the glyphs shrink in proportion with the box (and with
fit_to_width) instead of clamping and overflowing; an unscaled label keeps the floor. Scaling an ancestor far enough down therefore makes the text illegibly small, exactly as it makes a sprite unreadably small.
Common port patterns are first-class node Properties:
outline/outline_colour– a readable halo on any background.rect– position + align inside a box instead of at a point.fit_to_width– shrinkfont_scaleso the text fitsrectwidth.
Initialization
- text¶
‘Property(…)’
- font_scale¶
‘Property(…)’
- colour¶
‘Colour(…)’
- align¶
‘Property(…)’
- outline¶
‘Property(…)’
- outline_colour¶
‘Colour(…)’
- rect¶
‘Property(…)’
- fit_to_width¶
‘Property(…)’
- position¶
‘_SpatialVecProperty(…)’
- rotation¶
‘Property(…)’
- scale¶
‘_SpatialVecProperty(…)’
- z_index¶
‘Property(…)’
- z_as_relative¶
‘Property(…)’
- render_layer¶
‘Property(…)’
- set_render_layer(index: int, enabled: bool = True) None¶
- is_on_render_layer(index: int) bool¶
- property absolute_z_index: int¶
- property rotation_degrees: float¶
- property world_position: simvx.core.math.types.Vec2¶
- property world_rotation: float¶
- property world_scale: simvx.core.math.types.Vec2¶
- property world_transform: tuple[simvx.core.math.types.Vec2, simvx.core.math.types.Vec2, float]¶
- property forward: simvx.core.math.types.Vec2¶
- property right: simvx.core.math.types.Vec2¶
- translate(offset: tuple[float, float] | numpy.ndarray)¶
- rotate(radians: float)¶
- rotate_deg(degrees: float)¶
- look_at(target: tuple[float, float] | numpy.ndarray)¶
- transform_points(points: list[simvx.core.math.types.Vec2]) list[simvx.core.math.types.Vec2]¶
- draw_polygon(renderer, points: list[simvx.core.math.types.Vec2], closed=True, colour=None)¶
- wrap_screen(margin: float = 20)¶
- hdr¶
‘Property(…)’
- property transform_render_dirty: bool¶
- strict_errors: ClassVar[bool]¶
True
- dev_checks: ClassVar[bool]¶
None
- script_error_raised¶
‘Signal(…)’
- dynamic: bool¶
False
- visible¶
‘Property(…)’
- update_mode¶
‘Property(…)’
- __properties__: ClassVar[dict[str, simvx.core.descriptors.Property]]¶
None
- classmethod __init_subclass__(**kwargs)¶
- property name: str¶
- property visible_in_tree: bool¶
- reset_error() None¶
- add_child(node: simvx.core.node.T) simvx.core.node.T¶
- remove_child(node: simvx.core.node.Node) None¶
- reparent(new_parent: simvx.core.node.Node)¶
- node_at(path, default=_NO_DEFAULT)¶
- find(target, *, direct: bool = False)¶
- find_all(target, *, direct: bool = False)¶
- expect(target, *, direct: bool = False)¶
- ancestor(target)¶
- walk(*, include_self: bool = True) collections.abc.Iterator[simvx.core.node.Node]¶
- property path: str¶
- property is_scene_root: bool¶
- add_to_group(group: str)¶
- remove_from_group(group: str)¶
- is_in_group(group: str) bool¶
- on_ready() None¶
- on_enter_tree() None¶
- on_exit_tree() None¶
- on_update(dt: float) None¶
- on_fixed_update(dt: float) None¶
- on_picked(event: simvx.core.events.InputEvent) None¶
- on_unhandled_input(event: simvx.core.events.TreeInputEvent) None¶
- start_coroutine(gen: simvx.core.descriptors.Coroutine) simvx.core.descriptors.CoroutineHandle¶
- stop_coroutine(gen_or_handle)¶
- queue_redraw() None¶
- property render_dirty: bool¶
- clear_children()¶
- destroy()¶
- property destroying: bool¶
- call_deferred(method: collections.abc.Callable[..., Any], *args: Any) None¶
- property app¶
- property tree: simvx.core.scene_tree.SceneTree¶
- property physics¶
- property physics_2d¶
- __getitem__(key: str)¶
- classmethod get_properties() dict[str, simvx.core.descriptors.Property]¶
- __repr__()¶