Re-added Stack. Of course it only works right on GTK+ right now... the other platforms's Control.preferredSize()s aren't implemented yet!
This commit is contained in:
parent
9daab20fce
commit
8b1756e952
|
@ -58,18 +58,26 @@ func (s *Stack) SetStretchy(index int) {
|
||||||
s.stretchy[index] = true
|
s.stretchy[index] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stack) make(window *sysData) error {
|
func (s *Stack) setParent(parent *controlParent) {
|
||||||
for i, c := range s.controls {
|
for _, c := range s.controls {
|
||||||
err := c.make(window)
|
c.setParent(parent)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error adding control %d to Stack: %v", i, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
s.created = true
|
s.created = true
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stack) allocate(x int, y int, width int, height int, d *sysSizeData) (allocations []*allocation) {
|
func (s *Stack) containerShow() {
|
||||||
|
for _, c := range s.controls {
|
||||||
|
c.containerShow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Stack) containerHide() {
|
||||||
|
for _, c := range s.controls {
|
||||||
|
c.containerHide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Stack) allocate(x int, y int, width int, height int, d *sizing) (allocations []*allocation) {
|
||||||
var stretchywid, stretchyht int
|
var stretchywid, stretchyht int
|
||||||
var current *allocation // for neighboring
|
var current *allocation // for neighboring
|
||||||
|
|
||||||
|
@ -142,7 +150,7 @@ func (s *Stack) allocate(x int, y int, width int, height int, d *sysSizeData) (a
|
||||||
|
|
||||||
// The preferred size of a Stack is the sum of the preferred sizes of non-stretchy controls + (the number of stretchy controls * the largest preferred size among all stretchy controls).
|
// The preferred size of a Stack is the sum of the preferred sizes of non-stretchy controls + (the number of stretchy controls * the largest preferred size among all stretchy controls).
|
||||||
// We don't consider the margins here, but will need to in container if Window.SizeToFit() is ever made a thing. TODO
|
// We don't consider the margins here, but will need to in container if Window.SizeToFit() is ever made a thing. TODO
|
||||||
func (s *Stack) preferredSize(d *sysSizeData) (width int, height int) {
|
func (s *Stack) preferredSize(d *sizing) (width int, height int) {
|
||||||
max := func(a int, b int) int {
|
max := func(a int, b int) int {
|
||||||
if a > b {
|
if a > b {
|
||||||
return a
|
return a
|
||||||
|
@ -188,11 +196,11 @@ func (s *Stack) preferredSize(d *sysSizeData) (width int, height int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stack) commitResize(c *allocation, d *sysSizeData) {
|
func (s *Stack) commitResize(c *allocation, d *sizing) {
|
||||||
// this is to satisfy Control; nothing to do here
|
// this is to satisfy Control; nothing to do here
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stack) getAuxResizeInfo(d *sysSizeData) {
|
func (s *Stack) getAuxResizeInfo(d *sizing) {
|
||||||
// this is to satisfy Control; nothing to do here
|
// this is to satisfy Control; nothing to do here
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ var ddata = []dtype{
|
||||||
type testwin struct {
|
type testwin struct {
|
||||||
t Tab
|
t Tab
|
||||||
w Window
|
w Window
|
||||||
|
s *Stack // TODO make Stack
|
||||||
l Label
|
l Label
|
||||||
table Table
|
table Table
|
||||||
b Button
|
b Button
|
||||||
|
@ -48,6 +49,14 @@ func (tw *testwin) make(done chan struct{}) {
|
||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
stack1 := NewHorizontalStack(NewLabel("Test"), NewTextField())
|
||||||
|
stack1.SetStretchy(1)
|
||||||
|
stack2 := NewHorizontalStack(NewLabel("Test 2"),
|
||||||
|
NewTable(reflect.TypeOf(struct{A,B,C int}{})))
|
||||||
|
stack2.SetStretchy(1)
|
||||||
|
tw.s = NewVerticalStack(stack1, stack2)
|
||||||
|
tw.s.SetStretchy(1)
|
||||||
|
tw.t.Append("Stack", tw.s)
|
||||||
tw.l = NewStandaloneLabel("hello")
|
tw.l = NewStandaloneLabel("hello")
|
||||||
tw.t.Append("Label", tw.l)
|
tw.t.Append("Label", tw.l)
|
||||||
tw.table = NewTable(reflect.TypeOf(ddata[0]))
|
tw.table = NewTable(reflect.TypeOf(ddata[0]))
|
||||||
|
|
Loading…
Reference in New Issue