diff --git a/gtkcalls_unix.go b/gtkcalls_unix.go index 8f202b3..fdd3d61 100644 --- a/gtkcalls_unix.go +++ b/gtkcalls_unix.go @@ -247,8 +247,16 @@ func gtk_label_new() *C.GtkWidget { // there's a function gtk_label_set_justify() that indicates GTK_JUSTIFY_LEFT is the default // but this actually is NOT the control justification, just the multi-line justification // so we need to do THIS instead + // this will valign to the center, which is what the HIG says (https://developer.gnome.org/hig-book/3.4/design-text-labels.html.en) for all controls that label to the side; thankfully this means we don't need to do any extra positioning magic // this will also valign to the top // thanks to mclasen in irc.gimp.net/#gtk+ + C.gtk_misc_set_alignment((*C.GtkMisc)(unsafe.Pointer(label)), 0, 0.5) + return label +} + +func gtk_label_new_standalone() *C.GtkWidget { + label := gtk_label_new() + // this will valign to the top C.gtk_misc_set_alignment((*C.GtkMisc)(unsafe.Pointer(label)), 0, 0) return label } diff --git a/label.go b/label.go index c5e2ea8..dfb6cb1 100644 --- a/label.go +++ b/label.go @@ -8,15 +8,18 @@ import ( // A Label is a static line of text used to mark other controls. // Label text is drawn on a single line; text that does not fit is truncated. -// TODO vertical alignment +// A Label can appear in one of two places: bound to a control or standalone. +// This determines the vertical alignment of the label. type Label struct { lock sync.Mutex created bool sysData *sysData initText string + standalone bool } // NewLabel creates a new Label with the specified text. +// The label is set to be bound to a control, so its vertical position depends on its vertical cell size in an implementation-defined manner. func NewLabel(text string) *Label { return &Label{ sysData: mksysdata(c_label), @@ -24,6 +27,16 @@ func NewLabel(text string) *Label { } } +// NewStandaloneLabel creates a new Label with the specified text. +// The label is set to be standalone, so its vertical position will always be at the top of the vertical space assigned to it. +func NewStandaloneLabel(text string) *Label { + return &Label{ + sysData: mksysdata(c_label), + initText: text, + standalone: true, + } +} + // SetText sets the Label's text. func (l *Label) SetText(text string) { l.lock.Lock() @@ -51,6 +64,7 @@ func (l *Label) make(window *sysData) error { l.lock.Lock() defer l.lock.Unlock() + l.sysData.alternate = l.standalone err := l.sysData.make(window) if err != nil { return err diff --git a/sysdata_unix.go b/sysdata_unix.go index 086080c..c7a41f0 100644 --- a/sysdata_unix.go +++ b/sysdata_unix.go @@ -82,6 +82,7 @@ var classTypes = [nctypes]*classData{ }, c_label: &classData{ make: gtk_label_new, + makeAlt: gtk_label_new_standalone, setText: gtk_label_set_text, text: gtk_label_get_text, },