-
-
Notifications
You must be signed in to change notification settings - Fork 798
Expand file tree
/
Copy pathbase.py
More file actions
151 lines (117 loc) · 4.59 KB
/
base.py
File metadata and controls
151 lines (117 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from abc import abstractmethod
from toga_iOS.colors import native_color
from toga_iOS.constraints import Constraints
from ..libs import supports_liquid_glass
class Widget:
def __init__(self, interface):
super().__init__()
self.interface = interface
self._container = None
self.constraints = None
self.native = None
self.create()
# Many widgets have a "transparent" background; however, some widgets use
# UIColor.ClearColor, and some use UIExtendedGrayColorSpace 0 0, which has
# slightly different color mixing characteristics. Widgets like TextInput use
# `None` as their initial background color, so that always adapts to light/dark
# mode. Preserve the initial background color on the freshly created widget so
# that we can reset back to that color when background_color is set to None. See
# #3104 for details.
self._default_background_color = self.native.backgroundColor
@property
def scroll_vertical(self):
return False
# @property
# def scroll_horizontal(self):
# return False
@abstractmethod
def create(self): ...
def set_app(self, app):
pass
def set_window(self, window):
pass
@property
def container(self):
return self._container
@container.setter
def container(self, container):
if self.container:
assert container is None, f"{self} already has a container"
# Existing container should be removed
self.constraints.container = None
self._container = None
self.native.removeFromSuperview()
elif container:
# setting container
self._container = container
self._container.native.addSubview(self.native)
self.constraints.container = container
for child in self.interface.children:
child._impl.container = container
self.rehint()
def get_enabled(self):
return self.native.isEnabled()
def set_enabled(self, value):
self.native.setEnabled(value)
@property
def has_focus(self):
return self.native.isFirstResponder
def focus(self):
if not self.has_focus:
self.native.becomeFirstResponder()
def get_tab_index(self):
self.interface.factory.not_implemented("Widget.get_tab_index()")
def set_tab_index(self, tab_index):
self.interface.factory.not_implemented("Widget.set_tab_index()")
# APPLICATOR
def set_bounds(self, x, y, width, height):
# print("SET BOUNDS", self, x, y, width, height, self.container.top_inset)
if supports_liquid_glass or self.container.content == self:
if self.scroll_vertical and self.container.top_unset and y == 0:
y -= self.container.top_inset
height += self.container.top_inset
# Right now, the below lines are irrelevant and lead to coverage issues,
# as we only have a title bar to bleed over. When constructs such as
# if (
# self.scroll_vertical
# and self.container.bottom_unset
# and y + height == self.container.height
# ):
# height += self.container.bottom_inset
# if self.scroll_horizontal and self.container.left_unset and x == 0:
# x -= self.container.left_inset
# width += self.container.left_inset
# if (
# self.scroll_horizontal
# and self.container.right_unset
# and x + width == self.container.width
# ):
# width += self.container.right_inset
self.constraints.update(x, y, width, height)
def set_text_align(self, alignment):
pass
def set_hidden(self, hidden):
self.native.setHidden(hidden)
def set_font(self, font):
# By default, font can't be changed
pass
def set_color(self, color):
# By default, color can't be changed
pass
def set_background_color(self, color):
self.native.backgroundColor = (
self._default_background_color if color is None else native_color(color)
)
# INTERFACE
def add_child(self, child):
child.container = self.container
def insert_child(self, index, child):
self.add_child(child)
def remove_child(self, child):
child.container = None
def add_constraints(self):
self.constraints = Constraints(self)
def refresh(self):
self.rehint()
@abstractmethod
def rehint(self): ...