summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--button.go6
-rw-r--r--doc.go3
-rw-r--r--sysdata.go4
-rw-r--r--test/main.go1
-rw-r--r--todo.md1
-rw-r--r--window.go5
6 files changed, 8 insertions, 12 deletions
diff --git a/button.go b/button.go
index 195ebb3..61c9da5 100644
--- a/button.go
+++ b/button.go
@@ -7,8 +7,8 @@ import (
// A Button represents a clickable button with some text.
type Button struct {
- // This channel gets a message when the button is clicked.
- // Unlike other channels in this package, this channel is initialized to non-nil when creating a new button, and cannot be set to nil later.
+ // Clicked gets a message when the button is clicked.
+ // You cannot change it once the Window containing the Button has been opened.
Clicked chan struct{}
lock sync.Mutex
@@ -22,7 +22,7 @@ func NewButton(text string) (b *Button) {
return &Button{
sysData: mksysdata(c_button),
initText: text,
- Clicked: Event(),
+ Clicked: newEvent(),
}
}
diff --git a/doc.go b/doc.go
index d51b8f4..a0a1b01 100644
--- a/doc.go
+++ b/doc.go
@@ -9,8 +9,6 @@ Building GUIs is as simple as creating a Window, populating it with Controls, an
Once a Window is open, you cannot make layout changes.
-At present, you must also hook Window.Closing with ui.Event() to monitor for attempts to close the Window.
-
Once your Window is open, you can begin to handle events. Handling events is simple: because all events are channels exposed as exported members of the Window and Control types, simply select on them.
Here is a simple, complete program that asks the user for their name and greets them after clicking a button.
@@ -22,7 +20,6 @@ Here is a simple, complete program that asks the user for their name and greets
func myMain() {
w := ui.NewWindow("Hello", 400, 100)
- w.Closing = ui.Event()
nameField := ui.NewLineEdit("Enter Your Name Here")
button := ui.NewButton("Click Here For a Greeting")
err := w.Open(ui.NewVerticalStack(nameField, button))
diff --git a/sysdata.go b/sysdata.go
index 2680269..02fda39 100644
--- a/sysdata.go
+++ b/sysdata.go
@@ -7,8 +7,8 @@ import (
const eventbufsiz = 100 // suggested by skelterjohn
-// Event returns a new channel suitable for listening for events.
-func Event() chan struct{} {
+// newEvent returns a new channel suitable for listening for events.
+func newEvent() chan struct{} {
return make(chan struct{}, eventbufsiz)
}
diff --git a/test/main.go b/test/main.go
index 36339ca..fe685cc 100644
--- a/test/main.go
+++ b/test/main.go
@@ -112,7 +112,6 @@ var invalidBefore = flag.Bool("invalid", false, "run invalid test before opening
func myMain() {
w := NewWindow("Main Window", 320, 240)
- w.Closing = Event()
b := NewButton("Click Me")
b2 := NewButton("Or Me")
s2 := NewHorizontalStack(b, b2)
diff --git a/todo.md b/todo.md
index ed72424..3498d6b 100644
--- a/todo.md
+++ b/todo.md
@@ -86,4 +86,3 @@ maybe:
- rename Stack to Box?
- make Combobox and Listbox satisfy sort.Interface?
- should a noneditable Combobox be allowed to return to unselected mode by the user?
-- since all events are dispatched without blocking uitask, don't bother requiring explicit dispatch? remove ui.Event() and make Window.Closing initialized by default; if we don't listen on the channel, nothing will happen
diff --git a/window.go b/window.go
index 946138e..f09116d 100644
--- a/window.go
+++ b/window.go
@@ -8,8 +8,8 @@ import (
// Window represents an on-screen window.
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 gets a message when the user clicks the window's close button.
+ // You cannot change it once the Window has been opened.
Closing chan struct{}
lock sync.Mutex
@@ -27,6 +27,7 @@ func NewWindow(title string, width int, height int) *Window {
initTitle: title,
initWidth: width,
initHeight: height,
+ Closing: newEvent(),
}
}