summaryrefslogtreecommitdiff
path: root/redo/label_windows.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_windows.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_windows.go')
-rw-r--r--redo/label_windows.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/redo/label_windows.go b/redo/label_windows.go
new file mode 100644
index 0000000..e6b3e7f
--- /dev/null
+++ b/redo/label_windows.go
@@ -0,0 +1,68 @@
+// 15 july 2014
+
+package ui
+
+// #include "winapi_windows.h"
+import "C"
+
+type label struct {
+ *controlbase
+ standalone bool
+ supercommitResize func(c *allocation, d *sizing)
+}
+
+var labelclass = toUTF16("STATIC")
+
+func finishNewLabel(text string, standalone bool) *label {
+ c := newControl(labelclass,
+ // SS_NOPREFIX avoids accelerator translation; SS_LEFTNOWORDWRAP clips text past the end
+ // controls are vertically aligned to the top by default (thanks Xeek in irc.freenode.net/#winapi)
+ C.SS_NOPREFIX | C.SS_LEFTNOWORDWRAP,
+ 0)
+ c.setText(text)
+ C.controlSetControlFont(c.hwnd)
+ l := &label{
+ controlbase: c,
+ standalone: standalone,
+ }
+ l.fpreferredSize = l.labelpreferredSize
+ 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 l.text()
+}
+
+func (l *label) SetText(text string) {
+ l.setText(text)
+}
+
+const (
+ // via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
+ labelHeight = 8
+ labelYOffset = 3
+ // TODO the label is offset slightly by default...
+)
+
+func (l *label) labelpreferredSize(d *sizing) (width, height int) {
+ return int(l.textlen), fromdlgunitsY(labelHeight, d)
+}
+
+func (l *label) labelcommitResize(c *allocation, d *sizing) {
+ if !l.standalone {
+ yoff := fromdlgunitsY(labelYOffset, d)
+ c.y += yoff
+ c.height -= yoff
+ }
+ l.supercommitResize(c, d)
+}