From 2156b2f2fb7710b6310204eccd21cae4839f8da4 Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Wed, 1 Jan 2025 22:16:55 -0500 Subject: [PATCH] Added layer of 'translation' values for horisontal cross-axis in RTL --- core/pyproject.toml | 2 +- core/src/toga/style/pack.py | 34 +++++++++++++++++++++------------- tox.ini | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/core/pyproject.toml b/core/pyproject.toml index f0bba62dcd..322f2e4a70 100644 --- a/core/pyproject.toml +++ b/core/pyproject.toml @@ -56,7 +56,7 @@ classifiers = [ "Topic :: Software Development :: Widget Sets", ] dependencies = [ - "travertino >= 0.3.0, < 0.4.0", + "travertino", ] [project.optional-dependencies] diff --git a/core/src/toga/style/pack.py b/core/src/toga/style/pack.py index 65ae1ffa32..eafeed4e37 100644 --- a/core/src/toga/style/pack.py +++ b/core/src/toga/style/pack.py @@ -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}"] ) @@ -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: diff --git a/tox.ini b/tox.ini index 847c4a8107..e51a26763f 100644 --- a/tox.ini +++ b/tox.ini @@ -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}