diff options
Diffstat (limited to 'AAA_GOFILES')
| -rw-r--r-- | AAA_GOFILES/box.go | 121 | ||||
| -rw-r--r-- | AAA_GOFILES/button.go | 114 | ||||
| -rw-r--r-- | AAA_GOFILES/checkbox.go | 124 | ||||
| -rw-r--r-- | AAA_GOFILES/combobox.go | 116 | ||||
| -rw-r--r-- | AAA_GOFILES/datetimepicker.go | 160 | ||||
| -rw-r--r-- | AAA_GOFILES/editablecombobox.go | 120 |
6 files changed, 755 insertions, 0 deletions
diff --git a/AAA_GOFILES/box.go b/AAA_GOFILES/box.go new file mode 100644 index 0000000..caf49e3 --- /dev/null +++ b/AAA_GOFILES/box.go @@ -0,0 +1,121 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "ui.h" +import "C" + +// Box is a Control that holds a group of Controls horizontally +// or vertically. If horizontally, then all controls have the same +// height. If vertically, then all controls have the same width. +// By default, each control has its preferred width (horizontal) +// or height (vertical); if a control is marked "stretchy", it will +// take whatever space is left over. If multiple controls are marked +// stretchy, they will be given equal shares of the leftover space. +// There can also be space between each control ("padding"). +type Box struct { + c *C.uiControl + b *C.uiBox + + children []Control +} + +// NewHorizontalBox creates a new horizontal Box. +func NewHorizontalBox() *Box { + b := new(Box) + + b.b = C.uiNewHorizontalBox() + b.c = (*C.uiControl)(unsafe.Pointer(b.b)) + + return b +} + +// NewVerticalBox creates a new vertical Box. +func NewVerticalBox() *Box { + b := new(Box) + + b.b = C.uiNewVerticalBox() + b.c = (*C.uiControl)(unsafe.Pointer(b.b)) + + return b +} + +// Destroy destroys the Box. If the Box has children, +// Destroy calls Destroy on those Controls as well. +func (b *Box) Destroy() { + for len(b.children) != 0 { + c := b.children[0] + b.Delete(0) + c.Destroy() + } + C.uiControlDestroy(b.c) +} + +// LibuiControl returns the libui uiControl pointer that backs +// the Box. This is only used by package ui itself and should +// not be called by programs. +func (b *Box) LibuiControl() uintptr { + return uintptr(unsafe.Pointer(b.c)) +} + +// Handle returns the OS-level handle associated with this Box. +// On Windows this is an HWND of a libui-internal class. +// On GTK+ this is a pointer to a GtkBox. +// On OS X this is a pointer to a NSView. +func (b *Box) Handle() uintptr { + return uintptr(C.uiControlHandle(b.c)) +} + +// Show shows the Box. +func (b *Box) Show() { + C.uiControlShow(b.c) +} + +// Hide hides the Box. +func (b *Box) Hide() { + C.uiControlHide(b.c) +} + +// Enable enables the Box. +func (b *Box) Enable() { + C.uiControlEnable(b.c) +} + +// Disable disables the Box. +func (b *Box) Disable() { + C.uiControlDisable(b.c) +} + +// Append adds the given control to the end of the Box. +func (b *Box) Append(child Control, stretchy bool) { + c := (*C.uiControl)(nil) + if child != nil { + c = touiControl(child.LibuiControl()) + } + C.uiBoxAppend(b.b, c, frombool(stretchy)) + b.children = append(b.children, child) +} + +// Delete deletes the nth control of the Box. +func (b *Box) Delete(n int) { + b.children = append(b.children[:n], b.children[n + 1:]...) + // TODO why is this uintmax_t instead of intmax_t + C.uiBoxDelete(b.b, C.uintmax_t(n)) +} + +// Padded returns whether there is space between each control +// of the Box. +func (b *Box) Padded() bool { + return tobool(C.uiBoxPadded(b.b)) +} + +// SetPadded controls whether there is space between each control +// of the Box. The size of the padding is determined by the OS and +// its best practices. +func (b *Box) SetPadded(padded bool) { + C.uiBoxSetPadded(b.b, frombool(padded)) +} diff --git a/AAA_GOFILES/button.go b/AAA_GOFILES/button.go new file mode 100644 index 0000000..2696f82 --- /dev/null +++ b/AAA_GOFILES/button.go @@ -0,0 +1,114 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "ui.h" +// extern void doButtonOnClicked(uiButton *, void *); +// static inline void realuiButtonOnClicked(uiButton *b) +// { +// uiButtonOnClicked(b, doButtonOnClicked, NULL); +// } +import "C" + +// no need to lock this; only the GUI thread can access it +var buttons = make(map[*C.uiButton]*Button) + +// Button is a Control that represents a button that the user can +// click to perform an action. A Button has a text label that should +// describe what the button does. +type Button struct { + c *C.uiControl + b *C.uiButton + + onClicked func(*Button) +} + +// NewButton creates a new Button with the given text as its label. +func NewButton(text string) *Button { + b := new(Button) + + ctext := C.CString(text) + b.b = C.uiNewButton(ctext) + b.c = (*C.uiControl)(unsafe.Pointer(b.b)) + freestr(ctext) + + C.realuiButtonOnClicked(b.b) + buttons[b.b] = b + + return b +} + +// Destroy destroys the Button. +func (b *Button) Destroy() { + delete(buttons, b.b) + C.uiControlDestroy(b.c) +} + +// LibuiControl returns the libui uiControl pointer that backs +// the Button. This is only used by package ui itself and should +// not be called by programs. +func (b *Button) LibuiControl() uintptr { + return uintptr(unsafe.Pointer(b.c)) +} + +// Handle returns the OS-level handle associated with this Button. +// On Windows this is an HWND of a standard Windows API BUTTON +// class (as provided by Common Controls version 6). +// On GTK+ this is a pointer to a GtkButton. +// On OS X this is a pointer to a NSButton. +func (b *Button) Handle() uintptr { + return uintptr(C.uiControlHandle(b.c)) +} + +// Show shows the Button. +func (b *Button) Show() { + C.uiControlShow(b.c) +} + +// Hide hides the Button. +func (b *Button) Hide() { + C.uiControlHide(b.c) +} + +// Enable enables the Button. +func (b *Button) Enable() { + C.uiControlEnable(b.c) +} + +// Disable disables the Button. +func (b *Button) Disable() { + C.uiControlDisable(b.c) +} + +// Text returns the Button's text. +func (b *Button) Text() string { + ctext := C.uiButtonText(b.b) + text := C.GoString(ctext) + C.uiFreeText(ctext) + return text +} + +// SetText sets the Button's text to text. +func (b *Button) SetText(text string) { + ctext := C.CString(text) + C.uiButtonSetText(b.b, ctext) + freestr(ctext) +} + +// OnClicked registers f to be run when the user clicks the Button. +// Only one function can be registered at a time. +func (b *Button) OnClicked(f func(*Button)) { + b.onClicked = f +} + +//export doButtonOnClicked +func doButtonOnClicked(bb *C.uiButton, data unsafe.Pointer) { + b := buttons[bb] + if b.onClicked != nil { + b.onClicked(b) + } +} diff --git a/AAA_GOFILES/checkbox.go b/AAA_GOFILES/checkbox.go new file mode 100644 index 0000000..b518b29 --- /dev/null +++ b/AAA_GOFILES/checkbox.go @@ -0,0 +1,124 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "ui.h" +// extern void doCheckboxOnToggled(uiCheckbox *, void *); +// static inline void realuiCheckboxOnToggled(uiCheckbox *c) +// { +// uiCheckboxOnToggled(c, doCheckboxOnToggled, NULL); +// } +import "C" + +// no need to lock this; only the GUI thread can access it +var checkboxes = make(map[*C.uiCheckbox]*Checkbox) + +// Checkbox is a Control that represents a box with a text label at its +// side. When the user clicks the checkbox, a check mark will appear +// in the box; clicking it again removes the check. +type Checkbox struct { + co *C.uiControl + c *C.uiCheckbox + + onToggled func(*Checkbox) +} + +// NewCheckbox creates a new Checkbox with the given text as its label. +func NewCheckbox(text string) *Checkbox { + c := new(Checkbox) + + ctext := C.CString(text) + c.c = C.uiNewCheckbox(ctext) + c.co = (*C.uiControl)(unsafe.Pointer(c.c)) + freestr(ctext) + + C.realuiCheckboxOnToggled(c.c) + checkboxes[c.c] = c + + return c +} + +// Destroy destroys the Checkbox. +func (c *Checkbox) Destroy() { + delete(checkboxes, c.c) + C.uiControlDestroy(c.co) +} + +// LibuiControl returns the libui uiControl pointer that backs +// the Window. This is only used by package ui itself and should +// not be called by programs. +func (c *Checkbox) LibuiControl() uintptr { + return uintptr(unsafe.Pointer(c.co)) +} + +// Handle returns the OS-level handle associated with this Checkbox. +// On Windows this is an HWND of a standard Windows API BUTTON +// class (as provided by Common Controls version 6). +// On GTK+ this is a pointer to a GtkCheckButton. +// On OS X this is a pointer to a NSButton. +func (c *Checkbox) Handle() uintptr { + return uintptr(C.uiControlHandle(c.co)) +} + +// Show shows the Checkbox. +func (c *Checkbox) Show() { + C.uiControlShow(c.co) +} + +// Hide hides the Checkbox. +func (c *Checkbox) Hide() { + C.uiControlHide(c.co) +} + +// Enable enables the Checkbox. +func (c *Checkbox) Enable() { + C.uiControlEnable(c.co) +} + +// Disable disables the Checkbox. +func (c *Checkbox) Disable() { + C.uiControlDisable(c.co) +} + +// Text returns the Checkbox's text. +func (c *Checkbox) Text() string { + ctext := C.uiCheckboxText(c.c) + text := C.GoString(ctext) + C.uiFreeText(ctext) + return text +} + +// SetText sets the Checkbox's text to text. +func (c *Checkbox) SetText(text string) { + ctext := C.CString(text) + C.uiCheckboxSetText(c.c, ctext) + freestr(ctext) +} + +// OnToggled registers f to be run when the user clicks the Checkbox. +// Only one function can be registered at a time. +func (c *Checkbox) OnToggled(f func(*Checkbox)) { + c.onToggled = f +} + +//export doCheckboxOnToggled +func doCheckboxOnToggled(cc *C.uiCheckbox, data unsafe.Pointer) { + c := checkboxes[cc] + if c.onToggled != nil { + c.onToggled(c) + } +} + +// Checked returns whether the Checkbox is checked. +func (c *Checkbox) Checked() bool { + return tobool(C.uiCheckboxChecked(c.c)) +} + +// SetChecked sets whether the Checkbox is checked. +func (c *Checkbox) SetChecked(checked bool) { + C.uiCheckboxSetChecked(c.c, frombool(checked)) +} diff --git a/AAA_GOFILES/combobox.go b/AAA_GOFILES/combobox.go new file mode 100644 index 0000000..1224e1e --- /dev/null +++ b/AAA_GOFILES/combobox.go @@ -0,0 +1,116 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "ui.h" +// extern void doComboboxOnSelected(uiCombobox *, void *); +// static inline void realuiComboboxOnSelected(uiCombobox *c) +// { +// uiComboboxOnSelected(c, doComboboxOnSelected, NULL); +// } +import "C" + +// no need to lock this; only the GUI thread can access it +var comboboxes = make(map[*C.uiCombobox]*Combobox) + +// Combobox is a Control that represents a drop-down list of strings +// that the user can choose one of at any time. For a Combobox that +// users can type values into, see EditableCombobox. +type Combobox struct { + co *C.uiControl + c *C.uiCombobox + + onSelected func(*Combobox) +} + +// NewCombobox creates a new Combobox. +func NewCombobox() *Combobox { + c := new(Combobox) + + c.c = C.uiNewCombobox() + c.co = (*C.uiControl)(unsafe.Pointer(c.c)) + + C.realuiComboboxOnSelected(c.c) + comboboxes[c.c] = c + + return c +} + +// Destroy destroys the Combobox. +func (c *Combobox) Destroy() { + delete(comboboxes, c.c) + C.uiControlDestroy(c.co) +} + +// LibuiControl returns the libui uiControl pointer that backs +// the Window. This is only used by package ui itself and should +// not be called by programs. +func (c *Combobox) LibuiControl() uintptr { + return uintptr(unsafe.Pointer(c.co)) +} + +// Handle returns the OS-level handle associated with this Combobox. +// On Windows this is an HWND of a standard Windows API COMBOBOX +// class (as provided by Common Controls version 6). +// On GTK+ this is a pointer to a GtkComboBoxText. +// On OS X this is a pointer to a NSPopUpButton. +func (c *Combobox) Handle() uintptr { + return uintptr(C.uiControlHandle(c.co)) +} + +// Show shows the Combobox. +func (c *Combobox) Show() { + C.uiControlShow(c.co) +} + +// Hide hides the Combobox. +func (c *Combobox) Hide() { + C.uiControlHide(c.co) +} + +// Enable enables the Combobox. +func (c *Combobox) Enable() { + C.uiControlEnable(c.co) +} + +// Disable disables the Combobox. +func (c *Combobox) Disable() { + C.uiControlDisable(c.co) +} + +// Append adds the named item to the end of the Combobox. +func (c *Combobox) Append(text string) { + ctext := C.CString(text) + C.uiComboboxAppend(c.c, ctext) + freestr(ctext) +} + +// Selected returns the index of the currently selected item in the +// Combobox, or -1 if nothing is selected. +func (c *Combobox) Selected() int { + return int(C.uiComboboxSelected(c.c)) +} + +// SetChecked sets the currently select item in the Combobox +// to index. If index is -1 no item will be selected. +func (c *Combobox) SetSelected(index int) { + C.uiComboboxSetSelected(c.c, C.intmax_t(index)) +} + +// OnSelected registers f to be run when the user selects an item in +// the Combobox. Only one function can be registered at a time. +func (c *Combobox) OnSelected(f func(*Combobox)) { + c.onSelected = f +} + +//export doComboboxOnSelected +func doComboboxOnSelected(cc *C.uiCombobox, data unsafe.Pointer) { + c := comboboxes[cc] + if c.onSelected != nil { + c.onSelected(c) + } +} diff --git a/AAA_GOFILES/datetimepicker.go b/AAA_GOFILES/datetimepicker.go new file mode 100644 index 0000000..ff98ced --- /dev/null +++ b/AAA_GOFILES/datetimepicker.go @@ -0,0 +1,160 @@ +// 12 december 2015 + +package ui + +import ( + "time" + "unsafe" +) + +// #include <time.h> +// #include "ui.h" +// static inline struct tm *allocTimeStruct(void) +// { +// /* TODO handle error */ +// return (struct tm *) malloc(sizeof (struct tm)); +// } +// extern void doDateTimePickerChanged(uiDateTimePicker *, void *); +// static inline void realuiDateTimePickerOnChanged(uiDateTimePicker *d) +// { +// uiDateTimePickerOnChanged(d, doDateTimePickerOnChanged, NULL); +// } +import "C" + +// DateTimePicker is a Control that represents a field where the user +// can enter a date and/or a time. +type DateTimePicker struct { + c *C.uiControl + d *C.uiDateTimePicker + + onChanged func(*DateTimePicker) +} + +// NewDateTimePicker creates a new DateTimePicker that shows +// both a date and a time. +func NewDateTimePicker() *DateTimePicker { + d := new(DateTimePicker) + + d.d = C.uiNewDateTimePicker() + d.c = (*C.uiControl)(unsafe.Pointer(d.d)) + + C.realuiDateTimePickerOnChanged(d.d) + + return d +} + +// NewDatePicker creates a new DateTimePicker that shows +// only a date. +func NewDatePicker() *DateTimePicker { + d := new(DateTimePicker) + + d.d = C.uiNewDatePicker() + d.c = (*C.uiControl)(unsafe.Pointer(d.d)) + + C.realuiDateTimePickerOnChanged(d.d) + + return d +} + +// NewTimePicker creates a new DateTimePicker that shows +// only a time. +func NewTimePicker() *DateTimePicker { + d := new(DateTimePicker) + + d.d = C.uiNewTimePicker() + d.c = (*C.uiControl)(unsafe.Pointer(d.d)) + + C.realuiDateTimePickerOnChanged(d.d) + + return d +} + +// Destroy destroys the DateTimePicker. +func (d *DateTimePicker) Destroy() { + C.uiControlDestroy(d.c) +} + +// LibuiControl returns the libui uiControl pointer that backs +// the Window. This is only used by package ui itself and should +// not be called by programs. +func (d *DateTimePicker) LibuiControl() uintptr { + return uintptr(unsafe.Pointer(d.c)) +} + +// Handle returns the OS-level handle associated with this DateTimePicker. +// On Windows this is an HWND of a standard Windows API +// DATETIMEPICK_CLASS class (as provided by Common Controls +// version 6). +// On GTK+ this is a pointer to a libui-internal class. +// On OS X this is a pointer to a NSDatePicker. +func (d *DateTimePicker) Handle() uintptr { + return uintptr(C.uiControlHandle(d.c)) +} + +// Show shows the DateTimePicker. +func (d *DateTimePicker) Show() { + C.uiControlShow(d.c) +} + +// Hide hides the DateTimePicker. +func (d *DateTimePicker) Hide() { + C.uiControlHide(d.c) +} + +// Enable enables the DateTimePicker. +func (d *DateTimePicker) Enable() { + C.uiControlEnable(d.c) +} + +// Disable disables the DateTimePicker. +func (d *DateTimePicker) Disable() { + C.uiControlDisable(d.c) +} + +// Time returns the time stored in the uiDateTimePicker. +// The time is assumed to be local time. +func (d *DateTimePicker) Time() time.Time { + tm := C.allocTimeStruct() + defer C.free(unsafe.Pointer(tm)) + C.uiDateTimePickerTime(d.d, tm) + return time.Date( + int(tm.tm_year + 1900), + time.Month(tm.tm_mon + 1), + int(tm.tm_mday), + int(tm.tm_hour), + int(tm.tm_min), + int(tm.tm_sec), + 0, time.Local) +} + +// SetTime sets the time in the DateTimePicker to t. +// t's components are read as-is; no time zone manipulations +// are done. +func (d *DateTimePicker) SetTime(t time.Time) { + tm := C.allocTimeStruct() + defer C.free(unsafe.Pointer(tm)) + year, mon, mday := t.Date() + tm.tm_year = C.int(year - 1900) + tm.tm_mon = C.int(mon - 1) + tm.tm_mday = C.int(mday) + hour, min, sec := t.Time() + tm.tm_hour = C.int(hour) + tm.tm_min = C.int(min) + tm.tm_sec = C.int(sec) + tm.tm_isdst = -1 + C.uiDateTimePickerSetTime(d.d, tm) +} + +// OnChanged registers f to be run when the user changes the time in the DateTimePicker. +// Only one function can be registered at a time. +func (d *DateTimePicker) OnChanged(f func(*DateTimePicker)) { + d.onChanged = f +} + +//export doDateTimePickerOnChanged +func doDateTimePickerOnChanged(dd *C.uiDateTimePicker, data unsafe.Pointer) { + d := dateTimePickers[dd] + if d.onChanged != nil { + d.onChanged(d) + } +} diff --git a/AAA_GOFILES/editablecombobox.go b/AAA_GOFILES/editablecombobox.go new file mode 100644 index 0000000..8f6a825 --- /dev/null +++ b/AAA_GOFILES/editablecombobox.go @@ -0,0 +1,120 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "ui.h" +// extern void doEditableComboboxOnChanged(uiCombobox *, void *); +// static inline void realuiEditableComboboxOnChanged(uiCombobox *c) +// { +// uiEditableComboboxOnChanged(c, doEditableComboboxOnChanged, NULL); +// } +import "C" + +// no need to lock this; only the GUI thread can access it +var editableComboboxes = make(map[*C.uiEditableCombobox]*Combobox) + +// EditableCombobox is a Control that represents a drop-down list +// of strings that the user can choose one of at any time. It also has +// an entry field that the user can type an alternate choice into. +type EditableCombobox struct { + co *C.uiControl + c *C.uiEditableCombobox + + onChanged func(*EditableCombobox) +} + +// NewEditableCombobox creates a new EditableCombobox. +func NewEditableCombobox() *EditableCombobox { + c := new(EditableCombobox) + + c.c = C.uiNewEditableCombobox() + c.co = (*C.uiControl)(unsafe.Pointer(c.c)) + + C.realuiEditableComboboxOnChanged(c.c) + editableComboboxes[c.c] = c + + return c +} + +// Destroy destroys the EditableCombobox. +func (c *Combobox) Destroy() { + delete(editableComboboxes, c.c) + C.uiControlDestroy(c.co) +} + +// LibuiControl returns the libui uiControl pointer that backs +// the EditableCombobox. This is only used by package ui itself and +// should not be called by programs. +func (c *Combobox) LibuiControl() uintptr { + return uintptr(unsafe.Pointer(c.co)) +} + +// Handle returns the OS-level handle associated with this EditableCombobox. +// On Windows this is an HWND of a standard Windows API COMBOBOX +// class (as provided by Common Controls version 6). +// On GTK+ this is a pointer to a GtkComboBoxText. +// On OS X this is a pointer to a NSComboBox. +func (c *Combobox) Handle() uintptr { + return uintptr(C.uiControlHandle(c.co)) +} + +// Show shows the EditableCombobox. +func (c *Combobox) Show() { + C.uiControlShow(c.co) +} + +// Hide hides the EditableCombobox. +func (c *Combobox) Hide() { + C.uiControlHide(c.co) +} + +// Enable enables the EditableCombobox. +func (c *Combobox) Enable() { + C.uiControlEnable(c.co) +} + +// Disable disables the EditableCombobox. +func (c *Combobox) Disable() { + C.uiControlDisable(c.co) +} + +// Append adds the named item to the end of the EditableCombobox. +func (c *Combobox) Append(text string) { + ctext := C.CString(text) + C.uiComboboxAppend(c.c, ctext) + freestr(ctext) +} + +// Text returns the text in the entry of the EditableCombobox, which +// could be one of the choices in the list if the user has selected one. +func (c *Combobox) Text() string { + ctext := C.uiEditableComboboxText(c.c) + text := C.GoString(ctext) + C.uiFreeText(ctext) + return text +} + +// SetText sets the text in the entry of the EditableCombobox. +func (c *Combobox) SetText(index int) { + ctext := C.CString(text) + C.uiEditableComboboxSetText(c.c, ctext) + freestr(ctext) +} + +// OnChanged registers f to be run when the user selects an item in +// the Combobox. Only one function can be registered at a time. +func (c *Combobox) OnChanged(f func(*Combobox)) { + c.onChanged = f +} + +//export doComboboxOnChanged +func doComboboxOnChanged(cc *C.uiCombobox, data unsafe.Pointer) { + c := editableComboboxes[cc] + if c.onChanged != nil { + c.onChanged(c) + } +} |
