forked from andlabs/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
label.go
66 lines (52 loc) · 1.31 KB
/
label.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
// 12 december 2015
package ui
import (
"unsafe"
)
// #include "pkgui.h"
import "C"
// Label is a Control that represents a line of text that cannot be
// interacted with.
type Label struct {
ControlBase
l *C.uiLabel
}
// NewLabel creates a new Label with the given text.
func NewLabel(text string) *Label {
l := new(Label)
ctext := C.CString(text)
l.l = C.uiNewLabel(ctext)
freestr(ctext)
l.ControlBase = NewControlBase(l, uintptr(unsafe.Pointer(l.l)))
return l
}
// NewLabel creates a new Label with the given text.
func NewCenteredLabel(text string) *Label {
l := new(Label)
ctext := C.CString(text)
l.l = C.uiNewCenteredLabel(ctext)
freestr(ctext)
l.ControlBase = NewControlBase(l, uintptr(unsafe.Pointer(l.l)))
return l
}
// Text returns the Label's text.
func (l *Label) Text() string {
ctext := C.uiLabelText(l.l)
text := C.GoString(ctext)
C.uiFreeText(ctext)
return text
}
// SetText sets the Label's text to text.
func (l *Label) SetText(text string) {
ctext := C.CString(text)
C.uiLabelSetText(l.l, ctext)
freestr(ctext)
}
func (l *Label) SetFont(name string, size int, weight TextWeight) {
cname := C.CString(name)
C.uiLabelSetFont(l.l, cname, C.int(size), C.int(weight), C.int(0))
freestr(cname)
}
func (l *Label) SetMinSize(w int, h int) {
C.uiLabelSetMinSize(l.l, C.int(w), C.int(h))
}