Set up restrictions tracking. Added a restriction that a window and its controls are fixed to the window once it has been open. Started accounting for parent windows in controls.
This commit is contained in:
parent
0f373195de
commit
e9e2c0f269
|
@ -9,6 +9,6 @@ import (
|
||||||
// A Control represents an UI control. Note that Control contains unexported members; this has the consequence that you can't build custom controls that interface directly with the system-specific code (fo rinstance, to import an unsupported control), or at least not without some hackery. If you want to make your own controls, embed Area and provide its necessities.
|
// A Control represents an UI control. Note that Control contains unexported members; this has the consequence that you can't build custom controls that interface directly with the system-specific code (fo rinstance, to import an unsupported control), or at least not without some hackery. If you want to make your own controls, embed Area and provide its necessities.
|
||||||
type Control interface {
|
type Control interface {
|
||||||
apply() error
|
apply() error
|
||||||
unapply() error
|
|
||||||
setParent(c Control)
|
setParent(c Control)
|
||||||
|
setParentWindow(w *Window)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
This is a file to keep track of API restrictions that simplify the implementation of the package. I would like to eliminate them, but...
|
||||||
|
|
||||||
|
- Once you open a window, the controls are finalized: you cannot change the window's control or add/remove controls to layouts.
|
||||||
|
- Once you open a window, you cannot change its event channels or its controls's event channels.
|
||||||
|
- [Windows] At most 65535 controls can be made, period. This is because child window IDs are alloted by the UI library application-global, not window-local, and BN_CLICKED only stores the control ID in a word (and I start counting at 1 to be safe). If I keep the first restriction and amend it such that you can only set the control of a window at the time of first open (somehow; split create and open?), I can easily make them window-local.
|
22
window.go
22
window.go
|
@ -32,23 +32,17 @@ func NewWindow(title string) *Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetControl sets the window's central control to control.
|
// SetControl sets the window's central control to control. This function cannot be called once the window has been opened.
|
||||||
func (w *Window) SetControl(control Control) (err error) {
|
func (w *Window) SetControl(control Control) (err error) {
|
||||||
w.lock.Lock()
|
w.lock.Lock()
|
||||||
defer w.lock.Unlock()
|
defer w.lock.Unlock()
|
||||||
|
|
||||||
w.control = control
|
|
||||||
err = w.control.unapply()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.control.setParent(w)
|
|
||||||
if w.created {
|
if w.created {
|
||||||
err = w.control.apply()
|
panic("cannot set window control after window has been opened")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
w.control = control
|
||||||
|
w.control.setParent(w)
|
||||||
|
w.control.setParentWindow(w)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,9 +79,9 @@ func (w *Window) Close() (err error) {
|
||||||
func (w *Window) apply() error {
|
func (w *Window) apply() error {
|
||||||
panic("Window.apply() should never be called")
|
panic("Window.apply() should never be called")
|
||||||
}
|
}
|
||||||
func (w *Window) unapply() error {
|
|
||||||
panic("Window.unapply() should never be called")
|
|
||||||
}
|
|
||||||
func (w *Window) setParent(c Control) {
|
func (w *Window) setParent(c Control) {
|
||||||
panic("Window.setParent() should never be called")
|
panic("Window.setParent() should never be called")
|
||||||
}
|
}
|
||||||
|
func (w *Window) setParentWindow(w *Window) {
|
||||||
|
panic("Window.setParent() should never be called")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue