-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
helpers.go
70 lines (63 loc) · 2.36 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
// Copyright (c) 2021-2024 by Richard A. Wilkes. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with
// this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, version 2.0.
package unison
import (
"strings"
"github.com/richardwilkes/unison/enums/paintstyle"
)
// DrawRectBase fills and strokes a rectangle.
func DrawRectBase(canvas *Canvas, rect Rect, fillInk, strokeInk Ink) {
canvas.DrawRect(rect, fillInk.Paint(canvas, rect, paintstyle.Fill))
rect = rect.Inset(NewUniformInsets(0.5))
canvas.DrawRect(rect, strokeInk.Paint(canvas, rect, paintstyle.Stroke))
}
// DrawRoundedRectBase fills and strokes a rounded rectangle.
func DrawRoundedRectBase(canvas *Canvas, rect Rect, cornerRadius, thickness float32, fillInk, strokeInk Ink) {
canvas.DrawRoundedRect(rect, cornerRadius, cornerRadius, fillInk.Paint(canvas, rect, paintstyle.Fill))
rect = rect.Inset(NewUniformInsets(thickness / 2))
cornerRadius = max(cornerRadius-thickness/2, 0)
p := strokeInk.Paint(canvas, rect, paintstyle.Stroke)
p.SetStrokeWidth(thickness)
canvas.DrawRoundedRect(rect, cornerRadius, cornerRadius, p)
}
// DrawEllipseBase fills and strokes an ellipse.
func DrawEllipseBase(canvas *Canvas, rect Rect, thickness float32, fillInk, strokeInk Ink) {
canvas.DrawOval(rect, fillInk.Paint(canvas, rect, paintstyle.Fill))
rect = rect.Inset(NewUniformInsets(thickness / 2))
p := strokeInk.Paint(canvas, rect, paintstyle.Stroke)
p.SetStrokeWidth(thickness)
canvas.DrawOval(rect, p)
}
// SanitizeExtensionList ensures the extension list is consistent:
//
// - removal of leading and trailing white space
// - removal of leading "*." or "."
// - lower-cased
// - removal of duplicates
// - removal of empty extensions
func SanitizeExtensionList(in []string) []string {
var actual []string
existence := make(map[string]bool)
for _, ext := range in {
ext = strings.TrimSpace(ext)
if strings.HasPrefix(ext, "*.") {
ext = strings.TrimSpace(ext[2:])
} else {
ext = strings.TrimSpace(strings.TrimPrefix(ext, "."))
}
if ext != "" {
ext = strings.ToLower(ext)
if !existence[ext] {
existence[ext] = true
actual = append(actual, ext)
}
}
}
return actual
}