summaryrefslogtreecommitdiff
path: root/redo/label_unix.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-02 22:35:58 -0400
committerPietro Gagliardi <[email protected]>2014-08-02 22:35:58 -0400
commitd018953d7ef1b276cc3229e04ba6fc75018c888a (patch)
tree3f980a017ca498bf499ff9c5e6a53210606b12f9 /redo/label_unix.go
parent1f6bcde3d9ddcab921f2f4347148f6784ca36a14 (diff)
Split all the Control implementations into their own files and renamed the containerctrls implementation files to say tab instead as they only hold Tab. This is the first part of what should hopefully be the final restructuring.
Diffstat (limited to 'redo/label_unix.go')
-rw-r--r--redo/label_unix.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/redo/label_unix.go b/redo/label_unix.go
new file mode 100644
index 0000000..1776b73
--- /dev/null
+++ b/redo/label_unix.go
@@ -0,0 +1,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)
+}