-
Notifications
You must be signed in to change notification settings - Fork 71
/
unitgen.go
387 lines (325 loc) · 10.6 KB
/
unitgen.go
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
// Code generated by "go run gen.go"; DO NOT EDIT.
// Copyright (c) 2023, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package units
// Dp returns a new dp value.
// Dp is density-independent pixels. 1dp is 1/160 in.
func Dp(value float32) Value {
return Value{Value: value, Unit: UnitDp}
}
// Dp sets the value in terms of dp.
// Dp is density-independent pixels. 1dp is 1/160 in.
func (v *Value) Dp(value float32) {
v.Value = value
v.Unit = UnitDp
}
// Dp converts the given dp value to dots.
// Dp is density-independent pixels. 1dp is 1/160 in.
func (uc *Context) Dp(value float32) float32 {
return uc.ToDots(value, UnitDp)
}
// Px returns a new px value.
// Px is logical pixels. 1px is 1/96 in. These are not raw display pixels, for which you should use dots.
func Px(value float32) Value {
return Value{Value: value, Unit: UnitPx}
}
// Px sets the value in terms of px.
// Px is logical pixels. 1px is 1/96 in. These are not raw display pixels, for which you should use dots.
func (v *Value) Px(value float32) {
v.Value = value
v.Unit = UnitPx
}
// Px converts the given px value to dots.
// Px is logical pixels. 1px is 1/96 in. These are not raw display pixels, for which you should use dots.
func (uc *Context) Px(value float32) float32 {
return uc.ToDots(value, UnitPx)
}
// Ew returns a new ew value.
// Ew is percentage of element width, which is equivalent to CSS % in some contexts.
func Ew(value float32) Value {
return Value{Value: value, Unit: UnitEw}
}
// Ew sets the value in terms of ew.
// Ew is percentage of element width, which is equivalent to CSS % in some contexts.
func (v *Value) Ew(value float32) {
v.Value = value
v.Unit = UnitEw
}
// Ew converts the given ew value to dots.
// Ew is percentage of element width, which is equivalent to CSS % in some contexts.
func (uc *Context) Ew(value float32) float32 {
return uc.ToDots(value, UnitEw)
}
// Eh returns a new eh value.
// Eh is percentage of element height, which is equivalent to CSS % in some contexts.
func Eh(value float32) Value {
return Value{Value: value, Unit: UnitEh}
}
// Eh sets the value in terms of eh.
// Eh is percentage of element height, which is equivalent to CSS % in some contexts.
func (v *Value) Eh(value float32) {
v.Value = value
v.Unit = UnitEh
}
// Eh converts the given eh value to dots.
// Eh is percentage of element height, which is equivalent to CSS % in some contexts.
func (uc *Context) Eh(value float32) float32 {
return uc.ToDots(value, UnitEh)
}
// Pw returns a new pw value.
// Pw is percentage of parent width, which is equivalent to CSS % in some contexts.
func Pw(value float32) Value {
return Value{Value: value, Unit: UnitPw}
}
// Pw sets the value in terms of pw.
// Pw is percentage of parent width, which is equivalent to CSS % in some contexts.
func (v *Value) Pw(value float32) {
v.Value = value
v.Unit = UnitPw
}
// Pw converts the given pw value to dots.
// Pw is percentage of parent width, which is equivalent to CSS % in some contexts.
func (uc *Context) Pw(value float32) float32 {
return uc.ToDots(value, UnitPw)
}
// Ph returns a new ph value.
// Ph is percentage of parent height, which is equivalent to CSS % in some contexts.
func Ph(value float32) Value {
return Value{Value: value, Unit: UnitPh}
}
// Ph sets the value in terms of ph.
// Ph is percentage of parent height, which is equivalent to CSS % in some contexts.
func (v *Value) Ph(value float32) {
v.Value = value
v.Unit = UnitPh
}
// Ph converts the given ph value to dots.
// Ph is percentage of parent height, which is equivalent to CSS % in some contexts.
func (uc *Context) Ph(value float32) float32 {
return uc.ToDots(value, UnitPh)
}
// Rem returns a new rem value.
// Rem is the font size of the root element, which is always 16dp.
func Rem(value float32) Value {
return Value{Value: value, Unit: UnitRem}
}
// Rem sets the value in terms of rem.
// Rem is the font size of the root element, which is always 16dp.
func (v *Value) Rem(value float32) {
v.Value = value
v.Unit = UnitRem
}
// Rem converts the given rem value to dots.
// Rem is the font size of the root element, which is always 16dp.
func (uc *Context) Rem(value float32) float32 {
return uc.ToDots(value, UnitRem)
}
// Em returns a new em value.
// Em is the font size of the element.
func Em(value float32) Value {
return Value{Value: value, Unit: UnitEm}
}
// Em sets the value in terms of em.
// Em is the font size of the element.
func (v *Value) Em(value float32) {
v.Value = value
v.Unit = UnitEm
}
// Em converts the given em value to dots.
// Em is the font size of the element.
func (uc *Context) Em(value float32) float32 {
return uc.ToDots(value, UnitEm)
}
// Ex returns a new ex value.
// Ex is x-height of the element's font (size of 'x' glyph). It falls back to a default of 0.5em.
func Ex(value float32) Value {
return Value{Value: value, Unit: UnitEx}
}
// Ex sets the value in terms of ex.
// Ex is x-height of the element's font (size of 'x' glyph). It falls back to a default of 0.5em.
func (v *Value) Ex(value float32) {
v.Value = value
v.Unit = UnitEx
}
// Ex converts the given ex value to dots.
// Ex is x-height of the element's font (size of 'x' glyph). It falls back to a default of 0.5em.
func (uc *Context) Ex(value float32) float32 {
return uc.ToDots(value, UnitEx)
}
// Ch returns a new ch value.
// Ch is width of the '0' glyph in the element's font. It falls back to a default of 0.5em.
func Ch(value float32) Value {
return Value{Value: value, Unit: UnitCh}
}
// Ch sets the value in terms of ch.
// Ch is width of the '0' glyph in the element's font. It falls back to a default of 0.5em.
func (v *Value) Ch(value float32) {
v.Value = value
v.Unit = UnitCh
}
// Ch converts the given ch value to dots.
// Ch is width of the '0' glyph in the element's font. It falls back to a default of 0.5em.
func (uc *Context) Ch(value float32) float32 {
return uc.ToDots(value, UnitCh)
}
// Vw returns a new vw value.
// Vw is percentage of viewport (Scene) width.
func Vw(value float32) Value {
return Value{Value: value, Unit: UnitVw}
}
// Vw sets the value in terms of vw.
// Vw is percentage of viewport (Scene) width.
func (v *Value) Vw(value float32) {
v.Value = value
v.Unit = UnitVw
}
// Vw converts the given vw value to dots.
// Vw is percentage of viewport (Scene) width.
func (uc *Context) Vw(value float32) float32 {
return uc.ToDots(value, UnitVw)
}
// Vh returns a new vh value.
// Vh is percentage of viewport (Scene) height.
func Vh(value float32) Value {
return Value{Value: value, Unit: UnitVh}
}
// Vh sets the value in terms of vh.
// Vh is percentage of viewport (Scene) height.
func (v *Value) Vh(value float32) {
v.Value = value
v.Unit = UnitVh
}
// Vh converts the given vh value to dots.
// Vh is percentage of viewport (Scene) height.
func (uc *Context) Vh(value float32) float32 {
return uc.ToDots(value, UnitVh)
}
// Vmin returns a new vmin value.
// Vmin is percentage of the smaller dimension of the viewport (Scene).
func Vmin(value float32) Value {
return Value{Value: value, Unit: UnitVmin}
}
// Vmin sets the value in terms of vmin.
// Vmin is percentage of the smaller dimension of the viewport (Scene).
func (v *Value) Vmin(value float32) {
v.Value = value
v.Unit = UnitVmin
}
// Vmin converts the given vmin value to dots.
// Vmin is percentage of the smaller dimension of the viewport (Scene).
func (uc *Context) Vmin(value float32) float32 {
return uc.ToDots(value, UnitVmin)
}
// Vmax returns a new vmax value.
// Vmax is percentage of the larger dimension of the viewport (Scene).
func Vmax(value float32) Value {
return Value{Value: value, Unit: UnitVmax}
}
// Vmax sets the value in terms of vmax.
// Vmax is percentage of the larger dimension of the viewport (Scene).
func (v *Value) Vmax(value float32) {
v.Value = value
v.Unit = UnitVmax
}
// Vmax converts the given vmax value to dots.
// Vmax is percentage of the larger dimension of the viewport (Scene).
func (uc *Context) Vmax(value float32) float32 {
return uc.ToDots(value, UnitVmax)
}
// Cm returns a new cm value.
// Cm is centimeters. 1cm is 1/2.54 in.
func Cm(value float32) Value {
return Value{Value: value, Unit: UnitCm}
}
// Cm sets the value in terms of cm.
// Cm is centimeters. 1cm is 1/2.54 in.
func (v *Value) Cm(value float32) {
v.Value = value
v.Unit = UnitCm
}
// Cm converts the given cm value to dots.
// Cm is centimeters. 1cm is 1/2.54 in.
func (uc *Context) Cm(value float32) float32 {
return uc.ToDots(value, UnitCm)
}
// Mm returns a new mm value.
// Mm is millimeters. 1mm is 1/10 cm.
func Mm(value float32) Value {
return Value{Value: value, Unit: UnitMm}
}
// Mm sets the value in terms of mm.
// Mm is millimeters. 1mm is 1/10 cm.
func (v *Value) Mm(value float32) {
v.Value = value
v.Unit = UnitMm
}
// Mm converts the given mm value to dots.
// Mm is millimeters. 1mm is 1/10 cm.
func (uc *Context) Mm(value float32) float32 {
return uc.ToDots(value, UnitMm)
}
// Q returns a new q value.
// Q is quarter-millimeters. 1q is 1/40 cm.
func Q(value float32) Value {
return Value{Value: value, Unit: UnitQ}
}
// Q sets the value in terms of q.
// Q is quarter-millimeters. 1q is 1/40 cm.
func (v *Value) Q(value float32) {
v.Value = value
v.Unit = UnitQ
}
// Q converts the given q value to dots.
// Q is quarter-millimeters. 1q is 1/40 cm.
func (uc *Context) Q(value float32) float32 {
return uc.ToDots(value, UnitQ)
}
// In returns a new in value.
// In is inches. 1in is 2.54cm or 96px.
func In(value float32) Value {
return Value{Value: value, Unit: UnitIn}
}
// In sets the value in terms of in.
// In is inches. 1in is 2.54cm or 96px.
func (v *Value) In(value float32) {
v.Value = value
v.Unit = UnitIn
}
// In converts the given in value to dots.
// In is inches. 1in is 2.54cm or 96px.
func (uc *Context) In(value float32) float32 {
return uc.ToDots(value, UnitIn)
}
// Pc returns a new pc value.
// Pc is picas. 1pc is 1/6 in.
func Pc(value float32) Value {
return Value{Value: value, Unit: UnitPc}
}
// Pc sets the value in terms of pc.
// Pc is picas. 1pc is 1/6 in.
func (v *Value) Pc(value float32) {
v.Value = value
v.Unit = UnitPc
}
// Pc converts the given pc value to dots.
// Pc is picas. 1pc is 1/6 in.
func (uc *Context) Pc(value float32) float32 {
return uc.ToDots(value, UnitPc)
}
// Pt returns a new pt value.
// Pt is points. 1pt is 1/72 in.
func Pt(value float32) Value {
return Value{Value: value, Unit: UnitPt}
}
// Pt sets the value in terms of pt.
// Pt is points. 1pt is 1/72 in.
func (v *Value) Pt(value float32) {
v.Value = value
v.Unit = UnitPt
}
// Pt converts the given pt value to dots.
// Pt is points. 1pt is 1/72 in.
func (uc *Context) Pt(value float32) float32 {
return uc.ToDots(value, UnitPt)
}