summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-02-12 10:29:56 -0500
committerPietro Gagliardi <[email protected]>2014-02-12 10:29:56 -0500
commite9e2c0f269aac1157a3ea6a6021a86869fdd6888 (patch)
tree7edd6ae853fd47ea09972833bd74b3239674fcfa
parent0f373195de316b1b20a05ebff1463fb8a56b1f1b (diff)
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.
-rw-r--r--control.go2
-rw-r--r--restrictions.md5
-rw-r--r--window.go22
3 files changed, 14 insertions, 15 deletions
diff --git a/control.go b/control.go
index 40ce61a..b0a79a0 100644
--- a/control.go
+++ b/control.go
@@ -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.
type Control interface {
apply() error
- unapply() error
setParent(c Control)
+ setParentWindow(w *Window)
}
diff --git a/restrictions.md b/restrictions.md
new file mode 100644
index 0000000..11466f8
--- /dev/null
+++ b/restrictions.md
@@ -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.
diff --git a/window.go b/window.go
index 8fb7ff8..50d4dbb 100644
--- a/window.go
+++ b/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) {
w.lock.Lock()
defer w.lock.Unlock()
- w.control = control
- err = w.control.unapply()
- if err != nil {
- return err
- }
- w.control.setParent(w)
if w.created {
- err = w.control.apply()
- if err != nil {
- return err
- }
+ panic("cannot set window control after window has been opened")
}
+ w.control = control
+ w.control.setParent(w)
+ w.control.setParentWindow(w)
return nil
}
@@ -85,9 +79,9 @@ func (w *Window) Close() (err error) {
func (w *Window) apply() error {
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) {
panic("Window.setParent() should never be called")
}
+func (w *Window) setParentWindow(w *Window) {
+ panic("Window.setParent() should never be called")
+}