Added Form.
This commit is contained in:
parent
c58171a39e
commit
62fcb5ffd0
1
box.go
1
box.go
|
@ -57,6 +57,7 @@ func (b *Box) Destroy() {
|
||||||
// Append adds the given control to the end of the Box.
|
// Append adds the given control to the end of the Box.
|
||||||
func (b *Box) Append(child Control, stretchy bool) {
|
func (b *Box) Append(child Control, stretchy bool) {
|
||||||
c := (*C.uiControl)(nil)
|
c := (*C.uiControl)(nil)
|
||||||
|
// TODO this part is wrong for Box?
|
||||||
if child != nil {
|
if child != nil {
|
||||||
c = touiControl(child.LibuiControl())
|
c = touiControl(child.LibuiControl())
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
// 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))
|
||||||
|
}
|
|
@ -28,32 +28,16 @@ func makeBasicControlsPage() ui.Control {
|
||||||
vbox.Append(group, true)
|
vbox.Append(group, true)
|
||||||
|
|
||||||
group.SetChild(ui.NewNonWrappingMultilineEntry())
|
group.SetChild(ui.NewNonWrappingMultilineEntry())
|
||||||
/*
|
|
||||||
entryForm = uiNewForm();
|
|
||||||
uiFormSetPadded(entryForm, 1);
|
|
||||||
uiGroupSetChild(group, uiControl(entryForm));
|
|
||||||
|
|
||||||
uiFormAppend(entryForm,
|
entryForm := ui.NewForm()
|
||||||
"Entry",
|
entryForm.SetPadded(true)
|
||||||
uiControl(uiNewEntry()),
|
group.SetChild(entryForm)
|
||||||
0);
|
|
||||||
uiFormAppend(entryForm,
|
entryForm.Append("Entry", ui.NewEntry(), false)
|
||||||
"Password Entry",
|
entryForm.Append("Password Entry", ui.NewPasswordEntry(), false)
|
||||||
uiControl(uiNewPasswordEntry()),
|
entryForm.Append("Search Entry", ui.NewSearchEntry(), false)
|
||||||
0);
|
entryForm.Append("Multiline Entry", ui.NewMultilineEntry(), true)
|
||||||
uiFormAppend(entryForm,
|
entryForm.Append("Multiline Entry No Wrap", ui.NewNonWrappingMultilineEntry(), true)
|
||||||
"Search Entry",
|
|
||||||
uiControl(uiNewSearchEntry()),
|
|
||||||
0);
|
|
||||||
uiFormAppend(entryForm,
|
|
||||||
"Multiline Entry",
|
|
||||||
uiControl(uiNewMultilineEntry()),
|
|
||||||
1);
|
|
||||||
uiFormAppend(entryForm,
|
|
||||||
"Multiline Entry No Wrap",
|
|
||||||
uiControl(uiNewNonWrappingMultilineEntry()),
|
|
||||||
1);
|
|
||||||
*/
|
|
||||||
|
|
||||||
return vbox
|
return vbox
|
||||||
}
|
}
|
||||||
|
@ -129,14 +113,10 @@ func makeDataChoosersPage() ui.Control {
|
||||||
vbox.Append(ui.NewDatePicker(), false)
|
vbox.Append(ui.NewDatePicker(), false)
|
||||||
vbox.Append(ui.NewTimePicker(), false)
|
vbox.Append(ui.NewTimePicker(), false)
|
||||||
vbox.Append(ui.NewDateTimePicker(), false)
|
vbox.Append(ui.NewDateTimePicker(), false)
|
||||||
/*
|
vbox.Append(ui.NewFontButton(), false)
|
||||||
uiBoxAppend(vbox,
|
vbox.Append(ui.NewColorButton(), false)
|
||||||
uiControl(uiNewFontButton()),
|
|
||||||
0);
|
|
||||||
uiBoxAppend(vbox,
|
|
||||||
uiControl(uiNewColorButton()),
|
|
||||||
0);
|
|
||||||
|
|
||||||
|
/*
|
||||||
uiBoxAppend(hbox,
|
uiBoxAppend(hbox,
|
||||||
uiControl(uiNewVerticalSeparator()),
|
uiControl(uiNewVerticalSeparator()),
|
||||||
0);
|
0);
|
||||||
|
|
|
@ -10,9 +10,12 @@ import (
|
||||||
"github.com/andlabs/ui"
|
"github.com/andlabs/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
var fontButton *ui.FontButton
|
var (
|
||||||
|
fontButton *ui.FontButton
|
||||||
|
alignment *ui.Combobox
|
||||||
|
|
||||||
var attrstr *ui.AttributedString
|
attrstr *ui.AttributedString
|
||||||
|
)
|
||||||
|
|
||||||
func appendWithAttributes(what string, attrs ...ui.Attribute) {
|
func appendWithAttributes(what string, attrs ...ui.Attribute) {
|
||||||
start := len(attrstr.String())
|
start := len(attrstr.String())
|
||||||
|
@ -44,7 +47,7 @@ func makeAttributedString() {
|
||||||
attrstr.AppendUnattributed(", ")
|
attrstr.AppendUnattributed(", ")
|
||||||
|
|
||||||
appendWithAttributes("text color", ui.TextColor{0.75, 0.25, 0.5, 0.75})
|
appendWithAttributes("text color", ui.TextColor{0.75, 0.25, 0.5, 0.75})
|
||||||
attrstr.AppendUnattributed(", ");
|
attrstr.AppendUnattributed(", ")
|
||||||
|
|
||||||
appendWithAttributes("text background color", ui.TextBackground{0.5, 0.5, 0.25, 0.5})
|
appendWithAttributes("text background color", ui.TextBackground{0.5, 0.5, 0.25, 0.5})
|
||||||
attrstr.AppendUnattributed(", ")
|
attrstr.AppendUnattributed(", ")
|
||||||
|
@ -84,7 +87,7 @@ func (areaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
||||||
String: attrstr,
|
String: attrstr,
|
||||||
DefaultFont: fontButton.Font(),
|
DefaultFont: fontButton.Font(),
|
||||||
Width: p.AreaWidth,
|
Width: p.AreaWidth,
|
||||||
Align: ui.DrawTextAlignLeft,
|
Align: ui.DrawTextAlign(alignment.Selected()),
|
||||||
})
|
})
|
||||||
defer tl.Free()
|
defer tl.Free()
|
||||||
p.Context.Text(tl, 0, 0)
|
p.Context.Text(tl, 0, 0)
|
||||||
|
@ -138,21 +141,21 @@ func setupUI() {
|
||||||
})
|
})
|
||||||
vbox.Append(fontButton, false)
|
vbox.Append(fontButton, false)
|
||||||
|
|
||||||
/*
|
form := ui.NewForm()
|
||||||
form = uiNewForm();
|
form.SetPadded(true)
|
||||||
uiFormSetPadded(form, 1);
|
|
||||||
// TODO on OS X if this is set to 1 then the window can't resize; does the form not have the concept of stretchy trailing space?
|
// TODO on OS X if this is set to 1 then the window can't resize; does the form not have the concept of stretchy trailing space?
|
||||||
uiBoxAppend(vbox, uiControl(form), 0);
|
vbox.Append(form, false)
|
||||||
|
|
||||||
alignment = uiNewCombobox();
|
alignment = ui.NewCombobox()
|
||||||
// note that the items match with the values of the uiDrawTextAlign values
|
// note that the items match with the values of the uiDrawTextAlign values
|
||||||
uiComboboxAppend(alignment, "Left");
|
alignment.Append("Left")
|
||||||
uiComboboxAppend(alignment, "Center");
|
alignment.Append("Center")
|
||||||
uiComboboxAppend(alignment, "Right");
|
alignment.Append("Right")
|
||||||
uiComboboxSetSelected(alignment, 0); // start with left alignment
|
alignment.SetSelected(0) // start with left alignment
|
||||||
uiComboboxOnSelected(alignment, onComboboxSelected, NULL);
|
alignment.OnSelected(func(*ui.Combobox) {
|
||||||
uiFormAppend(form, "Alignment", uiControl(alignment), 0);
|
area.QueueRedrawAll()
|
||||||
*/
|
})
|
||||||
|
form.Append("Alignment", alignment, false)
|
||||||
|
|
||||||
hbox.Append(area, true)
|
hbox.Append(area, true)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue