summaryrefslogtreecommitdiff
path: root/redo/label_unix.go
blob: 1776b7320f9a5af56052944bf01cc11230d6029c (plain)
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
// +build !windows,!darwin

// 7 july 2014

package ui

import (
	"unsafe"
)

// #include "gtk_unix.h"
// extern void buttonClicked(GtkButton *, gpointer);
// extern void checkboxToggled(GtkToggleButton *, gpointer);
import "C"

// TODOs:
// - standalone label on its own: should it be centered or not?

type label struct {
	*controlbase
	misc					*C.GtkMisc
	label					*C.GtkLabel
	standalone			bool
	supercommitResize		func(c *allocation, d *sizing)
}

func finishNewLabel(text string, standalone bool) *label {
	ctext := togstr(text)
	defer freegstr(ctext)
	widget := C.gtk_label_new(ctext)
	l := &label{
		controlbase:	newControl(widget),
		misc:		(*C.GtkMisc)(unsafe.Pointer(widget)),
		label:		(*C.GtkLabel)(unsafe.Pointer(widget)),
		standalone:	standalone,
	}
	l.supercommitResize = l.fcommitResize
	l.fcommitResize = l.labelcommitResize
	return l
}

func newLabel(text string) Label {
	return finishNewLabel(text, false)
}

func newStandaloneLabel(text string) Label {
	return finishNewLabel(text, true)
}

func (l *label) Text() string {
	return fromgstr(C.gtk_label_get_text(l.label))
}

func (l *label) SetText(text string) {
	ctext := togstr(text)
	defer freegstr(ctext)
	C.gtk_label_set_text(l.label, ctext)
}

func (l *label) labelcommitResize(c *allocation, d *sizing) {
	if !l.standalone && c.neighbor != nil {
		c.neighbor.getAuxResizeInfo(d)
		if d.shouldVAlignTop {
			// don't bother aligning it to the first line of text in the control; this is harder than it's worth (thanks gregier in irc.gimp.net/#gtk+)
			C.gtk_misc_set_alignment(l.misc, 0, 0)
		} else {
			C.gtk_misc_set_alignment(l.misc, 0, 0.5)
		}
	}
	l.supercommitResize(c, d)
}