diff options
| author | Pietro Gagliardi <[email protected]> | 2018-08-26 13:24:47 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2018-08-26 13:24:47 -0400 |
| commit | 2bc76219286dfe39949772ceee4dbd9560ec2c1f (patch) | |
| tree | 28ae5f6f24c4a12ce349bc39490a7dda068d087a /BBB_GOFILES | |
| parent | 809662459dcd2cbe0b42f338413b88fea0483086 (diff) | |
Migrated window.go, box.go, button.go, and checkbox.go back.
Diffstat (limited to 'BBB_GOFILES')
| -rw-r--r-- | BBB_GOFILES/box.go | 85 | ||||
| -rw-r--r-- | BBB_GOFILES/button.go | 65 | ||||
| -rw-r--r-- | BBB_GOFILES/checkbox.go | 76 | ||||
| -rw-r--r-- | BBB_GOFILES/window.go | 125 |
4 files changed, 0 insertions, 351 deletions
diff --git a/BBB_GOFILES/box.go b/BBB_GOFILES/box.go deleted file mode 100644 index 65421d4..0000000 --- a/BBB_GOFILES/box.go +++ /dev/null @@ -1,85 +0,0 @@ -// 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 { - ControlBase - b *C.uiBox - children []Control -} - -// NewHorizontalBox creates a new horizontal Box. -func NewHorizontalBox() *Box { - b := new(Box) - - b.b = C.uiNewHorizontalBox() - - b.ControlBase = NewControlBase(b, uintptr(unsafe.Pointer(b.b))) - return b -} - -// NewVerticalBox creates a new vertical Box. -func NewVerticalBox() *Box { - b := new(Box) - - b.b = C.uiNewVerticalBox() - - b.ControlBase = NewControlBase(b, uintptr(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() - } - b.ControlBase.Destroy() -} - -// Append adds the given control to the end of the Box. -func (b *Box) Append(child Control, stretchy bool) { - c := (*C.uiControl)(nil) - // TODO this part is wrong for Box? - 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:]...) - C.uiBoxDelete(b.b, C.int(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/BBB_GOFILES/button.go b/BBB_GOFILES/button.go deleted file mode 100644 index 630c684..0000000 --- a/BBB_GOFILES/button.go +++ /dev/null @@ -1,65 +0,0 @@ -// 12 december 2015 - -package ui - -import ( - "unsafe" -) - -// #include "ui.h" -// extern void doButtonOnClicked(uiButton *, void *); -// // see golang/go#19835 -// typedef void (*buttonCallback)(uiButton *, void *); -import "C" - -// 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 { - ControlBase - 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) - freestr(ctext) - - C.uiButtonOnClicked(b.b, C.buttonCallback(C.doButtonOnClicked), nil) - - b.ControlBase = NewControlBase(b, uintptr(unsafe.Pointer(b.b))) - return b -} - -// 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 := ControlFromLibui(uintptr(unsafe.Pointer(bb))).(*Button) - if b.onClicked != nil { - b.onClicked(b) - } -} diff --git a/BBB_GOFILES/checkbox.go b/BBB_GOFILES/checkbox.go deleted file mode 100644 index 8177226..0000000 --- a/BBB_GOFILES/checkbox.go +++ /dev/null @@ -1,76 +0,0 @@ -// 12 december 2015 - -package ui - -import ( - "unsafe" -) - -// #include "ui.h" -// extern void doCheckboxOnToggled(uiCheckbox *, void *); -// // see golang/go#19835 -// typedef void (*checkboxCallback)(uiCheckbox *, void *); -import "C" - -// 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 { - ControlBase - 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) - freestr(ctext) - - C.uiCheckboxOnToggled(c.c, C.checkboxCallback(C.doCheckboxOnToggled), nil) - - c.ControlBase = NewControlBase(c, uintptr(unsafe.Pointer(c.c))) - return c -} - -// 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 := ControlFromLibui(uintptr(unsafe.Pointer(cc))).(*Checkbox) - 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/BBB_GOFILES/window.go b/BBB_GOFILES/window.go deleted file mode 100644 index a40ddd9..0000000 --- a/BBB_GOFILES/window.go +++ /dev/null @@ -1,125 +0,0 @@ -// 12 december 2015 - -package ui - -import ( - "unsafe" -) - -// #include "ui.h" -// extern int doWindowOnClosing(uiWindow *, void *); -// // see golang/go#19835 -// typedef int (*windowOnClosingCallback)(uiWindow *, void *); -import "C" - -// Window is a Control that represents a top-level window. -// A Window contains one child Control that occupies the -// entirety of the window. Though a Window is a Control, -// a Window cannot be the child of another Control. -type Window struct { - ControlBase - w *C.uiWindow - child Control - onClosing func(w *Window) bool -} - -// NewWindow creates a new Window. -func NewWindow(title string, width int, height int, hasMenubar bool) *Window { - w := new(Window) - - ctitle := C.CString(title) - w.w = C.uiNewWindow(ctitle, C.int(width), C.int(height), frombool(hasMenubar)) - freestr(ctitle) - - C.uiWindowOnClosing(w.w, C.windowOnClosingCallback(C.doWindowOnClosing), nil) - - w.ControlBase = NewControlBase(w, uintptr(unsafe.Pointer(w.w))) - return w -} - -// Destroy destroys the Window. If the Window has a child, -// Destroy calls Destroy on that as well. -func (w *Window) Destroy() { - w.Hide() // first hide the window, in case anything in the below if statement forces an immediate redraw - if w.child != nil { - c := w.child - w.SetChild(nil) - c.Destroy() - } - w.ControlBase.Destroy() -} - -// Title returns the Window's title. -func (w *Window) Title() string { - ctitle := C.uiWindowTitle(w.w) - title := C.GoString(ctitle) - C.uiFreeText(ctitle) - return title -} - -// SetTitle sets the Window's title to title. -func (w *Window) SetTitle(title string) { - ctitle := C.CString(title) - C.uiWindowSetTitle(w.w, ctitle) - freestr(ctitle) -} - -// TODO ContentSize -// TODO SetContentSize -// TODO Fullscreen -// TODO SetFullscreen -// TODO OnContentSizeChanged - -// OnClosing registers f to be run when the user clicks the Window's -// close button. Only one function can be registered at a time. -// If f returns true, the window is destroyed with the Destroy method. -// If f returns false, or if OnClosing is never called, the window is not -// destroyed and is kept visible. -func (w *Window) OnClosing(f func(*Window) bool) { - w.onClosing = f -} - -//export doWindowOnClosing -func doWindowOnClosing(ww *C.uiWindow, data unsafe.Pointer) C.int { - w := ControlFromLibui(uintptr(unsafe.Pointer(ww))).(*Window) - if w.onClosing == nil { - return 0 - } - if w.onClosing(w) { - w.Destroy() - } - return 0 -} - -// Borderless returns whether the Window is borderless. -func (w *Window) Borderless() bool { - return tobool(C.uiWindowBorderless(w.w)) -} - -// SetBorderless sets the Window to be borderless or not. -func (w *Window) SetBorderless(borderless bool) { - C.uiWindowSetBorderless(w.w, frombool(borderless)) -} - -// SetChild sets the Window's child to child. If child is nil, the Window -// will not have a child. -func (w *Window) SetChild(child Control) { - w.child = child - c := (*C.uiControl)(nil) - if w.child != nil { - c = touiControl(w.child.LibuiControl()) - } - C.uiWindowSetChild(w.w, c) -} - -// Margined returns whether the Window has margins around its child. -func (w *Window) Margined() bool { - return tobool(C.uiWindowMargined(w.w)) -} - -// SetMargined controls whether the Window has margins around its -// child. The size of the margins are determined by the OS and its -// best practices. -func (w *Window) SetMargined(margined bool) { - C.uiWindowSetMargined(w.w, frombool(margined)) -} |
