Migrated the containers.
This commit is contained in:
parent
68ffb80867
commit
c05fc0d645
|
@ -18,9 +18,8 @@ import "C"
|
||||||
// stretchy, they will be given equal shares of the leftover space.
|
// stretchy, they will be given equal shares of the leftover space.
|
||||||
// There can also be space between each control ("padding").
|
// There can also be space between each control ("padding").
|
||||||
type Box struct {
|
type Box struct {
|
||||||
c *C.uiControl
|
ControlBase
|
||||||
b *C.uiBox
|
b *C.uiBox
|
||||||
|
|
||||||
children []Control
|
children []Control
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +28,8 @@ func NewHorizontalBox() *Box {
|
||||||
b := new(Box)
|
b := new(Box)
|
||||||
|
|
||||||
b.b = C.uiNewHorizontalBox()
|
b.b = C.uiNewHorizontalBox()
|
||||||
b.c = (*C.uiControl)(unsafe.Pointer(b.b))
|
|
||||||
|
|
||||||
|
b.ControlBase = NewControlBase(b, uintptr(unsafe.Pointer(b.b)))
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,8 +38,8 @@ func NewVerticalBox() *Box {
|
||||||
b := new(Box)
|
b := new(Box)
|
||||||
|
|
||||||
b.b = C.uiNewVerticalBox()
|
b.b = C.uiNewVerticalBox()
|
||||||
b.c = (*C.uiControl)(unsafe.Pointer(b.b))
|
|
||||||
|
|
||||||
|
b.ControlBase = NewControlBase(b, uintptr(unsafe.Pointer(b.b)))
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,42 +51,7 @@ func (b *Box) Destroy() {
|
||||||
b.Delete(0)
|
b.Delete(0)
|
||||||
c.Destroy()
|
c.Destroy()
|
||||||
}
|
}
|
||||||
C.uiControlDestroy(b.c)
|
b.ControlBase.Destroy()
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
// Append adds the given control to the end of the Box.
|
|
@ -13,9 +13,8 @@ import "C"
|
||||||
// a labelled box (though some systems make this box invisible).
|
// a labelled box (though some systems make this box invisible).
|
||||||
// You can use this to group related controls together.
|
// You can use this to group related controls together.
|
||||||
type Group struct {
|
type Group struct {
|
||||||
c *C.uiControl
|
ControlBase
|
||||||
g *C.uiGroup
|
g *C.uiGroup
|
||||||
|
|
||||||
child Control
|
child Control
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,9 +24,9 @@ func NewGroup(title string) *Group {
|
||||||
|
|
||||||
ctitle := C.CString(title)
|
ctitle := C.CString(title)
|
||||||
g.g = C.uiNewGroup(ctitle)
|
g.g = C.uiNewGroup(ctitle)
|
||||||
g.c = (*C.uiControl)(unsafe.Pointer(g.g))
|
|
||||||
freestr(ctitle)
|
freestr(ctitle)
|
||||||
|
|
||||||
|
g.ControlBase = NewControlBase(g, uintptr(unsafe.Pointer(g.g)))
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,43 +38,7 @@ func (g *Group) Destroy() {
|
||||||
g.SetChild(nil)
|
g.SetChild(nil)
|
||||||
c.Destroy()
|
c.Destroy()
|
||||||
}
|
}
|
||||||
C.uiControlDestroy(g.c)
|
g.ControlBase.Destroy()
|
||||||
}
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Title returns the Group's title.
|
// Title returns the Group's title.
|
|
@ -13,9 +13,8 @@ import "C"
|
||||||
// has a label. The user can click on the tabs themselves to switch
|
// has a label. The user can click on the tabs themselves to switch
|
||||||
// pages. Individual pages can also have margins.
|
// pages. Individual pages can also have margins.
|
||||||
type Tab struct {
|
type Tab struct {
|
||||||
c *C.uiControl
|
ControlBase
|
||||||
t *C.uiTab
|
t *C.uiTab
|
||||||
|
|
||||||
children []Control
|
children []Control
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +23,8 @@ func NewTab() *Tab {
|
||||||
t := new(Tab)
|
t := new(Tab)
|
||||||
|
|
||||||
t.t = C.uiNewTab()
|
t.t = C.uiNewTab()
|
||||||
t.c = (*C.uiControl)(unsafe.Pointer(t.t))
|
|
||||||
|
|
||||||
|
t.ControlBase = NewControlBase(t, uintptr(unsafe.Pointer(t.t)))
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,45 +36,7 @@ func (t *Tab) Destroy() {
|
||||||
t.Delete(0)
|
t.Delete(0)
|
||||||
c.Destroy()
|
c.Destroy()
|
||||||
}
|
}
|
||||||
C.uiControlDestroy(t.c)
|
t.ControlBase.Destroy()
|
||||||
}
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append adds the given page to the end of the Tab.
|
// 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())
|
c = touiControl(child.LibuiControl())
|
||||||
}
|
}
|
||||||
cname := C.CString(name)
|
cname := C.CString(name)
|
||||||
// TODO why is this uintmax_t and not intmax_t
|
C.uiTabInsertAt(t.t, cname, C.int(n), c)
|
||||||
C.uiTabInsertAt(t.t, cname, C.uintmax_t(n), c)
|
|
||||||
freestr(cname)
|
freestr(cname)
|
||||||
ch := make([]Control, len(t.children) + 1)
|
ch := make([]Control, len(t.children) + 1)
|
||||||
// and insert into t.children at the right place
|
// and insert into t.children at the right place
|
|
@ -7,26 +7,17 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// #include "ui.h"
|
// #include "ui.h"
|
||||||
// extern int doOnClosing(uiWindow *, void *);
|
// extern int doWindowOnClosing(uiWindow *, void *);
|
||||||
// static inline void realuiWindowOnClosing(uiWindow *w)
|
|
||||||
// {
|
|
||||||
// uiWindowOnClosing(w, doOnClosing, NULL);
|
|
||||||
// }
|
|
||||||
import "C"
|
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.
|
// Window is a Control that represents a top-level window.
|
||||||
// A Window contains one child Control that occupies the
|
// A Window contains one child Control that occupies the
|
||||||
// entirety of the window. Though a Window is a Control,
|
// entirety of the window. Though a Window is a Control,
|
||||||
// a Window cannot be the child of another Control.
|
// a Window cannot be the child of another Control.
|
||||||
type Window struct {
|
type Window struct {
|
||||||
c *C.uiControl
|
ControlBase
|
||||||
w *C.uiWindow
|
w *C.uiWindow
|
||||||
|
|
||||||
child Control
|
child Control
|
||||||
|
|
||||||
onClosing func(w *Window) bool
|
onClosing func(w *Window) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,66 +28,24 @@ func NewWindow(title string, width int, height int, hasMenubar bool) *Window {
|
||||||
ctitle := C.CString(title)
|
ctitle := C.CString(title)
|
||||||
// TODO wait why did I make these ints and not intmax_ts?
|
// 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.w = C.uiNewWindow(ctitle, C.int(width), C.int(height), frombool(hasMenubar))
|
||||||
w.c = (*C.uiControl)(unsafe.Pointer(w.w))
|
|
||||||
freestr(ctitle)
|
freestr(ctitle)
|
||||||
|
|
||||||
C.realuiWindowOnClosing(w.w)
|
C.uiWindowOnClosing(w.w, C.doWindowOnClosing, nil)
|
||||||
windows[w.w] = w
|
|
||||||
|
|
||||||
|
w.ControlBase = NewControlBase(w, uintptr(unsafe.Pointer(w.w)))
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy destroys the Window. If the Window has a child,
|
// Destroy destroys the Window. If the Window has a child,
|
||||||
// Destroy calls Destroy on that as well.
|
// Destroy calls Destroy on that as well.
|
||||||
func (w *Window) Destroy() {
|
func (w *Window) Destroy() {
|
||||||
// first hide ourselves
|
w.Hide() // first hide the window, in case anything in the below if statement forces an immediate redraw
|
||||||
w.Hide()
|
|
||||||
// get rid of the child
|
|
||||||
if w.child != nil {
|
if w.child != nil {
|
||||||
c := w.child
|
c := w.child
|
||||||
w.SetChild(nil)
|
w.SetChild(nil)
|
||||||
c.Destroy()
|
c.Destroy()
|
||||||
}
|
}
|
||||||
// unregister events
|
w.ControlBase.Destroy()
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Title returns the Window's title.
|
// Title returns the Window's title.
|
||||||
|
@ -114,6 +63,12 @@ func (w *Window) SetTitle(title string) {
|
||||||
freestr(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
|
// OnClosing registers f to be run when the user clicks the Window's
|
||||||
// close button. Only one function can be registered at a time.
|
// 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 true, the window is destroyed with the Destroy method.
|
||||||
|
@ -123,9 +78,9 @@ func (w *Window) OnClosing(f func(*Window) bool) {
|
||||||
w.onClosing = f
|
w.onClosing = f
|
||||||
}
|
}
|
||||||
|
|
||||||
//export doOnClosing
|
//export doWindowOnClosing
|
||||||
func doOnClosing(ww *C.uiWindow, data unsafe.Pointer) C.int {
|
func doWindowOnClosing(ww *C.uiWindow, data unsafe.Pointer) C.int {
|
||||||
w := windows[ww]
|
w := ControlFromLibui(uintptr(unsafe.Pointer(ww))).(*Window)
|
||||||
if w.onClosing == nil {
|
if w.onClosing == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -135,6 +90,16 @@ func doOnClosing(ww *C.uiWindow, data unsafe.Pointer) C.int {
|
||||||
return 0
|
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
|
// SetChild sets the Window's child to child. If child is nil, the Window
|
||||||
// will not have a child.
|
// will not have a child.
|
||||||
func (w *Window) SetChild(child Control) {
|
func (w *Window) SetChild(child Control) {
|
Loading…
Reference in New Issue