From 5d339e656b66d00356960ae057969532d34245b4 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 2 Jul 2014 17:13:40 -0400 Subject: Moved everything out of the way pending rewrite. --- prevlib/button.go | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 prevlib/button.go (limited to 'prevlib/button.go') diff --git a/prevlib/button.go b/prevlib/button.go new file mode 100644 index 0000000..465427a --- /dev/null +++ b/prevlib/button.go @@ -0,0 +1,76 @@ +// 12 february 2014 + +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 +} + +// NewButton creates a new button with the specified text. +func NewButton(text string) (b *Button) { + return &Button{ + sysData: mksysdata(c_button), + initText: text, + } +} + +// SetText sets the button's text. +func (b *Button) SetText(text string) { + if b.created { + b.sysData.setText(text) + return + } + b.initText = text +} + +// Text returns the button's text. +func (b *Button) Text() string { + if b.created { + return b.sysData.text() + } + return b.initText +} + +func (b *Button) make(window *sysData) error { + b.sysData.event = b.Clicked + if b.sysData.event == nil { + b.sysData.event = func() {} + } + err := b.sysData.make(window) + if err != nil { + return err + } + b.sysData.setText(b.initText) + b.created = true + return nil +} + +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, + }} +} + +func (b *Button) preferredSize(d *sysSizeData) (width int, height int) { + return b.sysData.preferredSize(d) +} + +func (b *Button) commitResize(a *allocation, d *sysSizeData) { + b.sysData.commitResize(a, d) +} + +func (b *Button) getAuxResizeInfo(d *sysSizeData) { + b.sysData.getAuxResizeInfo(d) +} -- cgit v1.2.3