Skip to content

Commit

Permalink
Merge pull request #3033 from HalfWhitt/align_properties_with_css
Browse files Browse the repository at this point in the history
Updated Pack property names to match CSS
  • Loading branch information
mhsmith authored Dec 15, 2024
2 parents e9f5760 + 53112c6 commit eec2395
Show file tree
Hide file tree
Showing 137 changed files with 893 additions and 690 deletions.
4 changes: 2 additions & 2 deletions android/src/toga_android/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def set_background_filter(self, value):
else PorterDuffColorFilter(native_color(value), PorterDuff.Mode.SRC_IN)
)

def set_alignment(self, alignment):
def set_text_align(self, alignment):
pass # If appropriate, a widget subclass will implement this.

def set_color(self, color):
Expand Down Expand Up @@ -190,7 +190,7 @@ def rehint(self):
pass


def align(value):
def android_text_align(value):
"""Convert toga alignment values into Android alignment values."""
return {
LEFT: Gravity.LEFT,
Expand Down
6 changes: 3 additions & 3 deletions android/src/toga_android/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from toga.constants import JUSTIFY
from toga_android.colors import native_color

from .base import Widget, align
from .base import Widget, android_text_align


def set_textview_font(tv, font, default_typeface, default_size):
Expand Down Expand Up @@ -51,7 +51,7 @@ def set_textview_alignment(self, value, vertical_gravity):
else Layout.JUSTIFICATION_MODE_NONE
)

self.native.setGravity(vertical_gravity | align(value))
self.native.setGravity(vertical_gravity | android_text_align(value))


class Label(TextViewWidget):
Expand Down Expand Up @@ -80,5 +80,5 @@ def rehint(self):
at_least(self.native.getMeasuredWidth()), ROUND_UP
)

def set_alignment(self, value):
def set_text_align(self, value):
self.set_textview_alignment(value, Gravity.TOP)
2 changes: 1 addition & 1 deletion android/src/toga_android/widgets/multilinetextinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _on_gain_focus(self):
def _on_lose_focus(self):
pass # The interface doesn't support this event.

def set_alignment(self, value):
def set_text_align(self, value):
self.set_textview_alignment(value, Gravity.TOP)

# This method is necessary to override the TextInput base class.
Expand Down
2 changes: 1 addition & 1 deletion android/src/toga_android/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def get_placeholder(self):
def set_placeholder(self, value):
self.native.setHint(value)

def set_alignment(self, value):
def set_text_align(self, value):
self.set_textview_alignment(value, Gravity.CENTER_VERTICAL)

def set_error(self, error_message):
Expand Down
6 changes: 3 additions & 3 deletions android/tests_backend/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ def assert_not_contained(self):
assert self.widget._impl.container is None
assert self.native.getParent() is None

def assert_alignment(self, expected):
actual = self.alignment
def assert_text_align(self, expected):
actual = self.text_align
if expected == JUSTIFY and (
Build.VERSION.SDK_INT < 26 or not self.supports_justify
):
assert actual == LEFT
else:
assert actual == expected

def assert_vertical_alignment(self, expected):
def assert_vertical_text_align(self, expected):
assert toga_vertical_alignment(self.native.getGravity()) == expected

@property
Expand Down
6 changes: 3 additions & 3 deletions android/tests_backend/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from java import jclass

from .base import SimpleProbe
from .properties import toga_alignment, toga_color
from .properties import toga_color, toga_text_align


class LabelProbe(SimpleProbe):
Expand All @@ -26,8 +26,8 @@ def text_size(self):
return self.native.getTextSize()

@property
def alignment(self):
def text_align(self):
justification_mode = (
None if Build.VERSION.SDK_INT < 26 else self.native.getJustificationMode()
)
return toga_alignment(self.native.getGravity(), justification_mode)
return toga_text_align(self.native.getGravity(), justification_mode)
2 changes: 1 addition & 1 deletion android/tests_backend/widgets/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def toga_color(color_int):
)


