-
Notifications
You must be signed in to change notification settings - Fork 11
/
text.go
84 lines (67 loc) · 1.8 KB
/
text.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
package text
import (
"fmt"
"image/color"
"strings"
html_go "html"
"qlova.org/seed"
"qlova.org/seed/client"
"qlova.org/seed/use/css"
"qlova.org/seed/use/html"
"qlova.org/seed/new/text/rich"
"qlova.org/seed/use/css/units"
)
//New returns a new text widget.
func New(options ...seed.Option) seed.Seed {
return seed.New(
html.SetTag("span"),
seed.Options(options),
)
}
//SetString sets the text from the given string.
func SetString(value string) seed.Option {
value = html_go.EscapeString(value)
value = strings.Replace(value, "\n", "<br>", -1)
value = strings.Replace(value, " ", " ", -1)
value = strings.Replace(value, "\t", " ", -1)
return html.Set(value)
}
//Set sets the text content of the text to the given formatted lines, each argument is seperated by a newline.
func Set(lines ...rich.Text) seed.Option {
var result string
for i, line := range lines {
if i > 0 {
result += "<br>"
}
result += line.HTML()
}
return html.Set(result)
}
//SetStringTo sets the text content of the text.
func SetStringTo(value client.String) seed.Option {
return html.SetInnerTextTo(value)
}
//SetColor sets the color of the text.
func SetColor(c color.Color) css.Rule {
return css.SetColor(css.RGB{Color: c})
}
//SetSize sets the font-size of the text.
func SetSize(s units.Unit) css.Rule {
return css.SetFontSize(css.Measure(s))
}
//SetLineHeight sets the line-height of the text.
func SetLineHeight(height float64) css.Rule {
return css.Set("line-height", fmt.Sprint(height))
}
//Center aligns the text to to the center.
func Center() css.Rule {
return css.SetTextAlign(css.Center)
}
//Right aligns the text to to the right.
func Right() css.Rule {
return css.SetTextAlign(css.Right)
}
//Left aligns the text to to the left.
func Left() css.Rule {
return css.SetTextAlign(css.Left)
}