From 1095719d84a6ac5f90eefe8e23913f3e09ad692d Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 26 Aug 2018 13:33:54 -0400 Subject: Migrated more controls. --- BBB_GOFILES/combobox.go | 67 ---------------------------- BBB_GOFILES/editablecombobox.go | 72 ------------------------------- BBB_GOFILES/entry.go | 93 --------------------------------------- BBB_GOFILES/form.go | 71 ------------------------------ BBB_GOFILES/grid.go | 96 ----------------------------------------- BBB_GOFILES/group.go | 80 ---------------------------------- BBB_GOFILES/label.go | 44 ------------------- BBB_GOFILES/progressbar.go | 39 ----------------- combobox.go | 64 +++++++++++++++++++++++++++ editablecombobox.go | 69 +++++++++++++++++++++++++++++ entry.go | 90 ++++++++++++++++++++++++++++++++++++++ form.go | 71 ++++++++++++++++++++++++++++++ grid.go | 96 +++++++++++++++++++++++++++++++++++++++++ group.go | 80 ++++++++++++++++++++++++++++++++++ label.go | 44 +++++++++++++++++++ pkgui.c | 15 +++++++ pkgui.h | 14 ++++++ progressbar.go | 39 +++++++++++++++++ 18 files changed, 582 insertions(+), 562 deletions(-) delete mode 100644 BBB_GOFILES/combobox.go delete mode 100644 BBB_GOFILES/editablecombobox.go delete mode 100644 BBB_GOFILES/entry.go delete mode 100644 BBB_GOFILES/form.go delete mode 100644 BBB_GOFILES/grid.go delete mode 100644 BBB_GOFILES/group.go delete mode 100644 BBB_GOFILES/label.go delete mode 100644 BBB_GOFILES/progressbar.go create mode 100644 combobox.go create mode 100644 editablecombobox.go create mode 100644 entry.go create mode 100644 form.go create mode 100644 grid.go create mode 100644 group.go create mode 100644 label.go create mode 100644 progressbar.go diff --git a/BBB_GOFILES/combobox.go b/BBB_GOFILES/combobox.go deleted file mode 100644 index 1e381de..0000000 --- a/BBB_GOFILES/combobox.go +++ /dev/null @@ -1,67 +0,0 @@ -// 12 december 2015 - -package ui - -import ( - "unsafe" -) - -// #include "ui.h" -// extern void doComboboxOnSelected(uiCombobox *, void *); -// // see golang/go#19835 -// typedef void (*comboboxCallback)(uiCombobox *, void *); -import "C" - -// Combobox is a Control that represents a drop-down list of strings -// that the user can choose one of at any time. For a Combobox that -// users can type values into, see EditableCombobox. -type Combobox struct { - ControlBase - c *C.uiCombobox - onSelected func(*Combobox) -} - -// NewCombobox creates a new Combobox. -func NewCombobox() *Combobox { - c := new(Combobox) - - c.c = C.uiNewCombobox() - - C.uiComboboxOnSelected(c.c, C.comboboxCallback(C.doComboboxOnSelected), nil) - - c.ControlBase = NewControlBase(c, uintptr(unsafe.Pointer(c.c))) - return c -} - -// Append adds the named item to the end of the Combobox. -func (c *Combobox) Append(text string) { - ctext := C.CString(text) - C.uiComboboxAppend(c.c, ctext) - freestr(ctext) -} - -// Selected returns the index of the currently selected item in the -// Combobox, or -1 if nothing is selected. -func (c *Combobox) Selected() int { - return int(C.uiComboboxSelected(c.c)) -} - -// 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.int(index)) -} - -// OnSelected registers f to be run when the user selects an item in -// the Combobox. Only one function can be registered at a time. -func (c *Combobox) OnSelected(f func(*Combobox)) { - c.onSelected = f -} - -//export doComboboxOnSelected -func doComboboxOnSelected(cc *C.uiCombobox, data unsafe.Pointer) { - c := ControlFromLibui(uintptr(unsafe.Pointer(cc))).(*Combobox) - if c.onSelected != nil { - c.onSelected(c) - } -} diff --git a/BBB_GOFILES/editablecombobox.go b/BBB_GOFILES/editablecombobox.go deleted file mode 100644 index 1242928..0000000 --- a/BBB_GOFILES/editablecombobox.go +++ /dev/null @@ -1,72 +0,0 @@ -// 12 december 2015 - -package ui - -import ( - "unsafe" -) - -// #include "ui.h" -// extern void doEditableComboboxOnChanged(uiEditableCombobox *, void *); -// // see golang/go#19835 -// typedef void (*editableComboboxCallback)(uiEditableCombobox *, void *); -import "C" - -// EditableCombobox is a Control that represents a drop-down list -// of strings that the user can choose one of at any time. It also has -// an entry field that the user can type an alternate choice into. -type EditableCombobox struct { - ControlBase - c *C.uiEditableCombobox - onChanged func(*EditableCombobox) -} - -// NewEditableCombobox creates a new EditableCombobox. -func NewEditableCombobox() *EditableCombobox { - c := new(EditableCombobox) - - c.c = C.uiNewEditableCombobox() - - C.uiEditableComboboxOnChanged(c.c, C.editableComboboxCallback(C.doEditableComboboxOnChanged), nil) - - c.ControlBase = NewControlBase(c, uintptr(unsafe.Pointer(c.c))) - return c -} - -// Append adds the named item to the end of the EditableCombobox. -func (e *EditableCombobox) Append(text string) { - ctext := C.CString(text) - C.uiEditableComboboxAppend(e.c, ctext) - freestr(ctext) -} - -// Text returns the text in the entry of the EditableCombobox, which -// could be one of the choices in the list if the user has selected one. -func (e *EditableCombobox) Text() string { - ctext := C.uiEditableComboboxText(e.c) - text := C.GoString(ctext) - C.uiFreeText(ctext) - return text -} - -// SetText sets the text in the entry of the EditableCombobox. -func (e *EditableCombobox) SetText(text string) { - ctext := C.CString(text) - C.uiEditableComboboxSetText(e.c, ctext) - freestr(ctext) -} - -// OnChanged registers f to be run when the user either selects an -// item or changes the text in the EditableCombobox. Only one -// function can be registered at a time. -func (e *EditableCombobox) OnChanged(f func(*EditableCombobox)) { - e.onChanged = f -} - -//export doEditableComboboxOnChanged -func doEditableComboboxOnChanged(cc *C.uiEditableCombobox, data unsafe.Pointer) { - e := ControlFromLibui(uintptr(unsafe.Pointer(cc))).(*EditableCombobox) - if e.onChanged != nil { - e.onChanged(e) - } -} diff --git a/BBB_GOFILES/entry.go b/BBB_GOFILES/entry.go deleted file mode 100644 index 52da537..0000000 --- a/BBB_GOFILES/entry.go +++ /dev/null @@ -1,93 +0,0 @@ -// 12 december 2015 - -// TODO typing in entry in OS X crashes libui -// I've had similar issues with checkboxes on libui -// something's wrong with NSMapTable - -package ui - -import ( - "unsafe" -) - -// #include "ui.h" -// extern void doEntryOnChanged(uiEntry *, void *); -// // see golang/go#19835 -// typedef void (*entryCallback)(uiEntry *, void *); -import "C" - -// Entry is a Control that represents a space that the user can -// type a single line of text into. -type Entry struct { - ControlBase - e *C.uiEntry - onChanged func(*Entry) -} - -func finishNewEntry(ee *C.uiEntry) *Entry { - e := new(Entry) - - e.e = ee - - C.uiEntryOnChanged(e.e, C.entryCallback(C.doEntryOnChanged), nil) - - e.ControlBase = NewControlBase(e, uintptr(unsafe.Pointer(e.e))) - return e -} - -// NewEntry creates a new Entry. -func NewEntry() *Entry { - return finishNewEntry(C.uiNewEntry()) -} - -// NewPasswordEntry creates a new Entry whose contents are -// visibly obfuscated, suitable for passwords. -func NewPasswordEntry() *Entry { - return finishNewEntry(C.uiNewPasswordEntry()) -} - -// NewSearchEntry creates a new Entry suitable for searching with. -// Changed events may, depending on the system, be delayed -// with a search Entry, to produce a smoother user experience. -func NewSearchEntry() *Entry { - return finishNewEntry(C.uiNewSearchEntry()) -} - -// Text returns the Entry's text. -func (e *Entry) Text() string { - ctext := C.uiEntryText(e.e) - text := C.GoString(ctext) - C.uiFreeText(ctext) - return text -} - -// SetText sets the Entry's text to text. -func (e *Entry) SetText(text string) { - ctext := C.CString(text) - C.uiEntrySetText(e.e, ctext) - freestr(ctext) -} - -// OnChanged registers f to be run when the user makes a change to -// the Entry. Only one function can be registered at a time. -func (e *Entry) OnChanged(f func(*Entry)) { - e.onChanged = f -} - -//export doEntryOnChanged -func doEntryOnChanged(ee *C.uiEntry, data unsafe.Pointer) { - e := ControlFromLibui(uintptr(unsafe.Pointer(ee))).(*Entry) - if e.onChanged != nil { - e.onChanged(e) - } -} - -// ReadOnly returns whether the Entry can be changed. -func (e *Entry) ReadOnly() bool { - return tobool(C.uiEntryReadOnly(e.e)) -} - -// SetReadOnly sets whether the Entry can be changed. -func (e *Entry) SetReadOnly(ro bool) { - C.uiEntrySetReadOnly(e.e, frombool(ro)) -} diff --git a/BBB_GOFILES/form.go b/BBB_GOFILES/form.go deleted file mode 100644 index 6f8a282..0000000 --- a/BBB_GOFILES/form.go +++ /dev/null @@ -1,71 +0,0 @@ -// 12 december 2015 - -package ui - -import ( - "unsafe" -) - -// #include "ui.h" -import "C" - -// Form is a Control that holds a group of Controls vertically -// with labels next to each. By default, each control has its -// preferred height; 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 Form struct { - ControlBase - f *C.uiForm - children []Control -} - -// NewForm creates a new horizontal Form. -func NewForm() *Form { - f := new(Form) - - f.f = C.uiNewForm() - - f.ControlBase = NewControlBase(f, uintptr(unsafe.Pointer(f.f))) - return f -} - -// Destroy destroys the Form. If the Form has children, -// Destroy calls Destroy on those Controls as well. -func (f *Form) Destroy() { - for len(f.children) != 0 { - c := f.children[0] - f.Delete(0) - c.Destroy() - } - f.ControlBase.Destroy() -} - -// Append adds the given control to the end of the Form. -func (f *Form) Append(label string, child Control, stretchy bool) { - clabel := C.CString(label) - defer freestr(clabel) - c := touiControl(child.LibuiControl()) - C.uiFormAppend(f.f, clabel, c, frombool(stretchy)) - f.children = append(f.children, child) -} - -// Delete deletes the nth control of the Form. -func (f *Form) Delete(n int) { - f.children = append(f.children[:n], f.children[n + 1:]...) - C.uiFormDelete(f.f, C.int(n)) -} - -// Padded returns whether there is space between each control -// of the Form. -func (f *Form) Padded() bool { - return tobool(C.uiFormPadded(f.f)) -} - -// SetPadded controls whether there is space between each control -// of the Form. The size of the padding is determined by the OS and -// its best practices. -func (f *Form) SetPadded(padded bool) { - C.uiFormSetPadded(f.f, frombool(padded)) -} diff --git a/BBB_GOFILES/grid.go b/BBB_GOFILES/grid.go deleted file mode 100644 index a1985fc..0000000 --- a/BBB_GOFILES/grid.go +++ /dev/null @@ -1,96 +0,0 @@ -// 12 december 2015 - -package ui - -import ( - "unsafe" -) - -// #include "ui.h" -import "C" - -// Grid is a Control that arranges other Controls in a grid. -// Grid is a very powerful container: it can position and size each -// Control in several ways and can (and must) have Controls added -// to it in any direction. It can also have Controls spanning multiple -// rows and columns. -// -// Each Control in a Grid has associated "expansion" and -// "alignment" values in both the X and Y direction. -// Expansion determines whether all cells in the same row/column -// are given whatever space is left over after figuring out how big -// the rest of the Grid should be. Alignment determines the position -// of a Control relative to its cell after computing the above. The -// special alignment Fill can be used to grow a Control to fit its cell. -// Note that expansion and alignment are independent variables. -// For more information on expansion and alignment, read -// https://developer.gnome.org/gtk3/unstable/ch28s02.html. -type Grid struct { - ControlBase - g *C.uiGrid - children []Control -} - -// Align represents the alignment of a Control in its cell of a Grid. -type Align int -const ( - AlignFill Align = iota - AlignStart - AlignCenter - AlignEnd -) - -// At represents a side of a Control to add other Controls to a Grid to. -type At int -const ( - Leading At = iota - Top - Trailing - Bottom -) - -// NewGrid creates a new Grid. -func NewGrid() *Grid { - g := new(Grid) - - g.g = C.uiNewGrid() - - g.ControlBase = NewControlBase(g, uintptr(unsafe.Pointer(g.g))) - return g -} - -// TODO Destroy - -// Append adds the given control to the Grid, at the given coordinate. -func (g *Grid) Append(child Control, left, top int, xspan, yspan int, hexpand bool, halign Align, vexpand bool, valign Align) { - C.uiGridAppend(g.g, touiControl(child.LibuiControl()), - C.int(left), C.int(top), - C.int(xspan), C.int(yspan), - frombool(hexpand), C.uiAlign(halign), - frombool(vexpand), C.uiAlign(valign)) - g.children = append(g.children, child) -} - -// InsertAt adds the given control to the Grid relative to an existing -// control. -func (g *Grid) InsertAt(child Control, existing Control, at At, xspan, yspan int, hexpand bool, halign Align, vexpand bool, valign Align) { - C.uiGridInsertAt(g.g, touiControl(child.LibuiControl()), - touiControl(existing.LibuiControl()), C.uiAt(at), - C.int(xspan), C.int(yspan), - frombool(hexpand), C.uiAlign(halign), - frombool(vexpand), C.uiAlign(valign)) - g.children = append(g.children, child) -} - -// Padded returns whether there is space between each control -// of the Grid. -func (g *Grid) Padded() bool { - return tobool(C.uiGridPadded(g.g)) -} - -// SetPadded controls whether there is space between each control -// of the Grid. The size of the padding is determined by the OS and -// its best practices. -func (g *Grid) SetPadded(padded bool) { - C.uiGridSetPadded(g.g, frombool(padded)) -} diff --git a/BBB_GOFILES/group.go b/BBB_GOFILES/group.go deleted file mode 100644 index 6992948..0000000 --- a/BBB_GOFILES/group.go +++ /dev/null @@ -1,80 +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 { - 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/BBB_GOFILES/label.go b/BBB_GOFILES/label.go deleted file mode 100644 index cac7680..0000000 --- a/BBB_GOFILES/label.go +++ /dev/null @@ -1,44 +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. -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) -} diff --git a/BBB_GOFILES/progressbar.go b/BBB_GOFILES/progressbar.go deleted file mode 100644 index f58976f..0000000 --- a/BBB_GOFILES/progressbar.go +++ /dev/null @@ -1,39 +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 { - 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)) -} diff --git a/combobox.go b/combobox.go new file mode 100644 index 0000000..60df08a --- /dev/null +++ b/combobox.go @@ -0,0 +1,64 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "pkgui.h" +import "C" + +// Combobox is a Control that represents a drop-down list of strings +// that the user can choose one of at any time. For a Combobox that +// users can type values into, see EditableCombobox. +type Combobox struct { + ControlBase + c *C.uiCombobox + onSelected func(*Combobox) +} + +// NewCombobox creates a new Combobox. +func NewCombobox() *Combobox { + c := new(Combobox) + + c.c = C.uiNewCombobox() + + C.pkguiComboboxOnSelected(c.c) + + c.ControlBase = NewControlBase(c, uintptr(unsafe.Pointer(c.c))) + return c +} + +// Append adds the named item to the end of the Combobox. +func (c *Combobox) Append(text string) { + ctext := C.CString(text) + C.uiComboboxAppend(c.c, ctext) + freestr(ctext) +} + +// Selected returns the index of the currently selected item in the +// Combobox, or -1 if nothing is selected. +func (c *Combobox) Selected() int { + return int(C.uiComboboxSelected(c.c)) +} + +// 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.int(index)) +} + +// OnSelected registers f to be run when the user selects an item in +// the Combobox. Only one function can be registered at a time. +func (c *Combobox) OnSelected(f func(*Combobox)) { + c.onSelected = f +} + +//export pkguiDoComboboxOnSelected +func pkguiDoComboboxOnSelected(cc *C.uiCombobox, data unsafe.Pointer) { + c := ControlFromLibui(uintptr(unsafe.Pointer(cc))).(*Combobox) + if c.onSelected != nil { + c.onSelected(c) + } +} diff --git a/editablecombobox.go b/editablecombobox.go new file mode 100644 index 0000000..9c0d9d0 --- /dev/null +++ b/editablecombobox.go @@ -0,0 +1,69 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "pkgui.h" +import "C" + +// EditableCombobox is a Control that represents a drop-down list +// of strings that the user can choose one of at any time. It also has +// an entry field that the user can type an alternate choice into. +type EditableCombobox struct { + ControlBase + c *C.uiEditableCombobox + onChanged func(*EditableCombobox) +} + +// NewEditableCombobox creates a new EditableCombobox. +func NewEditableCombobox() *EditableCombobox { + c := new(EditableCombobox) + + c.c = C.uiNewEditableCombobox() + + C.pkguiEditableComboboxOnChanged(c.c) + + c.ControlBase = NewControlBase(c, uintptr(unsafe.Pointer(c.c))) + return c +} + +// Append adds the named item to the end of the EditableCombobox. +func (e *EditableCombobox) Append(text string) { + ctext := C.CString(text) + C.uiEditableComboboxAppend(e.c, ctext) + freestr(ctext) +} + +// Text returns the text in the entry of the EditableCombobox, which +// could be one of the choices in the list if the user has selected one. +func (e *EditableCombobox) Text() string { + ctext := C.uiEditableComboboxText(e.c) + text := C.GoString(ctext) + C.uiFreeText(ctext) + return text +} + +// SetText sets the text in the entry of the EditableCombobox. +func (e *EditableCombobox) SetText(text string) { + ctext := C.CString(text) + C.uiEditableComboboxSetText(e.c, ctext) + freestr(ctext) +} + +// OnChanged registers f to be run when the user either selects an +// item or changes the text in the EditableCombobox. Only one +// function can be registered at a time. +func (e *EditableCombobox) OnChanged(f func(*EditableCombobox)) { + e.onChanged = f +} + +//export pkguiDoEditableComboboxOnChanged +func pkguiDoEditableComboboxOnChanged(cc *C.uiEditableCombobox, data unsafe.Pointer) { + e := ControlFromLibui(uintptr(unsafe.Pointer(cc))).(*EditableCombobox) + if e.onChanged != nil { + e.onChanged(e) + } +} diff --git a/entry.go b/entry.go new file mode 100644 index 0000000..00c7dd7 --- /dev/null +++ b/entry.go @@ -0,0 +1,90 @@ +// 12 december 2015 + +// TODO typing in entry in OS X crashes libui +// I've had similar issues with checkboxes on libui +// something's wrong with NSMapTable + +package ui + +import ( + "unsafe" +) + +// #include "pkgui.h" +import "C" + +// Entry is a Control that represents a space that the user can +// type a single line of text into. +type Entry struct { + ControlBase + e *C.uiEntry + onChanged func(*Entry) +} + +func finishNewEntry(ee *C.uiEntry) *Entry { + e := new(Entry) + + e.e = ee + + C.pkguiEntryOnChanged(e.e) + + e.ControlBase = NewControlBase(e, uintptr(unsafe.Pointer(e.e))) + return e +} + +// NewEntry creates a new Entry. +func NewEntry() *Entry { + return finishNewEntry(C.uiNewEntry()) +} + +// NewPasswordEntry creates a new Entry whose contents are +// visibly obfuscated, suitable for passwords. +func NewPasswordEntry() *Entry { + return finishNewEntry(C.uiNewPasswordEntry()) +} + +// NewSearchEntry creates a new Entry suitable for searching with. +// Changed events may, depending on the system, be delayed +// with a search Entry, to produce a smoother user experience. +func NewSearchEntry() *Entry { + return finishNewEntry(C.uiNewSearchEntry()) +} + +// Text returns the Entry's text. +func (e *Entry) Text() string { + ctext := C.uiEntryText(e.e) + text := C.GoString(ctext) + C.uiFreeText(ctext) + return text +} + +// SetText sets the Entry's text to text. +func (e *Entry) SetText(text string) { + ctext := C.CString(text) + C.uiEntrySetText(e.e, ctext) + freestr(ctext) +} + +// OnChanged registers f to be run when the user makes a change to +// the Entry. Only one function can be registered at a time. +func (e *Entry) OnChanged(f func(*Entry)) { + e.onChanged = f +} + +//export pkguiDoEntryOnChanged +func pkguiDoEntryOnChanged(ee *C.uiEntry, data unsafe.Pointer) { + e := ControlFromLibui(uintptr(unsafe.Pointer(ee))).(*Entry) + if e.onChanged != nil { + e.onChanged(e) + } +} + +// ReadOnly returns whether the Entry can be changed. +func (e *Entry) ReadOnly() bool { + return tobool(C.uiEntryReadOnly(e.e)) +} + +// SetReadOnly sets whether the Entry can be changed. +func (e *Entry) SetReadOnly(ro bool) { + C.uiEntrySetReadOnly(e.e, frombool(ro)) +} diff --git a/form.go b/form.go new file mode 100644 index 0000000..aef7597 --- /dev/null +++ b/form.go @@ -0,0 +1,71 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "pkgui.h" +import "C" + +// Form is a Control that holds a group of Controls vertically +// with labels next to each. By default, each control has its +// preferred height; 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 Form struct { + ControlBase + f *C.uiForm + children []Control +} + +// NewForm creates a new horizontal Form. +func NewForm() *Form { + f := new(Form) + + f.f = C.uiNewForm() + + f.ControlBase = NewControlBase(f, uintptr(unsafe.Pointer(f.f))) + return f +} + +// Destroy destroys the Form. If the Form has children, +// Destroy calls Destroy on those Controls as well. +func (f *Form) Destroy() { + for len(f.children) != 0 { + c := f.children[0] + f.Delete(0) + c.Destroy() + } + f.ControlBase.Destroy() +} + +// Append adds the given control to the end of the Form. +func (f *Form) Append(label string, child Control, stretchy bool) { + clabel := C.CString(label) + defer freestr(clabel) + c := touiControl(child.LibuiControl()) + C.uiFormAppend(f.f, clabel, c, frombool(stretchy)) + f.children = append(f.children, child) +} + +// Delete deletes the nth control of the Form. +func (f *Form) Delete(n int) { + f.children = append(f.children[:n], f.children[n + 1:]...) + C.uiFormDelete(f.f, C.int(n)) +} + +// Padded returns whether there is space between each control +// of the Form. +func (f *Form) Padded() bool { + return tobool(C.uiFormPadded(f.f)) +} + +// SetPadded controls whether there is space between each control +// of the Form. The size of the padding is determined by the OS and +// its best practices. +func (f *Form) SetPadded(padded bool) { + C.uiFormSetPadded(f.f, frombool(padded)) +} diff --git a/grid.go b/grid.go new file mode 100644 index 0000000..7a027a8 --- /dev/null +++ b/grid.go @@ -0,0 +1,96 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "pkgui.h" +import "C" + +// Grid is a Control that arranges other Controls in a grid. +// Grid is a very powerful container: it can position and size each +// Control in several ways and can (and must) have Controls added +// to it in any direction. It can also have Controls spanning multiple +// rows and columns. +// +// Each Control in a Grid has associated "expansion" and +// "alignment" values in both the X and Y direction. +// Expansion determines whether all cells in the same row/column +// are given whatever space is left over after figuring out how big +// the rest of the Grid should be. Alignment determines the position +// of a Control relative to its cell after computing the above. The +// special alignment Fill can be used to grow a Control to fit its cell. +// Note that expansion and alignment are independent variables. +// For more information on expansion and alignment, read +// https://developer.gnome.org/gtk3/unstable/ch28s02.html. +type Grid struct { + ControlBase + g *C.uiGrid + children []Control +} + +// Align represents the alignment of a Control in its cell of a Grid. +type Align int +const ( + AlignFill Align = iota + AlignStart + AlignCenter + AlignEnd +) + +// At represents a side of a Control to add other Controls to a Grid to. +type At int +const ( + Leading At = iota + Top + Trailing + Bottom +) + +// NewGrid creates a new Grid. +func NewGrid() *Grid { + g := new(Grid) + + g.g = C.uiNewGrid() + + g.ControlBase = NewControlBase(g, uintptr(unsafe.Pointer(g.g))) + return g +} + +// TODO Destroy + +// Append adds the given control to the Grid, at the given coordinate. +func (g *Grid) Append(child Control, left, top int, xspan, yspan int, hexpand bool, halign Align, vexpand bool, valign Align) { + C.uiGridAppend(g.g, touiControl(child.LibuiControl()), + C.int(left), C.int(top), + C.int(xspan), C.int(yspan), + frombool(hexpand), C.uiAlign(halign), + frombool(vexpand), C.uiAlign(valign)) + g.children = append(g.children, child) +} + +// InsertAt adds the given control to the Grid relative to an existing +// control. +func (g *Grid) InsertAt(child Control, existing Control, at At, xspan, yspan int, hexpand bool, halign Align, vexpand bool, valign Align) { + C.uiGridInsertAt(g.g, touiControl(child.LibuiControl()), + touiControl(existing.LibuiControl()), C.uiAt(at), + C.int(xspan), C.int(yspan), + frombool(hexpand), C.uiAlign(halign), + frombool(vexpand), C.uiAlign(valign)) + g.children = append(g.children, child) +} + +// Padded returns whether there is space between each control +// of the Grid. +func (g *Grid) Padded() bool { + return tobool(C.uiGridPadded(g.g)) +} + +// SetPadded controls whether there is space between each control +// of the Grid. The size of the padding is determined by the OS and +// its best practices. +func (g *Grid) SetPadded(padded bool) { + C.uiGridSetPadded(g.g, frombool(padded)) +} diff --git a/group.go b/group.go new file mode 100644 index 0000000..4aaa24a --- /dev/null +++ b/group.go @@ -0,0 +1,80 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "pkgui.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/label.go b/label.go new file mode 100644 index 0000000..09d0b3c --- /dev/null +++ b/label.go @@ -0,0 +1,44 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "pkgui.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) +} diff --git a/pkgui.c b/pkgui.c index b6871a3..643f50e 100644 --- a/pkgui.c +++ b/pkgui.c @@ -36,3 +36,18 @@ void pkguiCheckboxOnToggled(uiCheckbox *c) { uiCheckboxOnToggled(c, pkguiDoCheckboxOnToggled, NULL); } + +void pkguiComboboxOnSelected(uiCombobox *c) +{ + uiComboboxOnSelected(c, pkguiDoComboboxOnSelected, NULL); +} + +void pkguiEditableComboboxOnChanged(uiEditableCombobox *c) +{ + uiEditableComboboxOnChanged(c, pkguiDoEditableComboboxOnChanged, NULL); +} + +void pkguiEntryOnChanged(uiEntry *e) +{ + uiEntryOnChanged(e, pkguiDoEntryOnChanged, NULL); +} diff --git a/pkgui.h b/pkgui.h index 6a0261b..eefea53 100644 --- a/pkgui.h +++ b/pkgui.h @@ -1,4 +1,7 @@ // 12 august 2018 +#ifndef pkguiHFileIncluded +#define pkguiHFileIncluded + #include #include "ui.h" @@ -16,3 +19,14 @@ extern void pkguiButtonOnClicked(uiButton *b); // checkbox.go extern void pkguiCheckboxOnToggled(uiCheckbox *c); + +// combobox.go +extern void pkguiComboboxOnSelected(uiCombobox *c); + +// editablecombobox.go +extern void pkguiEditableComboboxOnChanged(uiEditableCombobox *c); + +// entry.go +extern void pkguiEntryOnChanged(uiEntry *e); + +#endif diff --git a/progressbar.go b/progressbar.go new file mode 100644 index 0000000..4c771df --- /dev/null +++ b/progressbar.go @@ -0,0 +1,39 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "pkgui.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)) +} -- cgit v1.2.3