def toga_alignment(gravity, justification_mode=None):
def toga_text_align(gravity, justification_mode=None):
horizontal_gravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK
if (Build.VERSION.SDK_INT < 26) or (
justification_mode in (None, Layout.JUSTIFICATION_MODE_NONE)
Expand Down
4 changes: 2 additions & 2 deletions android/tests_backend/widgets/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def assert_resizes_on_content_change(self):
xfail("Selection doesn't resize on content changes on this backend")

@property
def alignment(self):
xfail("Can't change the alignment of Selection on this backend")
def text_align(self):
xfail("Can't change the text alignment of Selection on this backend")

@property
def color(self):
Expand Down
1 change: 1 addition & 0 deletions changes/3033.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pack's ``padding`` and ``alignment`` properties have been renamed to ``margin`` and ``align_items``, to match their CSS analogues. ``align_items`` also now takes CSS-compatible values of ``START``, ``CENTER``, and ``END``, instead of ``alignment``'s' ``TOP``/``RIGHT``/``BOTTOM``/``LEFT``/``CENTER``. The old names are still present — and ``alignment`` still takes its existing values — but these are deprecated.
2 changes: 1 addition & 1 deletion cocoa/src/toga_cocoa/hardware/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def create_preview_window(self):
style=Pack(flex=1),
),
],
style=Pack(padding=10),
style=Pack(margin=10),
),
],
style=Pack(direction=COLUMN),
Expand Down
2 changes: 1 addition & 1 deletion cocoa/src/toga_cocoa/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def set_bounds(self, x, y, width, height):
# print(f"SET BOUNDS ON {self.interface} {width}x{height} @ ({x},{y})")
self.constraints.update(x, y, width, height)

def set_alignment(self, alignment):
def set_text_align(self, alignment):
pass

def set_hidden(self, hidden):
Expand Down
2 changes: 1 addition & 1 deletion cocoa/src/toga_cocoa/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create(self):
# Add the layout constraints
self.add_constraints()

def set_alignment(self, value):
def set_text_align(self, value):
self.native.alignment = NSTextAlignment(value)

def set_color(self, value):
Expand Down
2 changes: 1 addition & 1 deletion cocoa/src/toga_cocoa/widgets/multilinetextinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def set_background_color(self, color):
self.native_text.drawsBackground = True
self.native_text.backgroundColor = native_color(color)

def set_alignment(self, value):
def set_text_align(self, value):
self.native_text.alignment = NSTextAlignment(value)

def set_font(self, font):
Expand Down
2 changes: 1 addition & 1 deletion cocoa/src/toga_cocoa/widgets/numberinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def set_max_value(self, value):
else:
self.native_stepper.maxValue = float(value)

def set_alignment(self, value):
def set_text_align(self, value):
self.native_input.alignment = NSTextAlignment(value)

def set_font(self, font):
Expand Down
2 changes: 1 addition & 1 deletion cocoa/src/toga_cocoa/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def get_placeholder(self):
def set_placeholder(self, value):
self.native.cell.placeholderString = value

def set_alignment(self, value):
def set_text_align(self, value):
self.native.alignment = NSTextAlignment(value)
# The alert label should be on the trailing edge
if value == RIGHT:
Expand Down
4 changes: 2 additions & 2 deletions cocoa/tests_backend/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def assert_not_contained(self):
assert self.native.superview is None
assert self.native.window is None

def assert_alignment(self, expected):
assert self.alignment == expected
def assert_text_align(self, expected):
assert self.text_align == expected

async def redraw(self, message=None, delay=0):
"""Request a redraw of the app, waiting until that redraw has completed."""
Expand Down
8 changes: 4 additions & 4 deletions cocoa/tests_backend/widgets/label.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from toga_cocoa.libs import NSTextField

from .base import SimpleProbe
from .properties import toga_alignment, toga_color
from .properties import toga_color, toga_text_align


