Skip to content

Commit

Permalink
Merge pull request #2478 from proneon267/iOS_divider
Browse files Browse the repository at this point in the history
Implemented Divider widget on iOS
  • Loading branch information
freakboy3742 authored Aug 22, 2024
2 parents 6e6e18a + ba18622 commit 5adb61a
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes/2478.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Divider widget was implemented on iOS.
6 changes: 4 additions & 2 deletions docs/reference/api/widgets/divider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ A separator used to visually distinguish two sections of content in a layout.
:align: center
:width: 300px

.. group-tab:: iOS |no|
.. group-tab:: iOS

Not supported
.. figure:: /reference/images/divider-iOS.png
:align: center
:width: 300px

.. group-tab:: Web |beta|

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/data/widgets_by_platform.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Button,General Widget,:class:`~toga.Button`,Basic clickable Button,|y|,|y|,|y|,|
Canvas,General Widget,:class:`~toga.Canvas`,A drawing area for 2D vector graphics.,|y|,|y|,|y|,|y|,|y|,,
DateInput,General Widget,:class:`~toga.DateInput`,A widget to select a calendar date,,,|y|,,|y|,,
DetailedList,General Widget,:class:`~toga.DetailedList`,"An ordered list of content where each item has an icon, a main heading, and a line of supplementary text.",|y|,|y|,|b|,|y|,|y|,,
Divider,General Widget,:class:`~toga.Divider`,A horizontal or vertical line,|y|,|y|,|y|,,|y|,|b|,
Divider,General Widget,:class:`~toga.Divider`,A horizontal or vertical line,|y|,|y|,|y|,|y|,|y|,|b|,
ImageView,General Widget,:class:`~toga.ImageView`,A widget that displays an image,|y|,|y|,|y|,|y|,|y|,,
Label,General Widget,:class:`~toga.Label`,Text label,|y|,|y|,|y|,|y|,|y|,|b|,|b|
MapView,General Widget,:class:`~toga.MapView`,A zoomable map that can be annotated with location pins,|y|,|y|,|y|,|y|,|y|,,
Expand Down
Binary file added docs/reference/images/divider-iOS.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions iOS/src/toga_iOS/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .widgets.button import Button
from .widgets.canvas import Canvas
from .widgets.detailedlist import DetailedList
from .widgets.divider import Divider
from .widgets.imageview import ImageView
from .widgets.label import Label
from .widgets.mapview import MapView
Expand Down Expand Up @@ -62,6 +63,7 @@ def not_implemented(feature):
"Button",
"Canvas",
"DetailedList",
"Divider",
"ImageView",
"Label",
"MapView",
Expand Down
41 changes: 41 additions & 0 deletions iOS/src/toga_iOS/widgets/divider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from travertino.size import at_least

from toga_iOS.libs import UIColor, UIView
from toga_iOS.widgets.base import Widget


class Divider(Widget):
def create(self):
self.native = UIView.alloc().init()
self.native.interface = self.interface
self.native.impl = self

# Background color needs to be set or else divider will not be visible.
self.system_gray_color = UIColor.systemGrayColor()
self.native.backgroundColor = self.system_gray_color

# Add the layout constraints
self.add_constraints()

# Set the initial direction
self._direction = self.interface.HORIZONTAL

def set_background_color(self, value):
# Do nothing, since background color of Divider shouldn't be changed.
pass

def rehint(self):
content_size = self.native.intrinsicContentSize()

if self._direction == self.interface.VERTICAL:
self.interface.intrinsic.width = 1
self.interface.intrinsic.height = at_least(content_size.height)
else:
self.interface.intrinsic.width = at_least(content_size.width)
self.interface.intrinsic.height = 1

def get_direction(self):
return self._direction

def set_direction(self, value):
self._direction = value
7 changes: 7 additions & 0 deletions iOS/tests_backend/widgets/divider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from toga_iOS.libs import UIView

from .base import SimpleProbe


class DividerProbe(SimpleProbe):
native_class = UIView
2 changes: 0 additions & 2 deletions testbed/tests/widgets/test_divider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from toga.constants import Direction
from toga.style.pack import COLUMN, ROW

from ..conftest import skip_on_platforms
from .properties import ( # noqa: F401
test_enable_noop,
test_focus_noop,
Expand All @@ -13,7 +12,6 @@

@pytest.fixture
async def widget():
skip_on_platforms("iOS")
return toga.Divider()


Expand Down

0 comments on commit 5adb61a

Please sign in to comment.