From c05fc0d645e64d93700fde886c4af322544e03e5 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 11 Aug 2018 22:02:16 -0400 Subject: Migrated the containers. --- AAA_GOFILES/box.go | 121 -------------------------------------- AAA_GOFILES/group.go | 117 ------------------------------------- AAA_GOFILES/tab.go | 127 ---------------------------------------- AAA_GOFILES/window.go | 159 -------------------------------------------------- box.go | 85 +++++++++++++++++++++++++++ group.go | 80 +++++++++++++++++++++++++ tab.go | 87 +++++++++++++++++++++++++++ window.go | 124 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 376 insertions(+), 524 deletions(-) delete mode 100644 AAA_GOFILES/box.go delete mode 100644 AAA_GOFILES/group.go delete mode 100644 AAA_GOFILES/tab.go delete mode 100644 AAA_GOFILES/window.go create mode 100644 box.go create mode 100644 group.go create mode 100644 tab.go create mode 100644 window.go diff --git a/AAA_GOFILES/box.go b/AAA_GOFILES/box.go deleted file mode 100644 index caf49e3..0000000 --- a/AAA_GOFILES/box.go +++ /dev/null @@ -1,121 +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 { - 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/group.go b/AAA_GOFILES/group.go deleted file mode 100644 index 0f9b99a..0000000 --- a/AAA_GOFILES/group.go +++ /dev/null @@ -1,117 +0,0 @@ -// 12 december 2015 - -package ui - -import ( - "unsafe" -) - -// #include "ui.h" -import "C" - -// Group is a Control that holds another Control and wraps it around -// 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 - g *C.uiGroup - - child Control -} - -// NewGroup creates a new Group. -func NewGroup(title string) *Group { - g := new(Group) - - ctitle := C.CString(title) - g.g = C.uiNewGroup(ctitle) - g.c = (*C.uiControl)(unsafe.Pointer(g.g)) - freestr(ctitle) - - return g -} - -// Destroy destroys the Group. If the Group has a child, -// Destroy calls Destroy on that as well. -func (g *Group) Destroy() { - if g.child != nil { - c := g.child - 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) -} - -// Title returns the Group's title. -func (g *Group) Title() string { - ctitle := C.uiGroupTitle(g.g) - title := C.GoString(ctitle) - C.uiFreeText(ctitle) - return title -} - -// SetTitle sets the Group's title to title. -func (g *Group) SetTitle(title string) { - ctitle := C.CString(title) - C.uiGroupSetTitle(g.g, ctitle) - freestr(ctitle) -} - -// SetChild sets the Group's child to child. If child is nil, the Group -// will not have a child. -func (g *Group) SetChild(child Control) { - g.child = child - c := (*C.uiControl)(nil) - if g.child != nil { - c = touiControl(g.child.LibuiControl()) - } - C.uiGroupSetChild(g.g, c) -} - -// Margined returns whether the Group has margins around its child. -func (g *Group) Margined() bool { - return tobool(C.uiGroupMargined(g.g)) -} - -// SetMargined controls whether the Group has margins around its -// child. The size of the margins are determined by the OS and its -// best practices. -func (g *Group) SetMargined(margined bool) { - C.uiGroupSetMargined(g.g, frombool(margined)) -} diff --git a/AAA_GOFILES/tab.go b/AAA_GOFILES/tab.go deleted file mode 100644 index d18cecd..0000000 --- a/AAA_GOFILES/tab.go +++ /dev/null @@ -1,127 +0,0 @@ -// 12 december 2015 - -package ui - -import ( - "unsafe" -) - -// #include "ui.h" -import "C" - -// Tab is a Control that holds tabbed pages of Controls. Each tab -// 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 - t *C.uiTab - - children []Control -} - -// NewTab creates a new Tab. -func NewTab() *Tab { - t := new(Tab) - - t.t = C.uiNewTab() - t.c = (*C.uiControl)(unsafe.Pointer(t.t)) - - return t -} - -// Destroy destroys the Tab. If the Tab has pages, -// Destroy calls Destroy on the pages's Controls as well. -func (t *Tab) Destroy() { - for len(t.children) != 0 { - c := t.children[0] - 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) -} - -// Append adds the given page to the end of the Tab. -func (t *Tab) Append(name string, child Control) { - t.InsertAt(name, len(t.children), child) -} - -// InsertAt adds the given page to the Tab such that it is the -// nth page of the Tab (starting at 0). -func (t *Tab) InsertAt(name string, n int, child Control) { - c := (*C.uiControl)(nil) - if child != nil { - 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) - freestr(cname) - ch := make([]Control, len(t.children) + 1) - // and insert into t.children at the right place - copy(ch[:n], t.children[:n]) - ch[n] = child - copy(ch[n + 1:], t.children[n:]) - t.children = ch -} - -// Delete deletes the nth page of the Tab. -func (t *Tab) Delete(n int) { - t.children = append(t.children[:n], t.children[n + 1:]...) - C.uiTabDelete(t.t, C.uintmax_t(n)) -} - -// NumPages returns the number of pages in the Tab. -func (t *Tab) NumPages() int { - return len(t.children) -} - -// Margined returns whether page n (starting at 0) of the Tab -// has margins around its child. -func (t *Tab) Margined(n int) bool { - return tobool(C.uiTabMargined(t.t, C.uintmax_t(n))) -} - -// SetMargined controls whether page n (starting at 0) of the Tab -// has margins around its child. The size of the margins are -// determined by the OS and its best practices. -func (t *Tab) SetMargined(n int, margined bool) { - C.uiTabSetMargined(t.t, C.uintmax_t(n), frombool(margined)) -} diff --git a/AAA_GOFILES/window.go b/AAA_GOFILES/window.go deleted file mode 100644 index bdd230c..0000000 --- a/AAA_GOFILES/window.go +++ /dev/null @@ -1,159 +0,0 @@ -// 12 december 2015 - -package ui - -import ( - "unsafe" -) - -// #include "ui.h" -// extern int doOnClosing(uiWindow *, void *); -// static inline void realuiWindowOnClosing(uiWindow *w) -// { -// uiWindowOnClosing(w, doOnClosing, NULL); -// } -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 - 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) - // 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 - - 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 - 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) -} - -// 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) -} - -// 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 doOnClosing -func doOnClosing(ww *C.uiWindow, data unsafe.Pointer) C.int { - w := windows[ww] - if w.onClosing == nil { - return 0 - } - if w.onClosing(w) { - w.Destroy() - } - return 0 -} - -// 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)) -} diff --git a/box.go b/box.go new file mode 100644 index 0000000..a0cfb77 --- /dev/null +++ b/box.go @@ -0,0 +1,85 @@ +// 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) + 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/group.go b/group.go new file mode 100644 index 0000000..6992948 --- /dev/null +++ b/group.go @@ -0,0 +1,80 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "ui.h" +import "C" + +// Group is a Control that holds another Control and wraps it around +// a labelled box (though some systems make this box invisible). +// You can use this to group related controls together. +type Group struct { + ControlBase + g *C.uiGroup + child Control +} + +// NewGroup creates a new Group. +func NewGroup(title string) *Group { + g := new(Group) + + ctitle := C.CString(title) + g.g = C.uiNewGroup(ctitle) + freestr(ctitle) + + g.ControlBase = NewControlBase(g, uintptr(unsafe.Pointer(g.g))) + return g +} + +// Destroy destroys the Group. If the Group has a child, +// Destroy calls Destroy on that as well. +func (g *Group) Destroy() { + if g.child != nil { + c := g.child + g.SetChild(nil) + c.Destroy() + } + g.ControlBase.Destroy() +} + +// Title returns the Group's title. +func (g *Group) Title() string { + ctitle := C.uiGroupTitle(g.g) + title := C.GoString(ctitle) + C.uiFreeText(ctitle) + return title +} + +// SetTitle sets the Group's title to title. +func (g *Group) SetTitle(title string) { + ctitle := C.CString(title) + C.uiGroupSetTitle(g.g, ctitle) + freestr(ctitle) +} + +// SetChild sets the Group's child to child. If child is nil, the Group +// will not have a child. +func (g *Group) SetChild(child Control) { + g.child = child + c := (*C.uiControl)(nil) + if g.child != nil { + c = touiControl(g.child.LibuiControl()) + } + C.uiGroupSetChild(g.g, c) +} + +// Margined returns whether the Group has margins around its child. +func (g *Group) Margined() bool { + return tobool(C.uiGroupMargined(g.g)) +} + +// SetMargined controls whether the Group has margins around its +// child. The size of the margins are determined by the OS and its +// best practices. +func (g *Group) SetMargined(margined bool) { + C.uiGroupSetMargined(g.g, frombool(margined)) +} diff --git a/tab.go b/tab.go new file mode 100644 index 0000000..6fcaccf --- /dev/null +++ b/tab.go @@ -0,0 +1,87 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "ui.h" +import "C" + +// Tab is a Control that holds tabbed pages of Controls. Each tab +// has a label. The user can click on the tabs themselves to switch +// pages. Individual pages can also have margins. +type Tab struct { + ControlBase + t *C.uiTab + children []Control +} + +// NewTab creates a new Tab. +func NewTab() *Tab { + t := new(Tab) + + t.t = C.uiNewTab() + + t.ControlBase = NewControlBase(t, uintptr(unsafe.Pointer(t.t))) + return t +} + +// Destroy destroys the Tab. If the Tab has pages, +// Destroy calls Destroy on the pages's Controls as well. +func (t *Tab) Destroy() { + for len(t.children) != 0 { + c := t.children[0] + t.Delete(0) + c.Destroy() + } + t.ControlBase.Destroy() +} + +// Append adds the given page to the end of the Tab. +func (t *Tab) Append(name string, child Control) { + t.InsertAt(name, len(t.children), child) +} + +// InsertAt adds the given page to the Tab such that it is the +// nth page of the Tab (starting at 0). +func (t *Tab) InsertAt(name string, n int, child Control) { + c := (*C.uiControl)(nil) + if child != nil { + c = touiControl(child.LibuiControl()) + } + cname := C.CString(name) + 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 + copy(ch[:n], t.children[:n]) + ch[n] = child + copy(ch[n + 1:], t.children[n:]) + t.children = ch +} + +// Delete deletes the nth page of the Tab. +func (t *Tab) Delete(n int) { + t.children = append(t.children[:n], t.children[n + 1:]...) + C.uiTabDelete(t.t, C.uintmax_t(n)) +} + +// NumPages returns the number of pages in the Tab. +func (t *Tab) NumPages() int { + return len(t.children) +} + +// Margined returns whether page n (starting at 0) of the Tab +// has margins around its child. +func (t *Tab) Margined(n int) bool { + return tobool(C.uiTabMargined(t.t, C.uintmax_t(n))) +} + +// SetMargined controls whether page n (starting at 0) of the Tab +// has margins around its child. The size of the margins are +// determined by the OS and its best practices. +func (t *Tab) SetMargined(n int, margined bool) { + C.uiTabSetMargined(t.t, C.uintmax_t(n), frombool(margined)) +} diff --git a/window.go b/window.go new file mode 100644 index 0000000..c446123 --- /dev/null +++ b/window.go @@ -0,0 +1,124 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "ui.h" +// extern int doWindowOnClosing(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) + // 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)) + freestr(ctitle) + + 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() { + 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)) +} -- cgit v1.2.3