class LabelProbe(SimpleProbe):
Expand All @@ -16,9 +16,9 @@ def color(self):
return toga_color(self.native.textColor)

@property
def alignment(self):
return toga_alignment(self.native.alignment)
def text_align(self):
return toga_text_align(self.native.alignment)

def assert_vertical_alignment(self, expected):
def assert_vertical_text_align(self, expected):
# Vertical alignment isn't configurable on NSTextField
pass
8 changes: 4 additions & 4 deletions cocoa/tests_backend/widgets/multilinetextinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from toga_cocoa.libs import NSRange, NSScrollView, NSTextView

from .base import SimpleProbe
from .properties import toga_alignment, toga_color
from .properties import toga_color, toga_text_align


class MultilineTextInputProbe(SimpleProbe):
Expand Down Expand Up @@ -58,10 +58,10 @@ def font(self):
return self.native_text.font

@property
def alignment(self):
return toga_alignment(self.native_text.alignment)
def text_align(self):
return toga_text_align(self.native_text.alignment)

def assert_vertical_alignment(self, expected):
def assert_vertical_text_align(self, expected):
# Vertical alignment isn't configurable on NSTextView
pass

Expand Down
8 changes: 4 additions & 4 deletions cocoa/tests_backend/widgets/numberinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)

from .base import SimpleProbe
from .properties import toga_alignment, toga_color
from .properties import toga_color, toga_text_align


class NumberInputProbe(SimpleProbe):
Expand Down Expand Up @@ -86,10 +86,10 @@ def font(self):
return self.native_input.font

@property
def alignment(self):
return toga_alignment(self.native_input.alignment)
def text_align(self):
return toga_text_align(self.native_input.alignment)

def assert_vertical_alignment(self, expected):
def assert_vertical_text_align(self, expected):
# Vertical alignment isn't configurable on NSTextField
pass

Expand Down
2 changes: 1 addition & 1 deletion cocoa/tests_backend/widgets/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def toga_color(color):
return None


def toga_alignment(alignment):
def toga_text_align(alignment):
return {
NSLeftTextAlignment: LEFT,
NSRightTextAlignment: RIGHT,
Expand Down
4 changes: 2 additions & 2 deletions cocoa/tests_backend/widgets/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def assert_resizes_on_content_change(self):
pass

@property
def alignment(self):
xfail("Can't change the alignment of Selection on macOS")
def text_align(self):
xfail("Can't change the text alignment of Selection on macOS")

@property
def color(self):
Expand Down
8 changes: 4 additions & 4 deletions cocoa/tests_backend/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)

from .base import SimpleProbe
from .properties import toga_alignment, toga_color
from .properties import toga_color, toga_text_align


class TextInputProbe(SimpleProbe):
Expand Down Expand Up @@ -60,15 +60,15 @@ def font(self):
return self.native.font

@property
def alignment(self):
result = toga_alignment(self.native.alignment)
def text_align(self):
result = toga_text_align(self.native.alignment)
if result == RIGHT:
assert self.impl.error_label.alignment == NSLeftTextAlignment
else:
assert self.impl.error_label.alignment == NSRightTextAlignment
return result

def assert_vertical_alignment(self, expected):
def assert_vertical_text_align(self, expected):
# Vertical alignment isn't configurable on NSTextField
pass

Expand Down
4 changes: 2 additions & 2 deletions core/src/toga/style/applicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def set_bounds(self) -> None:
for child in self.widget.children:
child.applicator.set_bounds()

def set_text_alignment(self, alignment: str) -> None:
self.widget._impl.set_alignment(alignment)
def set_text_align(self, alignment: str) -> None:
self.widget._impl.set_text_align(alignment)

def set_hidden(self, hidden: bool) -> None:
self.widget._impl.set_hidden(hidden)
Expand Down
Loading

0 comments on commit eec2395

Please sign in to comment.