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,
|
|
|
|
0)
|
|
|
|
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-03 20:52:21 -05:00
|
|
|
basesetParent(l, p)
|
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
|
|
|
|
// TODO the label is offset slightly by default...
|
|
|
|
)
|
|
|
|
|
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-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
|
|
|
}
|