2014-10-14 14:29:59 -05:00
|
|
|
// 15 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
// #include "winapi_windows.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type label struct {
|
|
|
|
*controlSingleHWNDWithText
|
|
|
|
standalone bool
|
|
|
|
}
|
|
|
|
|
|
|
|
var labelclass = toUTF16("STATIC")
|
|
|
|
|
2014-10-15 12:30:35 -05:00
|
|
|
func newLabel(text string) Label {
|
2014-10-14 14:29:59 -05:00
|
|
|
hwnd := 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,
|
|
|
|
C.WS_EX_TRANSPARENT)
|
|
|
|
l := &label{
|
|
|
|
controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
|
|
|
|
}
|
|
|
|
l.fpreferredSize = l.preferredSize
|
2014-10-16 17:41:17 -05:00
|
|
|
l.fnTabStops = func() int {
|
|
|
|
// labels are not tab stops
|
|
|
|
return 0
|
|
|
|
}
|
2014-10-14 14:29:59 -05:00
|
|
|
l.SetText(text)
|
|
|
|
C.controlSetControlFont(l.hwnd)
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
|
|
|
func (l *label) preferredSize(d *sizing) (width, height int) {
|
2014-10-16 14:16:11 -05:00
|
|
|
return int(l.textlen), fromdlgunitsY(labelHeight, d)
|
2014-10-14 14:29:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*TODO
|
|
|
|
func (l *label) commitResize(c *allocation, d *sizing) {
|
|
|
|
if !l.standalone {
|
|
|
|
yoff := fromdlgunitsY(labelYOffset, d)
|
|
|
|
c.y += yoff
|
|
|
|
c.height -= yoff
|
|
|
|
// by default, labels are drawn offset by the internal leading (the space reserved for accents on uppercase letters)
|
|
|
|
// the above calculation assumes otherwise, so account for the difference
|
|
|
|
// there will be enough space left over for the internal leading anyway (at least on the standard fonts)
|
|
|
|
// don't do this to standalone labels, otherwise those accents get cut off!
|
|
|
|
c.y -= int(d.internalLeading)
|
|
|
|
c.height += int(d.internalLeading)
|
|
|
|
}
|
|
|
|
basecommitResize(l, c, d)
|
|
|
|
}
|
|
|
|
*/
|