-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalignment_ui.py
227 lines (188 loc) · 7.08 KB
/
alignment_ui.py
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
from talon import actions
YELLOW = "FFCC00"
LIGHT_BLUE = "87CEEB"
WHITE = "CCCCCC"
item_style = {
"border_width": 1,
"border_color": WHITE,
"padding": 8,
}
def items():
div, text = actions.user.ui_elements(["div", "text"])
return [
div(item_style)[
text("Hello")
],
div(item_style)[
text("to")
],
div(item_style)[
text("the")
],
div(item_style)[
text("world")
],
]
def items_first_flex():
div, text = actions.user.ui_elements(["div", "text"])
return [
div(item_style, flex=1)[
text("Hello")
],
div(item_style)[
text("to")
],
div(item_style)[
text("the")
],
div(item_style)[
text("world")
],
]
def items_all_flex():
div, text = actions.user.ui_elements(["div", "text"])
return [
div(item_style, flex=1)[
text("Hello")
],
div(item_style, flex=1)[
text("to")
],
div(item_style, flex=1)[
text("the")
],
div(item_style, flex=1)[
text("world")
],
]
def example_ui(number: int, title, content):
div, text = actions.user.ui_elements(["div", "text"])
return div()[
div(flex_direction="row", align_items="center", margin_bottom=16)[
text(f"{number}. "),
title,
],
div(background_color="333333", width=360, height=180, border_radius=4, border_width=1, border_color=WHITE)[
content
],
]
def example1_ui():
div, text = actions.user.ui_elements(["div", "text"])
title = div(flex_direction="row")[
text('flex_direction=', color=WHITE), text('"column"', color=YELLOW),
text(', align_items=', color=WHITE), text('"stretch"', color=YELLOW),
]
return example_ui(1, title, content=div(padding=8, gap=8)[
*items(),
])
def example2_ui():
div, text = actions.user.ui_elements(["div", "text"])
title = div(flex_direction="row")[
text('flex_direction=', color=WHITE), text('"row"', color=YELLOW),
text(', height=', color=WHITE), text('"100%"', color=YELLOW),
]
return example_ui(2, title, content=div(padding=8, gap=8, flex_direction="row", height="100%")[
*items(),
])
def example3_ui():
div, text = actions.user.ui_elements(["div", "text"])
title = div(flex_direction="row")[
text('justify_content=', color=WHITE), text('"space_between"', color=YELLOW),
]
return example_ui(3, title, content=div(padding=8, gap=8, flex_direction="row", height="100%", justify_content="space_between")[
*items(),
])
def example4_ui():
div, text = actions.user.ui_elements(["div", "text"])
title = div(flex_direction="row")[
text('flex_direction=', color=WHITE), text('"row"', color=YELLOW),
text(', align_items=', color=WHITE), text('"flex_start"', color=YELLOW),
]
return example_ui(4, title, content=div(padding=8, gap=8, flex_direction="row", align_items="flex_start")[
*items(),
])
def example5_ui():
div, text = actions.user.ui_elements(["div", "text"])
title = div(flex_direction="row")[
text('align_items=', color=WHITE), text('"center"', color=YELLOW),
text(', justify_content=', color=WHITE), text('"center"', color=YELLOW),
]
return example_ui(5, title, content=div(padding=8, gap=8, height="100%", flex_direction="row", align_items="center", justify_content="center")[
*items(),
])
def example6_ui():
div, text = actions.user.ui_elements(["div", "text"])
title = div(flex_direction="row")[
text('flex_direction=', color=WHITE), text('"column"', color=YELLOW),
text(', align_items=', color=WHITE), text('"flex_end"', color=YELLOW),
]
return example_ui(6, title, content=div(padding=8, gap=8, flex_direction="column", align_items="flex_end")[
*items(),
])
def example7_ui():
div, text = actions.user.ui_elements(["div", "text"])
title = div(flex_direction="row")[
text('justify_content=', color=WHITE), text('"center"', color=YELLOW),
text(', height=', color=WHITE), text('"100%"', color=YELLOW),
]
return example_ui(7, title, content=div(padding=8, gap=8, flex_direction="row", justify_content="center", height="100%")[
*items(),
])
def example8_ui():
div, text = actions.user.ui_elements(["div", "text"])
title = div(flex_direction="row", align_items="center")[
div(flex_direction="row")[
text('flex=', color=WHITE),
text('1', color=YELLOW),
],
text(' on first child', color=WHITE),
]
return example_ui(8, title, content=div(padding=8, gap=8, flex_direction="row")[
*items_first_flex(),
])
def example9_ui():
div, text = actions.user.ui_elements(["div", "text"])
title = div(flex_direction="row", align_items="center")[
div(flex_direction="row")[
text('flex=', color=WHITE),
text('1', color=YELLOW),
],
text(' on every child', color=WHITE),
]
return example_ui(9, title, content=div(padding=8, gap=8, flex_direction="row")[
*items_all_flex(),
])
def alignment_ui():
div, text, screen = actions.user.ui_elements(["div", "text", "screen"])
return screen(justify_content="center", align_items="center")[
div(draggable=True, background_color="222222", padding=32, border_radius=8, border_width=1, border_color="555555")[
div(flex_direction="row", gap=32)[
div(padding=16, background_color=YELLOW, justify_content="space_between")[
text('A', color="000000"),
text('Z', color="000000"),
],
div()[
div(flex_direction='row', justify_content="space_between", padding_bottom=16, margin_bottom=16, border_bottom=1, border_color="555555")[
text("Alignment", font_size=32),
text("talon-ui-elements", font_size=32, color=YELLOW),
],
text("(default)", color=LIGHT_BLUE, margin_left=24, margin_bottom=-8, margin_top=16),
div(padding=24, flex_direction="row", gap=24)[
example1_ui(),
example2_ui(),
example3_ui(),
],
div(padding=24, flex_direction="row", gap=24)[
example4_ui(),
example5_ui(),
example6_ui(),
],
div(padding=24, flex_direction="row", gap=24)[
example7_ui(),
example8_ui(),
example9_ui(),
],
]
]
]
]