Skip to content

Types

Reference

Bases: NamedTuple

A geographic coordinate.

Source code in core/src/toga/types.py
26
27
28
29
30
31
32
33
34
35
36
class LatLng(NamedTuple):
    """A geographic coordinate."""

    lat: float
    """Latitude"""

    lng: float
    """Longitude"""

    def __str__(self) -> str:
        return f"({self.lat:6f}, {self.lng:6f})"

lat

Latitude

lng

Longitude

Bases: NamedTuple

A 2D position.

Source code in core/src/toga/types.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class Position(NamedTuple):
    """A 2D position."""

    x: int
    """X coordinate, in CSS pixels."""

    y: int
    """Y coordinate, in CSS pixels."""

    def __str__(self) -> str:
        return f"({self.x}, {self.y})"

    def __add__(self, other):
        return Position(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Position(self.x - other.x, self.y - other.y)

    def __mul__(self, other):
        return Position(self.x * other, self.y * other)

x

X coordinate, in CSS pixels.

y

Y coordinate, in CSS pixels.

Bases: NamedTuple

A 2D size.

Source code in core/src/toga/types.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class Size(NamedTuple):
    """A 2D size."""

    width: int
    """Width, in CSS pixels."""

    height: int
    """Height, in CSS pixels."""

    def __str__(self) -> str:
        return f"({self.width} x {self.height})"

    def __mul__(self, other):
        return Size(self.width * other, self.height * other)

height

Height, in CSS pixels.

width

Width, in CSS pixels.

A representation of a 2D position, in CSS pixels. This can be:

A representation of a 2D size, in CSS pixels. This can be:

  • A tuple of 2 integers (x,y); or
  • An instance of toga.Size.