2014-08-02 21:35:58 -05:00
|
|
|
// 15 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
// #include "winapi_windows.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type label struct {
|
2014-10-18 16:03:07 -05:00
|
|
|
*controlSingleHWNDWithText
|
2014-10-02 09:05:53 -05:00
|
|
|
standalone bool
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var labelclass = toUTF16("STATIC")
|
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
func newLabel(text string) Label {
|
2014-08-03 20:52:21 -05:00
|
|
|
hwnd := C.newControl(labelclass,
|
2014-08-02 21:35:58 -05:00
|
|
|
// 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)
|
2014-10-02 09:05:53 -05:00
|
|
|
C.SS_NOPREFIX|C.SS_LEFTNOWORDWRAP,
|
2014-08-14 16:13:52 -05:00
|
|
|
C.WS_EX_TRANSPARENT)
|
2014-08-02 21:35:58 -05:00
|
|
|
l := &label{
|
2014-10-18 16:03:07 -05:00
|
|
|
controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
|
|
|
|
}
|
|
|
|
l.fpreferredSize = l.xpreferredSize
|
|
|
|
l.fnTabStops = func() int {
|
|
|
|
// labels are not tab stops
|
|
|
|
return 0
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
2014-08-03 20:52:21 -05:00
|
|
|
l.SetText(text)
|
2014-10-18 16:03:07 -05:00
|
|
|
C.controlSetControlFont(l.hwnd)
|
2014-08-02 21:35:58 -05:00
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *label) Text() string {
|
2014-10-18 16:03:07 -05:00
|
|
|
return l.text()
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *label) SetText(text string) {
|
2014-10-18 16:03:07 -05:00
|
|
|
l.setText(text)
|
2014-08-03 08:18:35 -05:00
|
|
|
}
|
|
|
|
|
2014-08-02 21:35:58 -05:00
|
|
|
const (
|
|
|
|
// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
2014-10-02 09:05:53 -05:00
|
|
|
labelHeight = 8
|
2014-08-02 21:35:58 -05:00
|
|
|
labelYOffset = 3
|
|
|
|
)
|
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
func (l *label) xpreferredSize(d *sizing) (width, height int) {
|
|
|
|
return int(l.textlen), fromdlgunitsY(labelHeight, d)
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
/*TODO
|
2014-08-03 08:18:35 -05:00
|
|
|
func (l *label) commitResize(c *allocation, d *sizing) {
|
2014-08-02 21:35:58 -05:00
|
|
|
if !l.standalone {
|
|
|
|
yoff := fromdlgunitsY(labelYOffset, d)
|
|
|
|
c.y += yoff
|
|
|
|
c.height -= yoff
|
2014-08-08 23:28:12 -05:00
|
|
|
// 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)
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
2014-08-03 20:52:21 -05:00
|
|
|
basecommitResize(l, c, d)
|
2014-08-03 08:18:35 -05:00
|
|
|
}
|
2014-10-18 16:03:07 -05:00
|
|
|
*/
|