More control migration.
This commit is contained in:
parent
5ab5777d4c
commit
68ffb80867
|
@ -1,85 +0,0 @@
|
|||
// 12 december 2015
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// #include "ui.h"
|
||||
import "C"
|
||||
|
||||
// Label is a Control that represents a line of text that cannot be
|
||||
// interacted with. TODO rest of documentation.
|
||||
type Label struct {
|
||||
c *C.uiControl
|
||||
l *C.uiLabel
|
||||
}
|
||||
|
||||
// NewLabel creates a new Label with the given text.
|
||||
func NewLabel(text string) *Label {
|
||||
l := new(Label)
|
||||
|
||||
ctext := C.CString(text)
|
||||
l.l = C.uiNewLabel(ctext)
|
||||
l.c = (*C.uiControl)(unsafe.Pointer(l.l))
|
||||
freestr(ctext)
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
// Destroy destroys the Label.
|
||||
func (l *Label) Destroy() {
|
||||
C.uiControlDestroy(l.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 (l *Label) LibuiControl() uintptr {
|
||||
return uintptr(unsafe.Pointer(l.c))
|
||||
}
|
||||
|
||||
// Handle returns the OS-level handle associated with this Label.
|
||||
// On Windows this is an HWND of a standard Windows API STATIC
|
||||
// class (as provided by Common Controls version 6).
|
||||
// On GTK+ this is a pointer to a GtkLabel.
|
||||
// On OS X this is a pointer to a NSTextField.
|
||||
func (l *Label) Handle() uintptr {
|
||||
return uintptr(C.uiControlHandle(l.c))
|
||||
}
|
||||
|
||||
// Show shows the Label.
|
||||
func (l *Label) Show() {
|
||||
C.uiControlShow(l.c)
|
||||
}
|
||||
|
||||
// Hide hides the Label.
|
||||
func (l *Label) Hide() {
|
||||
C.uiControlHide(l.c)
|
||||
}
|
||||
|
||||
// Enable enables the Label.
|
||||
func (l *Label) Enable() {
|
||||
C.uiControlEnable(l.c)
|
||||
}
|
||||
|
||||
// Disable disables the Label.
|
||||
func (l *Label) Disable() {
|
||||
C.uiControlDisable(l.c)
|
||||
}
|
||||
|
||||
// Text returns the Label's text.
|
||||
func (l *Label) Text() string {
|
||||
ctext := C.uiLabelText(l.l)
|
||||
text := C.GoString(ctext)
|
||||
C.uiFreeText(ctext)
|
||||
return text
|
||||
}
|
||||
|
||||
// SetText sets the Label's text to text.
|
||||
func (l *Label) SetText(text string) {
|
||||
ctext := C.CString(text)
|
||||
C.uiLabelSetText(l.l, ctext)
|
||||
freestr(ctext)
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
// 12 december 2015
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// #include "ui.h"
|
||||
import "C"
|
||||
|
||||
// ProgressBar is a Control that represents a horizontal bar that
|
||||
// is filled in progressively over time as a process completes.
|
||||
type ProgressBar struct {
|
||||
c *C.uiControl
|
||||
p *C.uiProgressBar
|
||||
}
|
||||
|
||||
// NewProgressBar creates a new ProgressBar.
|
||||
func NewProgressBar() *ProgressBar {
|
||||
p := new(ProgressBar)
|
||||
|
||||
p.p = C.uiNewProgressBar()
|
||||
p.c = (*C.uiControl)(unsafe.Pointer(p.p))
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
// Destroy destroys the ProgressBar.
|
||||
func (p *ProgressBar) Destroy() {
|
||||
C.uiControlDestroy(p.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 (p *ProgressBar) LibuiControl() uintptr {
|
||||
return uintptr(unsafe.Pointer(p.c))
|
||||
}
|
||||
|
||||
// Handle returns the OS-level handle associated with this ProgressBar.
|
||||
// On Windows this is an HWND of a standard Windows API
|
||||
// PROGRESS_CLASS class (as provided by Common Controls
|
||||
// version 6).
|
||||
// On GTK+ this is a pointer to a GtkProgressBar.
|
||||
// On OS X this is a pointer to a NSProgressIndicator.
|
||||
func (p *ProgressBar) Handle() uintptr {
|
||||
return uintptr(C.uiControlHandle(p.c))
|
||||
}
|
||||
|
||||
// Show shows the ProgressBar.
|
||||
func (p *ProgressBar) Show() {
|
||||
C.uiControlShow(p.c)
|
||||
}
|
||||
|
||||
// Hide hides the ProgressBar.
|
||||
func (p *ProgressBar) Hide() {
|
||||
C.uiControlHide(p.c)
|
||||
}
|
||||
|
||||
// Enable enables the ProgressBar.
|
||||
func (p *ProgressBar) Enable() {
|
||||
C.uiControlEnable(p.c)
|
||||
}
|
||||
|
||||
// Disable disables the ProgressBar.
|
||||
func (p *ProgressBar) Disable() {
|
||||
C.uiControlDisable(p.c)
|
||||
}
|
||||
|
||||
// TODO Value
|
||||
|
||||
// SetValue sets the ProgressBar's currently displayed percentage
|
||||
// to value. value must be between 0 and 100 inclusive.
|
||||
func (p *ProgressBar) SetValue(value int) {
|
||||
C.uiProgressBarSetValue(p.p, C.int(value))
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
// 12 december 2015
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// #include "ui.h"
|
||||
import "C"
|
||||
|
||||
// RadioButtons is a Control that represents a set of checkable
|
||||
// buttons from which exactly one may be chosen by the user.
|
||||
type RadioButtons struct {
|
||||
c *C.uiControl
|
||||
r *C.uiRadioButtons
|
||||
}
|
||||
|
||||
// NewRadioButtons creates a new RadioButtons.
|
||||
func NewRadioButtons() *RadioButtons {
|
||||
r := new(RadioButtons)
|
||||
|
||||
r.r = C.uiNewRadioButtons()
|
||||
r.c = (*C.uiControl)(unsafe.Pointer(r.r))
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// Destroy destroys the RadioButtons.
|
||||
func (r *RadioButtons) Destroy() {
|
||||
C.uiControlDestroy(r.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 (r *RadioButtons) LibuiControl() uintptr {
|
||||
return uintptr(unsafe.Pointer(r.c))
|
||||
}
|
||||
|
||||
// Handle returns the OS-level handle associated with this RadioButtons.
|
||||
// On Windows this is an HWND of a libui-internal class; its
|
||||
// child windows are instances of the standard Windows API
|
||||
// BUTTON class (as provided by Common Controls version 6).
|
||||
// On GTK+ this is a pointer to a GtkBox containing GtkRadioButtons.
|
||||
// On OS X this is a pointer to a NSView with each radio button as a NSButton subview.
|
||||
func (r *RadioButtons) Handle() uintptr {
|
||||
return uintptr(C.uiControlHandle(r.c))
|
||||
}
|
||||
|
||||
// Show shows the RadioButtons.
|
||||
func (r *RadioButtons) Show() {
|
||||
C.uiControlShow(r.c)
|
||||
}
|
||||
|
||||
// Hide hides the RadioButtons.
|
||||
func (r *RadioButtons) Hide() {
|
||||
C.uiControlHide(r.c)
|
||||
}
|
||||
|
||||
// Enable enables the RadioButtons.
|
||||
func (r *RadioButtons) Enable() {
|
||||
C.uiControlEnable(r.c)
|
||||
}
|
||||
|
||||
// Disable disables the RadioButtons.
|
||||
func (r *RadioButtons) Disable() {
|
||||
C.uiControlDisable(r.c)
|
||||
}
|
||||
|
||||
// Append adds the named button to the end of the RadioButtons.
|
||||
// If this button is the first button, it is automatically selected.
|
||||
func (r *RadioButtons) Append(text string) {
|
||||
ctext := C.CString(text)
|
||||
C.uiRadioButtonsAppend(r.r, ctext)
|
||||
freestr(ctext)
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
// 12 december 2015
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// #include "ui.h"
|
||||
import "C"
|
||||
|
||||
// Separator is a Control that represents a horizontal line that
|
||||
// visually separates controls.
|
||||
type Separator struct {
|
||||
c *C.uiControl
|
||||
s *C.uiSeparator
|
||||
}
|
||||
|
||||
// NewSeparator creates a new horizontal Separator.
|
||||
func NewHorizontalSeparator() *Separator {
|
||||
s := new(Separator)
|
||||
|
||||
s.s = C.uiNewHorizontalSeparator()
|
||||
s.c = (*C.uiControl)(unsafe.Pointer(s.s))
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Destroy destroys the Separator.
|
||||
func (s *Separator) Destroy() {
|
||||
C.uiControlDestroy(s.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 (s *Separator) LibuiControl() uintptr {
|
||||
return uintptr(unsafe.Pointer(s.c))
|
||||
}
|
||||
|
||||
// Handle returns the OS-level handle associated with this Separator.
|
||||
// On Windows this is an HWND of a standard Windows API STATIC
|
||||
// class (as provided by Common Controls version 6).
|
||||
// On GTK+ this is a pointer to a GtkSeparator.
|
||||
// On OS X this is a pointer to a NSBox.
|
||||
func (s *Separator) Handle() uintptr {
|
||||
return uintptr(C.uiControlHandle(s.c))
|
||||
}
|
||||
|
||||
// Show shows the Separator.
|
||||
func (s *Separator) Show() {
|
||||
C.uiControlShow(s.c)
|
||||
}
|
||||
|
||||
// Hide hides the Separator.
|
||||
func (s *Separator) Hide() {
|
||||
C.uiControlHide(s.c)
|
||||
}
|
||||
|
||||
// Enable enables the Separator.
|
||||
func (s *Separator) Enable() {
|
||||
C.uiControlEnable(s.c)
|
||||
}
|
||||
|
||||
// Disable disables the Separator.
|
||||
func (s *Separator) Disable() {
|
||||
C.uiControlDisable(s.c)
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
// 12 december 2015
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// #include "ui.h"
|
||||
// extern void doSliderOnChanged(uiSlider *, void *);
|
||||
// static inline void realuiSliderOnChanged(uiSlider *b)
|
||||
// {
|
||||
// uiSliderOnChanged(b, doSliderOnChanged, NULL);
|
||||
// }
|
||||
import "C"
|
||||
|
||||
// no need to lock this; only the GUI thread can access it
|
||||
var sliders = make(map[*C.uiSlider]*Slider)
|
||||
|
||||
// Slider is a Control that represents a horizontal bar that represents
|
||||
// a range of integers. The user can drag a pointer on the bar to
|
||||
// select an integer.
|
||||
type Slider struct {
|
||||
c *C.uiControl
|
||||
s *C.uiSlider
|
||||
|
||||
onChanged func(*Slider)
|
||||
}
|
||||
|
||||
// NewSlider creates a new Slider. If min >= max, they are swapped.
|
||||
func NewSlider(min int, max int) *Slider {
|
||||
s := new(Slider)
|
||||
|
||||
s.s = C.uiNewSlider(C.intmax_t(min), C.intmax_t(max))
|
||||
s.c = (*C.uiControl)(unsafe.Pointer(s.s))
|
||||
|
||||
C.realuiSliderOnChanged(s.s)
|
||||
sliders[s.s] = s
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Destroy destroys the Slider.
|
||||
func (s *Slider) Destroy() {
|
||||
delete(sliders, s.s)
|
||||
C.uiControlDestroy(s.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 (s *Slider) LibuiControl() uintptr {
|
||||
return uintptr(unsafe.Pointer(s.c))
|
||||
}
|
||||
|
||||
// Handle returns the OS-level handle associated with this Slider.
|
||||
// On Windows this is an HWND of a standard Windows API
|
||||
// TRACKBAR_CLASS class (as provided by Common Controls
|
||||
// version 6).
|
||||
// On GTK+ this is a pointer to a GtkScale.
|
||||
// On OS X this is a pointer to a NSSlider.
|
||||
func (s *Slider) Handle() uintptr {
|
||||
return uintptr(C.uiControlHandle(s.c))
|
||||
}
|
||||
|
||||
// Show shows the Slider.
|
||||
func (s *Slider) Show() {
|
||||
C.uiControlShow(s.c)
|
||||
}
|
||||
|
||||
// Hide hides the Slider.
|
||||
func (s *Slider) Hide() {
|
||||
C.uiControlHide(s.c)
|
||||
}
|
||||
|
||||
// Enable enables the Slider.
|
||||
func (s *Slider) Enable() {
|
||||
C.uiControlEnable(s.c)
|
||||
}
|
||||
|
||||
// Disable disables the Slider.
|
||||
func (s *Slider) Disable() {
|
||||
C.uiControlDisable(s.c)
|
||||
}
|
||||
|
||||
// Value returns the Slider's current value.
|
||||
func (s *Slider) Value() int {
|
||||
return int(C.uiSliderValue(s.s))
|
||||
}
|
||||
|
||||
// SetText sets the Slider's current value to value.
|
||||
func (s *Slider) SetValue(value int) {
|
||||
C.uiSliderSetValue(s.s, C.intmax_t(value))
|
||||
}
|
||||
|
||||
// OnChanged registers f to be run when the user changes the value
|
||||
// of the Slider. Only one function can be registered at a time.
|
||||
func (s *Slider) OnChanged(f func(*Slider)) {
|
||||
s.onChanged = f
|
||||
}
|
||||
|
||||
//export doSliderOnChanged
|
||||
func doSliderOnChanged(ss *C.uiSlider, data unsafe.Pointer) {
|
||||
s := sliders[ss]
|
||||
if s.onChanged != nil {
|
||||
s.onChanged(s)
|
||||
}
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
// 12 december 2015
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// #include "ui.h"
|
||||
// extern void doSpinboxOnChanged(uiSpinbox *, void *);
|
||||
// static inline void realuiSpinboxOnChanged(uiSpinbox *b)
|
||||
// {
|
||||
// uiSpinboxOnChanged(b, doSpinboxOnChanged, NULL);
|
||||
// }
|
||||
import "C"
|
||||
|
||||
// no need to lock this; only the GUI thread can access it
|
||||
var spinboxes = make(map[*C.uiSpinbox]*Spinbox)
|
||||
|
||||
// Spinbox is a Control that represents a space where the user can
|
||||
// enter integers. The space also comes with buttons to add or
|
||||
// subtract 1 from the integer.
|
||||
type Spinbox struct {
|
||||
c *C.uiControl
|
||||
s *C.uiSpinbox
|
||||
|
||||
onChanged func(*Spinbox)
|
||||
}
|
||||
|
||||
// NewSpinbox creates a new Spinbox. If min >= max, they are swapped.
|
||||
func NewSpinbox(min int, max int) *Spinbox {
|
||||
s := new(Spinbox)
|
||||
|
||||
s.s = C.uiNewSpinbox(C.intmax_t(min), C.intmax_t(max))
|
||||
s.c = (*C.uiControl)(unsafe.Pointer(s.s))
|
||||
|
||||
C.realuiSpinboxOnChanged(s.s)
|
||||
spinboxes[s.s] = s
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Destroy destroys the Spinbox.
|
||||
func (s *Spinbox) Destroy() {
|
||||
delete(spinboxes, s.s)
|
||||
C.uiControlDestroy(s.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 (s *Spinbox) LibuiControl() uintptr {
|
||||
return uintptr(unsafe.Pointer(s.c))
|
||||
}
|
||||
|
||||
// Handle returns the OS-level handle associated with this Spinbox.
|
||||
// On Windows this is an HWND of a standard Windows API EDIT
|
||||
// class (as provided by Common Controls version 6). Due to
|
||||
// various limitations which affect the lifetime of the associated
|
||||
// Common Controls version 6 UPDOWN_CLASS window that
|
||||
// provides the buttons, there is no way to access it.
|
||||
// On GTK+ this is a pointer to a GtkSpinButton.
|
||||
// On OS X this is a pointer to a NSView that contains a NSTextField
|
||||
// and a NSStepper as subviews.
|
||||
func (s *Spinbox) Handle() uintptr {
|
||||
return uintptr(C.uiControlHandle(s.c))
|
||||
}
|
||||
|
||||
// Show shows the Spinbox.
|
||||
func (s *Spinbox) Show() {
|
||||
C.uiControlShow(s.c)
|
||||
}
|
||||
|
||||
// Hide hides the Spinbox.
|
||||
func (s *Spinbox) Hide() {
|
||||
C.uiControlHide(s.c)
|
||||
}
|
||||
|
||||
// Enable enables the Spinbox.
|
||||
func (s *Spinbox) Enable() {
|
||||
C.uiControlEnable(s.c)
|
||||
}
|
||||
|
||||
// Disable disables the Spinbox.
|
||||
func (s *Spinbox) Disable() {
|
||||
C.uiControlDisable(s.c)
|
||||
}
|
||||
|
||||
// Value returns the Spinbox's current value.
|
||||
func (s *Spinbox) Value() int {
|
||||
return int(C.uiSpinboxValue(s.s))
|
||||
}
|
||||
|
||||
// SetText sets the Spinbox's current value to value.
|
||||
func (s *Spinbox) SetValue(value int) {
|
||||
C.uiSpinboxSetValue(s.s, C.intmax_t(value))
|
||||
}
|
||||
|
||||
// OnChanged registers f to be run when the user changes the value
|
||||
// of the Spinbox. Only one function can be registered at a time.
|
||||
func (s *Spinbox) OnChanged(f func(*Spinbox)) {
|
||||
s.onChanged = f
|
||||
}
|
||||
|
||||
//export doSpinboxOnChanged
|
||||
func doSpinboxOnChanged(ss *C.uiSpinbox, data unsafe.Pointer) {
|
||||
s := spinboxes[ss]
|
||||
if s.onChanged != nil {
|
||||
s.onChanged(s)
|
||||
}
|
||||
}
|
|
@ -44,10 +44,10 @@ func (c *Combobox) Selected() int {
|
|||
return int(C.uiComboboxSelected(c.c))
|
||||
}
|
||||
|
||||
// SetChecked sets the currently select item in the Combobox
|
||||
// SetSelected sets the currently selected 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))
|
||||
C.uiComboboxSetSelected(c.c, C.int(index))
|
||||
}
|
||||
|
||||
// OnSelected registers f to be run when the user selects an item in
|
||||
|
|
|
@ -97,7 +97,7 @@ func (d *DateTimePicker) OnChanged(f func(*DateTimePicker)) {
|
|||
|
||||
//export doDateTimePickerOnChanged
|
||||
func doDateTimePickerOnChanged(dd *C.uiDateTimePicker, data unsafe.Pointer) {
|
||||
d := ControlFromLibui(uintptr(unsafe.Pointer(dd)).(*DateTimePicker)
|
||||
d := ControlFromLibui(uintptr(unsafe.Pointer(dd))).(*DateTimePicker)
|
||||
if d.onChanged != nil {
|
||||
d.onChanged(d)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
// 12 december 2015
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// #include "ui.h"
|
||||
import "C"
|
||||
|
||||
// Label is a Control that represents a line of text that cannot be
|
||||
// interacted with.
|
||||
type Label struct {
|
||||
ControlBase
|
||||
l *C.uiLabel
|
||||
}
|
||||
|
||||
// NewLabel creates a new Label with the given text.
|
||||
func NewLabel(text string) *Label {
|
||||
l := new(Label)
|
||||
|
||||
ctext := C.CString(text)
|
||||
l.l = C.uiNewLabel(ctext)
|
||||
freestr(ctext)
|
||||
|
||||
l.ControlBase = NewControlBase(l, uintptr(unsafe.Pointer(l.l)))
|
||||
return l
|
||||
}
|
||||
|
||||
// Text returns the Label's text.
|
||||
func (l *Label) Text() string {
|
||||
ctext := C.uiLabelText(l.l)
|
||||
text := C.GoString(ctext)
|
||||
C.uiFreeText(ctext)
|
||||
return text
|
||||
}
|
||||
|
||||
// SetText sets the Label's text to text.
|
||||
func (l *Label) SetText(text string) {
|
||||
ctext := C.CString(text)
|
||||
C.uiLabelSetText(l.l, ctext)
|
||||
freestr(ctext)
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
// 12 december 2015
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// #include "ui.h"
|
||||
import "C"
|
||||
|
||||
// ProgressBar is a Control that represents a horizontal bar that
|
||||
// is filled in progressively over time as a process completes.
|
||||
type ProgressBar struct {
|
||||
ControlBase
|
||||
p *C.uiProgressBar
|
||||
}
|
||||
|
||||
// NewProgressBar creates a new ProgressBar.
|
||||
func NewProgressBar() *ProgressBar {
|
||||
p := new(ProgressBar)
|
||||
|
||||
p.p = C.uiNewProgressBar()
|
||||
|
||||
p.ControlBase = NewControlBase(p, uintptr(unsafe.Pointer(p.p)))
|
||||
return p
|
||||
}
|
||||
|
||||
// Value returns the value currently shown in the ProgressBar.
|
||||
func (p *ProgressBar) Value() int {
|
||||
return int(C.uiProgressBarValue(p.p))
|
||||
}
|
||||
|
||||
// SetValue sets the ProgressBar's currently displayed percentage
|
||||
// to value. value must be between 0 and 100 inclusive, or -1 for
|
||||
// an indeterminate progressbar.
|
||||
func (p *ProgressBar) SetValue(value int) {
|
||||
C.uiProgressBarSetValue(p.p, C.int(value))
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
// 12 december 2015
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// #include "ui.h"
|
||||
// extern void doRadioButtonsOnSelected(uiRadioButtons *, void *);
|
||||
import "C"
|
||||
|
||||
// RadioButtons is a Control that represents a set of checkable
|
||||
// buttons from which exactly one may be chosen by the user.
|
||||
type RadioButtons struct {
|
||||
ControlBase
|
||||
r *C.uiRadioButtons
|
||||
onSelected func(*RadioButtons)
|
||||
}
|
||||
|
||||
// NewRadioButtons creates a new RadioButtons.
|
||||
func NewRadioButtons() *RadioButtons {
|
||||
r := new(RadioButtons)
|
||||
|
||||
r.r = C.uiNewRadioButtons()
|
||||
|
||||
C.uiRadioButtonsOnChanged(r.r, C.doRadioButtonsOnChanged, nil)
|
||||
|
||||
r.ControlBase = NewControlBase(r, uintptr(unsafe.Pointer(r.r)))
|
||||
return r
|
||||
}
|
||||
|
||||
// Append adds the named button to the end of the RadioButtons.
|
||||
// If this button is the first button, it is automatically selected.
|
||||
func (r *RadioButtons) Append(text string) {
|
||||
ctext := C.CString(text)
|
||||
C.uiRadioButtonsAppend(r.r, ctext)
|
||||
freestr(ctext)
|
||||
}
|
||||
|
||||
// Selected returns the index of the currently selected option in the
|
||||
// RadioButtons, or -1 if there are no items.
|
||||
func (r *RadioButtons) Selected() int {
|
||||
return int(C.uiRadioButtonsSelected(r.r))
|
||||
}
|
||||
|
||||
// SetSelected sets the currently selected option in the RadioButtons
|
||||
// to index.
|
||||
func (r *RadioButtons) SetSelected(index int) {
|
||||
C.uiRadioButtonsSetSelected(r.r, C.int(index))
|
||||
}
|
||||
|
||||
// OnSelected registers f to be run when the user selects an option in
|
||||
// the RadioButtons. Only one function can be registered at a time.
|
||||
func (r *RadioButtons) OnSelected(f func(*RadioButtons)) {
|
||||
r.onSelected = f
|
||||
}
|
||||
|
||||
//export doRadioButtonsOnSelected
|
||||
func doRadioButtonsOnSelected(rr *C.uiRadioButtons, data unsafe.Pointer) {
|
||||
r := ControlFromLibui(uintptr(unsafe.Pointer(rr))).(*RadioButtons)
|
||||
if r.onSelected != nil {
|
||||
r.onSelected(r)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
// 12 december 2015
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// #include "ui.h"
|
||||
import "C"
|
||||
|
||||
// Separator is a Control that represents a horizontal line that
|
||||
// visually separates controls.
|
||||
type Separator struct {
|
||||
ControlBase
|
||||
s *C.uiSeparator
|
||||
}
|
||||
|
||||
// NewHorizontalSeparator creates a new horizontal Separator.
|
||||
func NewHorizontalSeparator() *Separator {
|
||||
s := new(Separator)
|
||||
|
||||
s.s = C.uiNewHorizontalSeparator()
|
||||
|
||||
s.ControlBase = NewControlBase(s, uintptr(unsafe.Pointer(s.s)))
|
||||
return s
|
||||
}
|
||||
|
||||
// NewVerticalSeparator creates a new vertical Separator.
|
||||
func NewVerticalSeparator() *Separator {
|
||||
s := new(Separator)
|
||||
|
||||
s.s = C.uiNewVerticalSeparator()
|
||||
|
||||
s.ControlBase = NewControlBase(s, uintptr(unsafe.Pointer(s.s)))
|
||||
return s
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
// 12 december 2015
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// #include "ui.h"
|
||||
// extern void doSliderOnChanged(uiSlider *, void *);
|
||||
import "C"
|
||||
|
||||
// Slider is a Control that represents a horizontal bar that represents
|
||||
// a range of integers. The user can drag a pointer on the bar to
|
||||
// select an integer.
|
||||
type Slider struct {
|
||||
ControlBase
|
||||
s *C.uiSlider
|
||||
onChanged func(*Slider)
|
||||
}
|
||||
|
||||
// NewSlider creates a new Slider. If min >= max, they are swapped.
|
||||
func NewSlider(min int, max int) *Slider {
|
||||
s := new(Slider)
|
||||
|
||||
s.s = C.uiNewSlider(C.int(min), C.int(max))
|
||||
|
||||
C.uiSliderOnChanged(s.s, C.doSliderOnChanged, nil)
|
||||
|
||||
s.ControlBase = NewControlBase(s, uintptr(unsafe.Pointer(s.s)))
|
||||
return s
|
||||
}
|
||||
|
||||
// Value returns the Slider's current value.
|
||||
func (s *Slider) Value() int {
|
||||
return int(C.uiSliderValue(s.s))
|
||||
}
|
||||
|
||||
// SetValue sets the Slider's current value to value.
|
||||
func (s *Slider) SetValue(value int) {
|
||||
C.uiSliderSetValue(s.s, C.intmax_t(value))
|
||||
}
|
||||
|
||||
// OnChanged registers f to be run when the user changes the value
|
||||
// of the Slider. Only one function can be registered at a time.
|
||||
func (s *Slider) OnChanged(f func(*Slider)) {
|
||||
s.onChanged = f
|
||||
}
|
||||
|
||||
//export doSliderOnChanged
|
||||
func doSliderOnChanged(ss *C.uiSlider, data unsafe.Pointer) {
|
||||
s := ControlFromLibui(uintptr(unsafe.Pointer(ss))).(*Slider)
|
||||
if s.onChanged != nil {
|
||||
s.onChanged(s)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
// 12 december 2015
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// #include "ui.h"
|
||||
// extern void doSpinboxOnChanged(uiSpinbox *, void *);
|
||||
import "C"
|
||||
|
||||
// Spinbox is a Control that represents a space where the user can
|
||||
// enter integers. The space also comes with buttons to add or
|
||||
// subtract 1 from the integer.
|
||||
type Spinbox struct {
|
||||
ControlBase
|
||||
s *C.uiSpinbox
|
||||
onChanged func(*Spinbox)
|
||||
}
|
||||
|
||||
// NewSpinbox creates a new Spinbox. If min >= max, they are swapped.
|
||||
func NewSpinbox(min int, max int) *Spinbox {
|
||||
s := new(Spinbox)
|
||||
|
||||
s.s = C.uiNewSpinbox(C.int(min), C.int(max))
|
||||
|
||||
C.uiSpinboxOnChanged(s.s, C.doSpinboxOnChanged, nil)
|
||||
|
||||
s.ControlBase = NewControlBase(s, uintptr(unsafe.Pointer(s.s)))
|
||||
return s
|
||||
}
|
||||
|
||||
// Value returns the Spinbox's current value.
|
||||
func (s *Spinbox) Value() int {
|
||||
return int(C.uiSpinboxValue(s.s))
|
||||
}
|
||||
|
||||
// SetValue sets the Spinbox's current value to value.
|
||||
func (s *Spinbox) SetValue(value int) {
|
||||
C.uiSpinboxSetValue(s.s, C.intmax_t(value))
|
||||
}
|
||||
|
||||
// OnChanged registers f to be run when the user changes the value
|
||||
// of the Spinbox. Only one function can be registered at a time.
|
||||
func (s *Spinbox) OnChanged(f func(*Spinbox)) {
|
||||
s.onChanged = f
|
||||
}
|
||||
|
||||
//export doSpinboxOnChanged
|
||||
func doSpinboxOnChanged(ss *C.uiSpinbox, data unsafe.Pointer) {
|
||||
s := ControlFromLibui(uintptr(unsafe.Pointer(ss))).(*Spinbox)
|
||||
if s.onChanged != nil {
|
||||
s.onChanged(s)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue