2014-08-02 21:35:58 -05:00
|
|
|
// 15 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
// #include "winapi_windows.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type label struct {
|
2014-08-03 20:52:21 -05:00
|
|
|
_hwnd C.HWND
|
|
|
|
_textlen C.LONG
|
2014-08-03 08:18:35 -05:00
|
|
|
standalone bool
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var labelclass = toUTF16("STATIC")
|
|
|
|
|
|
|
|
func finishNewLabel(text string, standalone bool) *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)
|
|
|
|
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-08-03 20:52:21 -05:00
|
|
|
_hwnd: hwnd,
|
2014-08-02 21:35:58 -05:00
|
|
|
standalone: standalone,
|
|
|
|
}
|
2014-08-03 20:52:21 -05:00
|
|
|
l.SetText(text)
|
|
|
|
C.controlSetControlFont(l._hwnd)
|
2014-08-02 21:35:58 -05:00
|
|
|
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 {
|
2014-08-03 20:52:21 -05:00
|
|
|
return baseText(l)
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *label) SetText(text string) {
|
2014-08-03 20:52:21 -05:00
|
|
|
baseSetText(l, text)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *label) hwnd() C.HWND {
|
|
|
|
return l._hwnd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *label) textlen() C.LONG {
|
|
|
|
return l._textlen
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *label) settextlen(len C.LONG) {
|
|
|
|
l._textlen = len
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
2014-08-03 08:18:35 -05:00
|
|
|
func (l *label) setParent(p *controlParent) {
|
2014-08-14 12:05:31 -05:00
|
|
|
C.controlSetParent(l.hwnd(), p.c.hwnd)
|
|
|
|
// don't increment p.c.nchildren here because Labels aren't tab stops
|
2014-08-03 08:18:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *label) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
|
|
|
return baseallocate(l, x, y, width, height, d)
|
|
|
|
}
|
|
|
|
|
2014-08-02 21:35:58 -05:00
|
|
|
const (
|
|
|
|
// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
|
|
|
labelHeight = 8
|
|
|
|
labelYOffset = 3
|
|
|
|
)
|
|
|
|
|
2014-08-03 08:18:35 -05:00
|
|
|
func (l *label) preferredSize(d *sizing) (width, height int) {
|
2014-08-03 20:52:21 -05:00
|
|
|
return int(l._textlen), fromdlgunitsY(labelHeight, d)
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func (l *label) getAuxResizeInfo(d *sizing) {
|
2014-08-03 19:42:45 -05:00
|
|
|
basegetAuxResizeInfo(l, d)
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|