Added initial window size and the Window.SetTitle() function.
This commit is contained in:
parent
3f8fe0e710
commit
49d0375975
2
main.go
2
main.go
|
@ -2,7 +2,7 @@
|
|||
package main
|
||||
|
||||
func main() {
|
||||
w := NewWindow("Main Window")
|
||||
w := NewWindow("Main Window", 320, 240)
|
||||
w.Closing = make(chan struct{})
|
||||
err := w.Open()
|
||||
if err != nil {
|
||||
|
|
|
@ -12,7 +12,7 @@ type cSysData struct {
|
|||
// for Window
|
||||
closing chan struct{}
|
||||
}
|
||||
func (c *cSysData) make(initText string) error {
|
||||
func (c *cSysData) make(initText string, initWidth int, initHeight int) error {
|
||||
panic(runtime.GOOS + " sysData does not define make()")
|
||||
}
|
||||
func (c *cSysData) show() error {
|
||||
|
|
|
@ -52,7 +52,7 @@ func nextID() _HMENU {
|
|||
return cid
|
||||
}
|
||||
|
||||
func (s *sysData) make(initText string) (err error) {
|
||||
func (s *sysData) make(initText string, initWidth int, initHeight int) (err error) {
|
||||
ret := make(chan uiret)
|
||||
defer close(ret)
|
||||
ct := classTypes[s.ctype]
|
||||
|
@ -68,8 +68,8 @@ func (s *sysData) make(initText string) (err error) {
|
|||
uintptr(ct.style),
|
||||
uintptr(_CW_USEDEFAULT), // TODO
|
||||
uintptr(_CW_USEDEFAULT),
|
||||
uintptr(_CW_USEDEFAULT),
|
||||
uintptr(_CW_USEDEFAULT),
|
||||
uintptr(initWidth),
|
||||
uintptr(initHeight),
|
||||
uintptr(_NULL), // TODO parent
|
||||
uintptr(s.cid),
|
||||
uintptr(hInstance),
|
||||
|
|
39
window.go
39
window.go
|
@ -18,18 +18,22 @@ type Window struct {
|
|||
created bool
|
||||
control Control
|
||||
sysData *sysData
|
||||
initText string
|
||||
initTitle string
|
||||
initWidth int
|
||||
initHeight int
|
||||
}
|
||||
|
||||
// NewWindow creates a new window with the given title. The window is not constructed at the OS level until a call to Open().
|
||||
func NewWindow(title string) *Window {
|
||||
// NewWindow creates a new window with the given title and size. The window is not constructed at the OS level until a call to Open().
|
||||
func NewWindow(title string, width int, height int) *Window {
|
||||
return &Window{
|
||||
sysData: &sysData{
|
||||
cSysData: cSysData{
|
||||
ctype: c_window,
|
||||
},
|
||||
},
|
||||
initText: title,
|
||||
initTitle: title,
|
||||
initWidth: width,
|
||||
initHeight: height,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,6 +51,31 @@ func (w *Window) SetControl(control Control) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// SetTitle sets the window's title.
|
||||
func (w *Window) SetTitle(title string) (err error) {
|
||||
w.lock.Lock()
|
||||
defer w.lock.Unlock()
|
||||
|
||||
if w.created {
|
||||
panic("TODO")
|
||||
}
|
||||
w.initTitle = title
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetSize sets the window's size.
|
||||
func (w *Window) SetSize(width int, height int) (err error) {
|
||||
w.lock.Lock()
|
||||
defer w.lock.Unlock()
|
||||
|
||||
if w.created {
|
||||
panic("TODO")
|
||||
}
|
||||
w.initWidth = width
|
||||
w.initHeight = height
|
||||
return nil
|
||||
}
|
||||
|
||||
// Open opens the window. If the OS window has not been created yet, this function will.
|
||||
func (w *Window) Open() (err error) {
|
||||
w.lock.Lock()
|
||||
|
@ -55,7 +84,7 @@ func (w *Window) Open() (err error) {
|
|||
// If the window has already been created, show it.
|
||||
if !w.created {
|
||||
w.sysData.closing = w.Closing
|
||||
err = w.sysData.make(w.initText)
|
||||
err = w.sysData.make(w.initTitle, w.initWidth, w.initHeight)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue