Added initial window size and the Window.SetTitle() function.

This commit is contained in:
Pietro Gagliardi 2014-02-12 10:51:27 -05:00
parent 3f8fe0e710
commit 49d0375975
4 changed files with 45 additions and 16 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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),

View File

@ -12,24 +12,28 @@ import (
type Window struct {
// If this channel is non-nil, the event loop will receive on this when the user clicks the window's close button.
// This channel can only be set before initially opening the window.
Closing chan struct{}
Closing chan struct{}
lock sync.Mutex
created bool
control Control
sysData *sysData
initText string
lock sync.Mutex
created bool
control Control
sysData *sysData
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{
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
}