2014-08-02 21:35:58 -05:00
|
|
|
// 15 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
// #include "winapi_windows.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type label struct {
|
|
|
|
*controlbase
|
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 {
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2014-08-03 08:18:35 -05:00
|
|
|
func (l *label) setParent(p *controlParent) {
|
|
|
|
basesetParent(l.controlbase, p)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *label) containerShow() {
|
|
|
|
basecontainerShow(l.controlbase)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *label) containerHide() {
|
|
|
|
basecontainerHide(l.controlbase)
|
|
|
|
}
|
|
|
|
|
|
|
|
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-02 21:35:58 -05:00
|
|
|
return int(l.textlen), fromdlgunitsY(labelHeight, d)
|
|
|
|
}
|
|
|
|
|
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 08:18:35 -05:00
|
|
|
basecommitResize(l.controlbase, c, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *label) getAuxResizeInfo(d *sizing) {
|
|
|
|
basegetAuxResizeInfo(d)
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|