summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-02-12 10:51:27 -0500
committerPietro Gagliardi <[email protected]>2014-02-12 10:51:27 -0500
commit49d0375975b81d0e09120455548370d1a1a9f387 (patch)
treeb8000ccd98b2dfe5fe19b158a7eb9643b3c24111
parent3f8fe0e7108c1cd87e177bed22e3307c9df03e63 (diff)
Added initial window size and the Window.SetTitle() function.
-rw-r--r--main.go2
-rw-r--r--sysdata.go2
-rw-r--r--sysdata_windows.go6
-rw-r--r--window.go51
4 files changed, 45 insertions, 16 deletions
diff --git a/main.go b/main.go
index e1ff2a1..70caf80 100644
--- a/main.go
+++ b/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 {
diff --git a/sysdata.go b/sysdata.go
index b17f506..824df0c 100644
--- a/sysdata.go
+++ b/sysdata.go
@@ -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 {
diff --git a/sysdata_windows.go b/sysdata_windows.go
index 2d0796e..554ae19 100644
--- a/sysdata_windows.go
+++ b/sysdata_windows.go
@@ -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),
diff --git a/window.go b/window.go
index 77dc674..b5971c6 100644
--- a/window.go
+++ b/window.go
@@ -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
}