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
|
package main
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
w := NewWindow("Main Window")
|
w := NewWindow("Main Window", 320, 240)
|
||||||
w.Closing = make(chan struct{})
|
w.Closing = make(chan struct{})
|
||||||
err := w.Open()
|
err := w.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -12,7 +12,7 @@ type cSysData struct {
|
||||||
// for Window
|
// for Window
|
||||||
closing chan struct{}
|
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()")
|
panic(runtime.GOOS + " sysData does not define make()")
|
||||||
}
|
}
|
||||||
func (c *cSysData) show() error {
|
func (c *cSysData) show() error {
|
||||||
|
|
|
@ -52,7 +52,7 @@ func nextID() _HMENU {
|
||||||
return cid
|
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)
|
ret := make(chan uiret)
|
||||||
defer close(ret)
|
defer close(ret)
|
||||||
ct := classTypes[s.ctype]
|
ct := classTypes[s.ctype]
|
||||||
|
@ -68,8 +68,8 @@ func (s *sysData) make(initText string) (err error) {
|
||||||
uintptr(ct.style),
|
uintptr(ct.style),
|
||||||
uintptr(_CW_USEDEFAULT), // TODO
|
uintptr(_CW_USEDEFAULT), // TODO
|
||||||
uintptr(_CW_USEDEFAULT),
|
uintptr(_CW_USEDEFAULT),
|
||||||
uintptr(_CW_USEDEFAULT),
|
uintptr(initWidth),
|
||||||
uintptr(_CW_USEDEFAULT),
|
uintptr(initHeight),
|
||||||
uintptr(_NULL), // TODO parent
|
uintptr(_NULL), // TODO parent
|
||||||
uintptr(s.cid),
|
uintptr(s.cid),
|
||||||
uintptr(hInstance),
|
uintptr(hInstance),
|
||||||
|
|
51
window.go
51
window.go
|
@ -12,24 +12,28 @@ import (
|
||||||
type Window struct {
|
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.
|
// 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.
|
// This channel can only be set before initially opening the window.
|
||||||
Closing chan struct{}
|
Closing chan struct{}
|
||||||
|
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
created bool
|
created bool
|
||||||
control Control
|
control Control
|
||||||
sysData *sysData
|
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().
|
// 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) *Window {
|
func NewWindow(title string, width int, height int) *Window {
|
||||||
return &Window{
|
return &Window{
|
||||||
sysData: &sysData{
|
sysData: &sysData{
|
||||||
cSysData: cSysData{
|
cSysData: cSysData{
|
||||||
ctype: c_window,
|
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
|
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.
|
// Open opens the window. If the OS window has not been created yet, this function will.
|
||||||
func (w *Window) Open() (err error) {
|
func (w *Window) Open() (err error) {
|
||||||
w.lock.Lock()
|
w.lock.Lock()
|
||||||
|
@ -55,7 +84,7 @@ func (w *Window) Open() (err error) {
|
||||||
// If the window has already been created, show it.
|
// If the window has already been created, show it.
|
||||||
if !w.created {
|
if !w.created {
|
||||||
w.sysData.closing = w.Closing
|
w.sysData.closing = w.Closing
|
||||||
err = w.sysData.make(w.initText)
|
err = w.sysData.make(w.initTitle, w.initWidth, w.initHeight)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue