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

[widget audit] toga.Label #1799

Merged
merged 24 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bb522f4
Update tests for label.
freakboy3742 Mar 1, 2023
7ff8548
Add Android text alignment probe, and support for text justification.
freakboy3742 Mar 1, 2023
4363a98
Correct label implementation on iOS.
freakboy3742 Mar 1, 2023
af06298
Migrate label tests to pytest.
freakboy3742 Mar 1, 2023
71b523c
Update documentation for Label.
freakboy3742 Mar 1, 2023
35f3f6c
Add changenote for label bugfix.
freakboy3742 Mar 1, 2023
0a83350
Add changenote for Label audit.
freakboy3742 Mar 1, 2023
4238cb6
Add GTK alignment probe.
freakboy3742 Mar 1, 2023
d0b3da0
Update widget support chart.
freakboy3742 Mar 1, 2023
2550362
Merge branch 'audit-button' into audit-label
freakboy3742 Mar 20, 2023
4476d98
Merge branch 'audit-button' into audit-label
freakboy3742 Mar 21, 2023
1d5f74e
Merge branch 'main' into audit-label
mhsmith Mar 21, 2023
4691de8
Tighten up Android alignment tests
mhsmith Mar 21, 2023
1b70eee
Remove change note for issue which may not be completely fixed yet
mhsmith Mar 21, 2023
cdedf68
Remove unnecessary skips in base probes
mhsmith Mar 21, 2023
0f798cc
iOS: round up size in Label.rehint to prevent lines being omitted
mhsmith Mar 21, 2023
025259d
Add empty label height test
mhsmith Mar 21, 2023
f2fb171
Remove the use of shadow handling in label.
freakboy3742 Mar 22, 2023
28d3704
Add test resilience against changes in text length.
freakboy3742 Mar 22, 2023
572b07b
Correct handling of empty labels on iOS.
freakboy3742 Mar 22, 2023
7864c97
Correct the Pango negative size warning.
freakboy3742 Mar 22, 2023
2ffd585
Correct probe/API handling of ZWS.
freakboy3742 Mar 22, 2023
879f63e
Remove a redundant documentation note.
freakboy3742 Mar 22, 2023
15c3515
Relax width and height constraint during iOS rehinting to avoid word …
freakboy3742 Mar 22, 2023
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
3 changes: 1 addition & 2 deletions android/src/toga_android/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def set_alignment(self, value):
# Justified text wasn't added until Android O (SDK 26)
if value == JUSTIFY and Build.VERSION.SDK_INT >= Build.VERSION_CODES.O:
self.native.setJustificationMode(LineBreaker.JUSTIFICATION_MODE_INTER_WORD)
self.native.setGravity(Gravity.CENTER_VERTICAL)
else:
self.native.setJustificationMode(LineBreaker.JUSTIFICATION_MODE_NONE)
self.native.setGravity(Gravity.CENTER_VERTICAL | align(value))
self.native.setGravity(Gravity.CENTER_VERTICAL | align(value))
Copy link
Member

@mhsmith mhsmith Mar 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the previous code, I wasn't sure whether setting a label to centered and then to justified would give you a result with short lines still centered. Turns out it doesn't, because the native widget's horizontal gravity defaults to LEFT if unspecified, but this isn't clearly documented, so it's better to be explicit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow what you're saying here. Isn't this setting horizontal gravity every time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is now, but previously it was leaving the horizontal gravity unspecified when value == JUSTIFY.

4 changes: 2 additions & 2 deletions android/tests_backend/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def assert_container(self, container):
else:
raise AssertionError(f"cannot find {self.native} in {container_native}")

def assert_alignment_equivalent(self, actual, expected):
assert actual == expected
def assert_alignment(self, expected):
assert self.alignment == expected

def assert_font_family(self, expected):
actual = self.font.family
Expand Down
21 changes: 14 additions & 7 deletions android/tests_backend/widgets/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,18 @@ def toga_font(typeface, size, resources):
)


def toga_alignment(alignment, justification_mode):
if justification_mode == LineBreaker.JUSTIFICATION_MODE_INTER_WORD:
def toga_alignment(gravity, justification_mode):
horizontal_gravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK
if (
justification_mode == LineBreaker.JUSTIFICATION_MODE_INTER_WORD
and horizontal_gravity == Gravity.LEFT
):
return JUSTIFY
return {
Gravity.LEFT: LEFT,
Gravity.RIGHT: RIGHT,
Gravity.CENTER_HORIZONTAL: CENTER,
}[alignment & Gravity.HORIZONTAL_GRAVITY_MASK]
elif justification_mode == LineBreaker.JUSTIFICATION_MODE_NONE:
return {
Gravity.LEFT: LEFT,
Gravity.RIGHT: RIGHT,
Gravity.CENTER_HORIZONTAL: CENTER,
}[horizontal_gravity]
else:
raise ValueError(f"unknown combination: {gravity=}, {justification_mode=}")
4 changes: 2 additions & 2 deletions cocoa/tests_backend/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def assert_container(self, container):
else:
raise ValueError(f"cannot find {self.native} in {container_native}")

def assert_alignment_equivalent(self, actual, expected):
assert actual == expected
def assert_alignment(self, expected):
assert self.alignment == expected

def assert_font_family(self, expected):
assert self.font.family == {
Expand Down
4 changes: 2 additions & 2 deletions gtk/tests_backend/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def assert_container(self, container):
else:
raise ValueError(f"cannot find {self.native} in {container_native}")

def assert_alignment_equivalent(self, actual, expected):
assert actual == expected
def assert_alignment(self, expected):
assert self.alignment == expected

def assert_font_family(self, expected):
assert self.font.family == expected
Expand Down
4 changes: 2 additions & 2 deletions iOS/tests_backend/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def assert_container(self, container):
else:
raise ValueError(f"cannot find {self.native} in {container_native}")

def assert_alignment_equivalent(self, actual, expected):
assert actual == expected
def assert_alignment(self, expected):
assert self.alignment == expected

def assert_font_family(self, expected):
assert self.font.family == {
Expand Down
10 changes: 5 additions & 5 deletions testbed/tests/widgets/test_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,24 @@ async def test_alignment(widget, probe):
# Initial alignment is LEFT, initial direction is LTR
widget.parent.style.direction = COLUMN
await probe.redraw()
assert probe.alignment == LEFT
probe.assert_alignment(LEFT)

for alignment in [RIGHT, CENTER, JUSTIFY]:
widget.style.text_align = alignment
await probe.redraw()
probe.assert_alignment_equivalent(probe.alignment, alignment)
probe.assert_alignment(alignment)

# Clearing the alignment reverts to default alignment of LEFT
del widget.style.text_align
await probe.redraw()
assert probe.alignment == LEFT
probe.assert_alignment(LEFT)

# If text direction is RTL, default alignment is RIGHT
widget.style.text_direction = RTL
await probe.redraw()
assert probe.alignment == RIGHT
probe.assert_alignment(RIGHT)

# If text direction is expliclty LTR, default alignment is LEFT
widget.style.text_direction = LTR
await probe.redraw()
assert probe.alignment == LEFT
probe.assert_alignment(LEFT)
3 changes: 2 additions & 1 deletion winforms/tests_backend/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def assert_container(self, container):
else:
raise ValueError(f"cannot find {self.native} in {container_native}")

def assert_alignment_equivalent(self, actual, expected):
def assert_alignment(self, expected):
# Winforms doesn't have a "Justified" alignment; it falls back to LEFT
actual = self.alignment
if expected == JUSTIFY:
assert actual == LEFT
else:
Expand Down