Skip to content

Commit

Permalink
Added layer of 'translation' values for horisontal cross-axis in RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
HalfWhitt committed Jan 2, 2025
1 parent 422ac12 commit 2156b2f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ classifiers = [
"Topic :: Software Development :: Widget Sets",
]
dependencies = [
"travertino >= 0.3.0, < 0.4.0",
"travertino",
]

[project.optional-dependencies]
Expand Down
34 changes: 21 additions & 13 deletions core/src/toga/style/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,31 +803,39 @@ def _layout_children(

# Pass 4: Set cross-axis position of each child.

# Translate RTL into left-origin, which effectively flips start/end item
# alignment.
align_items = self.align_items
# The "effective" start, end, and align-items values are normally their "real"
# values. However, if the cross-axis is horizontal and text-direction RTL,
# they're flipped. This is necessary because final positioning is always set
# using a top-left origin, even if the "real" start is on the right.
effective_align_items = self.align_items

if cross_start == RIGHT:
cross_start = LEFT
effective_cross_start = LEFT
effective_cross_end = RIGHT

if self.align_items == START:
effective_align_items = END
elif self.align_items == END:
effective_align_items = START

if align_items == START:
align_items = END
elif align_items == END:
align_items = START
else:
effective_cross_start = cross_start
effective_cross_end = cross_end

for child in node.children:
# self._debug(f"PASS 4: {child}")
extra = cross - (
getattr(child.layout, f"content_{cross_name}")
+ child.style[f"margin_{cross_start}"]
+ child.style[f"margin_{cross_end}"]
+ child.style[f"margin_{effective_cross_start}"]
+ child.style[f"margin_{effective_cross_end}"]
)
# self._debug(f"- {self.direction} extra {cross_name} {extra}")

if align_items == END:
if effective_align_items == END:
cross_start_value = extra + child.style[f"margin_{cross_start}"]
# self._debug(f" align {child} to {cross_end}")

elif align_items == CENTER:
elif effective_align_items == CENTER:
cross_start_value = (
int(extra / 2) + child.style[f"margin_{cross_start}"]
)
Expand All @@ -837,7 +845,7 @@ def _layout_children(
cross_start_value = child.style[f"margin_{cross_start}"]
# self._debug(f" align {child} to {cross_start} ")

setattr(child.layout, f"content_{cross_start}", cross_start_value)
setattr(child.layout, f"content_{effective_cross_start}", cross_start_value)
# self._debug(f" {getattr(child.layout, f'content_{cross_start}')=}")

if self.direction == COLUMN:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ allowlist_externals =
commands =
# TOGA_INSTALL_COMMAND is set to a bash command by the CI workflow
# Install as editable so parallel runs don't clobber the build directory for each other
{env:TOGA_INSTALL_COMMAND:python -m pip install {tox_root}{/}core[dev] {tox_root}{/}dummy}
{env:TOGA_INSTALL_COMMAND:python -m pip install {tox_root}{/}core[dev] {tox_root}{/}dummy} {/}Users{/}charles{/}toga_dev{/}travertino
!cov: python -m pytest {posargs:-vv --color yes}
cov : python -m coverage run -m pytest {posargs:-vv --color yes}

Expand Down

0 comments on commit 2156b2f

Please sign in to comment.