diff options
| author | Pietro Gagliardi <[email protected]> | 2014-07-01 08:51:19 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-07-01 08:51:19 -0400 |
| commit | f4963e909bd1512b30de8d05e9a064183df5fdc8 (patch) | |
| tree | 15d212da4de79aaebaf39c9cf6c1b03b147df711 /button.go | |
| parent | 3565889e15e387fce435c3ffadeaea9823fb2eed (diff) | |
Made Button.Clicked a callback.
Diffstat (limited to 'button.go')
| -rw-r--r-- | button.go | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -4,6 +4,11 @@ package ui // A Button represents a clickable button with some text. type Button struct { + // Clicked is called when the button is clicked. + // This cannot be changed after the Window containing the Button has been created. + // If you do not specify a handler, a default of "do nothing" will be used instead. + Clicked func() + created bool sysData *sysData initText string @@ -35,8 +40,9 @@ func (b *Button) Text() string { } func (b *Button) make(window *sysData) error { - b.sysData.event = func() { - window.winhandler.Event(Clicked, b) + b.sysData.event = b.Clicked + if b.sysData.event == nil { + b.sysData.event = func() {} } err := b.sysData.make(window) if err != nil { @@ -49,11 +55,11 @@ func (b *Button) make(window *sysData) error { func (b *Button) allocate(x int, y int, width int, height int, d *sysSizeData) []*allocation { return []*allocation{&allocation{ - x: x, - y: y, - width: width, - height: height, - this: b, + x: x, + y: y, + width: width, + height: height, + this: b, }} } |
