summaryrefslogtreecommitdiff
path: root/label_unix.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-30 23:02:02 -0400
committerPietro Gagliardi <[email protected]>2014-08-30 23:02:02 -0400
commit77bf566ebbcb62acd4d08d905d9542d6ff9b6b80 (patch)
treeeeb8e72bc3bf57f5be7f0c0af4319189ac6de838 /label_unix.go
parent155899c65ed32245e2ccad4197a10c77017d835b (diff)
...in with the new.
Diffstat (limited to 'label_unix.go')
-rw-r--r--label_unix.go92
1 files changed, 92 insertions, 0 deletions
diff --git a/label_unix.go b/label_unix.go
new file mode 100644
index 0000000..45a3dad
--- /dev/null
+++ b/label_unix.go
@@ -0,0 +1,92 @@
+// +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"
+
+type label struct {
+ _widget *C.GtkWidget
+ misc *C.GtkMisc
+ label *C.GtkLabel
+ standalone bool
+}
+
+func finishNewLabel(text string, standalone bool) *label {
+ ctext := togstr(text)
+ defer freegstr(ctext)
+ widget := C.gtk_label_new(ctext)
+ l := &label{
+ _widget: widget,
+ misc: (*C.GtkMisc)(unsafe.Pointer(widget)),
+ label: (*C.GtkLabel)(unsafe.Pointer(widget)),
+ standalone: standalone,
+ }
+ return l
+}
+
+func newLabel(text string) Label {
+ return finishNewLabel(text, false)
+}
+
+func newStandaloneLabel(text string) Label {
+ l := finishNewLabel(text, true)
+ // standalone labels are always at the top left
+ C.gtk_misc_set_alignment(l.misc, 0, 0)
+ return l
+}
+
+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) isStandalone() bool {
+ return l.standalone
+}
+
+func (l *label) widget() *C.GtkWidget {
+ return l._widget
+}
+
+func (l *label) setParent(p *controlParent) {
+ basesetParent(l, p)
+}
+
+func (l *label) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
+ return baseallocate(l, x, y, width, height, d)
+}
+
+func (l *label) preferredSize(d *sizing) (width, height int) {
+ return basepreferredSize(l, d)
+}
+
+func (l *label) commitResize(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)
+ }
+ }
+ basecommitResize(l, c, d)
+}
+
+func (l *label) getAuxResizeInfo(d *sizing) {
+ basegetAuxResizeInfo(l, d)
+}