summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2018-08-11 22:02:16 -0400
committerPietro Gagliardi <[email protected]>2018-08-11 22:02:16 -0400
commitc05fc0d645e64d93700fde886c4af322544e03e5 (patch)
tree7d62af3b82cba62eaaabfcb37de95b2b6050f8f2
parent68ffb808678159b8810c8ed093c0458316d3f8f2 (diff)
Migrated the containers.
-rw-r--r--box.go (renamed from AAA_GOFILES/box.go)44
-rw-r--r--group.go (renamed from AAA_GOFILES/group.go)43
-rw-r--r--tab.go (renamed from AAA_GOFILES/tab.go)48
-rw-r--r--window.go (renamed from AAA_GOFILES/window.go)85
4 files changed, 36 insertions, 184 deletions
diff --git a/AAA_GOFILES/box.go b/box.go
index caf49e3..a0cfb77 100644
--- a/AAA_GOFILES/box.go
+++ b/box.go
@@ -18,9 +18,8 @@ import "C"
// 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
+ ControlBase
b *C.uiBox
-
children []Control
}
@@ -29,8 +28,8 @@ func NewHorizontalBox() *Box {
b := new(Box)
b.b = C.uiNewHorizontalBox()
- b.c = (*C.uiControl)(unsafe.Pointer(b.b))
+ b.ControlBase = NewControlBase(b, uintptr(unsafe.Pointer(b.b)))
return b
}
@@ -39,8 +38,8 @@ func NewVerticalBox() *Box {
b := new(Box)
b.b = C.uiNewVerticalBox()
- b.c = (*C.uiControl)(unsafe.Pointer(b.b))
+ b.ControlBase = NewControlBase(b, uintptr(unsafe.Pointer(b.b)))
return b
}
@@ -52,42 +51,7 @@ func (b *Box) Destroy() {
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)
+ b.ControlBase.Destroy()
}
// Append adds the given control to the end of the Box.
diff --git a/AAA_GOFILES/group.go b/group.go
index 0f9b99a..6992948 100644
--- a/AAA_GOFILES/group.go
+++ b/group.go
@@ -13,9 +13,8 @@ import "C"
// a labelled box (though some systems make this box invisible).
// You can use this to group related controls together.
type Group struct {
- c *C.uiControl
+ ControlBase
g *C.uiGroup
-
child Control
}
@@ -25,9 +24,9 @@ func NewGroup(title string) *Group {
ctitle := C.CString(title)
g.g = C.uiNewGroup(ctitle)
- g.c = (*C.uiControl)(unsafe.Pointer(g.g))
freestr(ctitle)
+ g.ControlBase = NewControlBase(g, uintptr(unsafe.Pointer(g.g)))
return g
}
@@ -39,43 +38,7 @@ func (g *Group) Destroy() {
g.SetChild(nil)
c.Destroy()
}
- C.uiControlDestroy(g.c)
-}
-
-// LibuiControl returns the libui uiControl pointer that backs
-// the Group. This is only used by package ui itself and should
-// not be called by programs.
-func (g *Group) LibuiControl() uintptr {
- return uintptr(unsafe.Pointer(g.c))
-}
-
-// Handle returns the OS-level handle associated with this Group.
-// 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 GtkFrame.
-// On OS X this is a pointer to a NSBox.
-func (g *Group) Handle() uintptr {
- return uintptr(C.uiControlHandle(g.c))
-}
-
-// Show shows the Group.
-func (g *Group) Show() {
- C.uiControlShow(g.c)
-}
-
-// Hide hides the Group.
-func (g *Group) Hide() {
- C.uiControlHide(g.c)
-}
-
-// Enable enables the Group.
-func (g *Group) Enable() {
- C.uiControlEnable(g.c)
-}
-
-// Disable disables the Group.
-func (g *Group) Disable() {
- C.uiControlDisable(g.c)
+ g.ControlBase.Destroy()
}
// Title returns the Group's title.
diff --git a/AAA_GOFILES/tab.go b/tab.go
index d18cecd..6fcaccf 100644
--- a/AAA_GOFILES/tab.go
+++ b/tab.go
@@ -13,9 +13,8 @@ import "C"
// has a label. The user can click on the tabs themselves to switch
// pages. Individual pages can also have margins.
type Tab struct {
- c *C.uiControl
+ ControlBase
t *C.uiTab
-
children []Control
}
@@ -24,8 +23,8 @@ func NewTab() *Tab {
t := new(Tab)
t.t = C.uiNewTab()
- t.c = (*C.uiControl)(unsafe.Pointer(t.t))
+ t.ControlBase = NewControlBase(t, uintptr(unsafe.Pointer(t.t)))
return t
}
@@ -37,45 +36,7 @@ func (t *Tab) Destroy() {
t.Delete(0)
c.Destroy()
}
- C.uiControlDestroy(t.c)
-}
-
-// LibuiControl returns the libui uiControl pointer that backs
-// the Tab. This is only used by package ui itself and should
-// not be called by programs.
-func (t *Tab) LibuiControl() uintptr {
- return uintptr(unsafe.Pointer(t.c))
-}
-
-// Handle returns the OS-level handle associated with this Tab.
-// On Windows this is an HWND of a standard Windows API
-// WC_TABCONTROL class (as provided by Common Controls
-// version 6). The pages are not children of this window and there
-// currently is no way to directly access them.
-// On GTK+ this is a pointer to a GtkNotebook.
-// On OS X this is a pointer to a NSTabView.
-func (t *Tab) Handle() uintptr {
- return uintptr(C.uiControlHandle(t.c))
-}
-
-// Show shows the Tab.
-func (t *Tab) Show() {
- C.uiControlShow(t.c)
-}
-
-// Hide hides the Tab.
-func (t *Tab) Hide() {
- C.uiControlHide(t.c)
-}
-
-// Enable enables the Tab.
-func (t *Tab) Enable() {
- C.uiControlEnable(t.c)
-}
-
-// Disable disables the Tab.
-func (t *Tab) Disable() {
- C.uiControlDisable(t.c)
+ t.ControlBase.Destroy()
}
// Append adds the given page to the end of the Tab.
@@ -91,8 +52,7 @@ func (t *Tab) InsertAt(name string, n int, child Control) {
c = touiControl(child.LibuiControl())
}
cname := C.CString(name)
- // TODO why is this uintmax_t and not intmax_t
- C.uiTabInsertAt(t.t, cname, C.uintmax_t(n), c)
+ C.uiTabInsertAt(t.t, cname, C.int(n), c)
freestr(cname)
ch := make([]Control, len(t.children) + 1)
// and insert into t.children at the right place
diff --git a/AAA_GOFILES/window.go b/window.go
index bdd230c..c446123 100644
--- a/AAA_GOFILES/window.go
+++ b/window.go
@@ -7,26 +7,17 @@ import (
)
// #include "ui.h"
-// extern int doOnClosing(uiWindow *, void *);
-// static inline void realuiWindowOnClosing(uiWindow *w)
-// {
-// uiWindowOnClosing(w, doOnClosing, NULL);
-// }
+// extern int doWindowOnClosing(uiWindow *, void *);
import "C"
-// no need to lock this; only the GUI thread can access it
-var windows = make(map[*C.uiWindow]*Window)
-
// 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 {
- c *C.uiControl
+ ControlBase
w *C.uiWindow
-
child Control
-
onClosing func(w *Window) bool
}
@@ -37,66 +28,24 @@ func NewWindow(title string, width int, height int, hasMenubar bool) *Window {
ctitle := C.CString(title)
// TODO wait why did I make these ints and not intmax_ts?
w.w = C.uiNewWindow(ctitle, C.int(width), C.int(height), frombool(hasMenubar))
- w.c = (*C.uiControl)(unsafe.Pointer(w.w))
freestr(ctitle)
- C.realuiWindowOnClosing(w.w)
- windows[w.w] = w
+ C.uiWindowOnClosing(w.w, 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() {
- // first hide ourselves
- w.Hide()
- // get rid of the child
+ 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()
}
- // unregister events
- delete(windows, w.w)
- // and finally destroy ourselves
- C.uiControlDestroy(w.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 (w *Window) LibuiControl() uintptr {
- return uintptr(unsafe.Pointer(w.c))
-}
-
-// Handle returns the OS-level handle associated with this Window.
-// On Windows this is an HWND of a libui-internal class.
-// On GTK+ this is a pointer to a GtkWindow.
-// On OS X this is a pointer to a NSWindow.
-func (w *Window) Handle() uintptr {
- return uintptr(C.uiControlHandle(w.c))
-}
-
-// Show shows the Window. It uses the OS conception of "presenting"
-// the Window, whatever that may be on a given OS.
-func (w *Window) Show() {
- C.uiControlShow(w.c)
-}
-
-// Hide hides the Window.
-func (w *Window) Hide() {
- C.uiControlHide(w.c)
-}
-
-// Enable enables the Window.
-func (w *Window) Enable() {
- C.uiControlEnable(w.c)
-}
-
-// Disable disables the Window.
-func (w *Window) Disable() {
- C.uiControlDisable(w.c)
+ w.ControlBase.Destroy()
}
// Title returns the Window's title.
@@ -114,6 +63,12 @@ func (w *Window) SetTitle(title string) {
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.
@@ -123,9 +78,9 @@ func (w *Window) OnClosing(f func(*Window) bool) {
w.onClosing = f
}
-//export doOnClosing
-func doOnClosing(ww *C.uiWindow, data unsafe.Pointer) C.int {
- w := windows[ww]
+//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
}
@@ -135,6 +90,16 @@ func doOnClosing(ww *C.uiWindow, data unsafe.Pointer) C.int {
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) {