-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers.go
71 lines (65 loc) · 1.98 KB
/
helpers.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
package helper
import (
"image"
"gioui.org/f32"
"gioui.org/layout"
"gioui.org/unit"
)
func DuoUIdrawRectangle(gtx layout.Context, w, h int, color string, borderRadius [4]float32, padding [4]float32) layout.Dimensions {
in := layout.Inset{
Top: unit.Dp(padding[0]),
Right: unit.Dp(padding[1]),
Bottom: unit.Dp(padding[2]),
Left: unit.Dp(padding[3]),
}
return in.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
bounds := image.Point{
X: w,
Y: h,
}
Fill(gtx, HexARGB(color), bounds)
// square := f32.Rectangle{
// Max: f32.Point{
// X: float32(w),
// Y: float32(h),
// },
// }
//
// paint.ColorOp{Color: HexARGB(color)}.Add(gtx.Ops)
// // clip.Rect{Rect: square,
// // NE: borderRadius[0], NW: borderRadius[1], SE: borderRadius[2], SW: borderRadius[3]}.Op(gtx.Ops).Add(gtx.Ops) // HLdraw
// paint.PaintOp{Rect: square}.Add(gtx.Ops)
return layout.Dimensions{Size: bounds}
})
}
// func DuoUIfill(gtx layout.Context, col string) {
// cs := gtx.Constraints
// d := image.Point{X: cs.Min.X, Y: cs.Min.Y}
// dr := f32.Rectangle{
// Max: f32.Point{X: float32(d.X), Y: float32(d.Y)},
// }
// paint.ColorOp{Color: HexARGB(col)}.Add(gtx.Ops)
// paint.PaintOp{Rect: dr}.Add(gtx.Ops)
// // gtx.Dimensions = layout.Dimensions{Size: d}
// }
func DuoUIline(vert bool, verticalPadding, horizontalPadding float32, size int, color string) func(gtx layout.Context) layout.Dimensions {
return func(gtx layout.Context) layout.Dimensions {
return layout.Inset{
Top: unit.Dp(verticalPadding),
Right: unit.Dp(horizontalPadding),
Bottom: unit.Dp(verticalPadding),
Left: unit.Dp(horizontalPadding),
}.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
v := size
h := gtx.Constraints.Max.X
if vert {
h = size
v = 8
}
return DuoUIdrawRectangle(gtx, h, v, color, [4]float32{0, 0, 0, 0}, [4]float32{0, 0, 0, 0})
})
}
}
func toPointF(p image.Point) f32.Point {
return f32.Point{X: float32(p.X), Y: float32(p.Y)}
}