Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make transform origin respect Text alignment #110

Merged
merged 3 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions neoscore/core/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@ def bounding_rect(self) -> Rect:
"""The bounding rect for this text positioned relative to ``pos``.

The rect ``(x, y)`` position is relative to the object's position.
Note that with text objects, the rect's ``(x, y)`` position will
typically not be at the origin.

Note that this currently accounts for scaling, but not rotation.
This currently accounts for scaling and alignment, but not rotation.
Rotated objects will generally have incorrect bounding rects.
"""
raw_rect = self._raw_scaled_bounding_rect
alignment_offset = self._alignment_offset
Expand Down Expand Up @@ -206,7 +209,7 @@ def _render_slice(
None if inside_flowable else self.parent.interface_for_children,
self.scale,
self.rotation,
self.transform_origin,
self.transform_origin - self._alignment_offset,
self.brush.interface,
self.pen.interface,
self.text,
Expand Down
7 changes: 7 additions & 0 deletions tests/test_core/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,14 @@ def test_rendered_interface_with_offset(self):
"testing",
alignment_x=AlignmentX.CENTER,
alignment_y=AlignmentY.CENTER,
transform_origin=(Unit(15), Unit(10)),
)
obj.render()
rendered_pos = obj.interfaces[0].pos
transform_origin = obj.interfaces[0].transform_origin
assert_almost_equal(rendered_pos, Point(Unit(-20), Unit(2.5)), epsilon=1.5)
assert_almost_equal(
transform_origin,
Point(Unit(35), Unit(7.5)),
epsilon=1.5,
)
Loading