Added labels.

This commit is contained in:
Pietro Gagliardi 2014-02-14 15:12:03 -05:00
parent 681afdf0ad
commit 9070eae214
5 changed files with 89 additions and 42 deletions

View File

@ -371,54 +371,54 @@ const (
LBN_SETFOCUS = 4 LBN_SETFOCUS = 4
LBN_KILLFOCUS = 5 LBN_KILLFOCUS = 5
) )
*/
// Static control styles. // Static control styles.
const ( const (
// from winuser.h // from winuser.h
SS_LEFT = 0x00000000 _SS_LEFT = 0x00000000
SS_CENTER = 0x00000001 _SS_CENTER = 0x00000001
SS_RIGHT = 0x00000002 _SS_RIGHT = 0x00000002
SS_ICON = 0x00000003 _SS_ICON = 0x00000003
SS_BLACKRECT = 0x00000004 _SS_BLACKRECT = 0x00000004
SS_GRAYRECT = 0x00000005 _SS_GRAYRECT = 0x00000005
SS_WHITERECT = 0x00000006 _SS_WHITERECT = 0x00000006
SS_BLACKFRAME = 0x00000007 _SS_BLACKFRAME = 0x00000007
SS_GRAYFRAME = 0x00000008 _SS_GRAYFRAME = 0x00000008
SS_WHITEFRAME = 0x00000009 _SS_WHITEFRAME = 0x00000009
SS_USERITEM = 0x0000000A _SS_USERITEM = 0x0000000A
SS_SIMPLE = 0x0000000B _SS_SIMPLE = 0x0000000B
SS_LEFTNOWORDWRAP = 0x0000000C _SS_LEFTNOWORDWRAP = 0x0000000C
SS_OWNERDRAW = 0x0000000D _SS_OWNERDRAW = 0x0000000D
SS_BITMAP = 0x0000000E _SS_BITMAP = 0x0000000E
SS_ENHMETAFILE = 0x0000000F _SS_ENHMETAFILE = 0x0000000F
SS_ETCHEDHORZ = 0x00000010 _SS_ETCHEDHORZ = 0x00000010
SS_ETCHEDVERT = 0x00000011 _SS_ETCHEDVERT = 0x00000011
SS_ETCHEDFRAME = 0x00000012 _SS_ETCHEDFRAME = 0x00000012
SS_TYPEMASK = 0x0000001F _SS_TYPEMASK = 0x0000001F
SS_REALSIZECONTROL = 0x00000040 _SS_REALSIZECONTROL = 0x00000040
SS_NOPREFIX = 0x00000080 _SS_NOPREFIX = 0x00000080
SS_NOTIFY = 0x00000100 _SS_NOTIFY = 0x00000100
SS_CENTERIMAGE = 0x00000200 _SS_CENTERIMAGE = 0x00000200
SS_RIGHTJUST = 0x00000400 _SS_RIGHTJUST = 0x00000400
SS_REALSIZEIMAGE = 0x00000800 _SS_REALSIZEIMAGE = 0x00000800
SS_SUNKEN = 0x00001000 _SS_SUNKEN = 0x00001000
SS_EDITCONTROL = 0x00002000 _SS_EDITCONTROL = 0x00002000
SS_ENDELLIPSIS = 0x00004000 _SS_ENDELLIPSIS = 0x00004000
SS_PATHELLIPSIS = 0x00008000 _SS_PATHELLIPSIS = 0x00008000
SS_WORDELLIPSIS = 0x0000C000 _SS_WORDELLIPSIS = 0x0000C000
SS_ELLIPSISMASK = 0x0000C000 _SS_ELLIPSISMASK = 0x0000C000
) )
// Static control messages and WM_COMMAND notifications. // Static control messages and WM_COMMAND notifications.
const ( const (
// from winuser.h // from winuser.h
STM_SETICON = 0x0170 _STM_SETICON = 0x0170
STM_GETICON = 0x0171 _STM_GETICON = 0x0171
STM_SETIMAGE = 0x0172 _STM_SETIMAGE = 0x0172
STM_GETIMAGE = 0x0173 _STM_GETIMAGE = 0x0173
STN_CLICKED = 0 _STN_CLICKED = 0
STN_DBLCLK = 1 _STN_DBLCLK = 1
STN_ENABLE = 2 _STN_ENABLE = 2
STN_DISABLE = 3 _STN_DISABLE = 3
) )
*/

40
label.go Normal file
View File

@ -0,0 +1,40 @@
// 14 february 2014
//package ui
package main
import (
"sync"
)
// A Label is a static line of text used to mark other controls.
type Label struct {
lock sync.Mutex
created bool
sysData *sysData
initText string
}
// NewLabel creates a new Label with the specified text.
func NewLabel(text string) *Label {
return &Label{
sysData: mksysdata(c_label),
initText: text,
}
}
// TODO SetText()/Text()?
// TODO adorn error messages
func (l *Label) make(window *sysData) error {
l.lock.Lock()
defer l.lock.Unlock()
return l.sysData.make(l.initText, 300, 300, window)
}
func (l *Label) setRect(x int, y int, width int, height int) error {
l.lock.Lock()
defer l.lock.Unlock()
return l.sysData.setRect(x, y, width, height)
}

View File

@ -13,7 +13,8 @@ func main() {
cb1 := NewCombobox(true, "You can edit me!", "Yes you can!", "Yes you will!") cb1 := NewCombobox(true, "You can edit me!", "Yes you can!", "Yes you will!")
cb2 := NewCombobox(false, "You can't edit me!", "No you can't!", "No you won't!") cb2 := NewCombobox(false, "You can't edit me!", "No you can't!", "No you won't!")
e := NewLineEdit("Enter text here too") e := NewLineEdit("Enter text here too")
s := NewStack(Vertical, b, c, cb1, cb2, e) l := NewLabel("This is a label")
s := NewStack(Vertical, b, c, cb1, cb2, e, l)
err := w.Open(s) err := w.Open(s)
if err != nil { if err != nil {
panic(err) panic(err)

View File

@ -44,6 +44,7 @@ const (
c_checkbox c_checkbox
c_combobox c_combobox
c_lineedit c_lineedit
c_label
nctypes nctypes
) )

View File

@ -61,6 +61,11 @@ var classTypes = [nctypes]*classData{
style: _ES_AUTOHSCROLL | _WS_BORDER | controlstyle, style: _ES_AUTOHSCROLL | _WS_BORDER | controlstyle,
xstyle: 0 | controlxstyle, xstyle: 0 | controlxstyle,
}, },
c_label: &classData{
name: "STATIC",
style: _SS_NOPREFIX | controlstyle,
xstyle: 0 | controlxstyle,
},
} }
func (s *sysData) addChild(child *sysData) _HMENU { func (s *sysData) addChild(child *sysData) _HMENU {