UI: Fix packing bug in the GUITest
This commit is contained in:
parent
fb8f4b1029
commit
2a162a86dd
|
@ -86,12 +86,12 @@ func (w *Frame) computePacked(e render.Engine) {
|
||||||
xDirection int32 = 1
|
xDirection int32 = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
if anchor.IsSouth() { // TODO: these need tuning
|
if anchor.IsSouth() {
|
||||||
y = frameSize.H - w.BoxThickness(4)
|
y = frameSize.H - w.BoxThickness(4)
|
||||||
yDirection = -1 * w.BoxThickness(4) // parent + child BoxThickness(1) = 2
|
yDirection = -1
|
||||||
} else if anchor == E {
|
} else if anchor.IsEast() {
|
||||||
x = frameSize.W - w.BoxThickness(4)
|
x = frameSize.W - w.BoxThickness(4)
|
||||||
xDirection = -1 - w.BoxThickness(4) // - w.BoxThickness(2)
|
xDirection = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, packedWidget := range w.packs[anchor] {
|
for _, packedWidget := range w.packs[anchor] {
|
||||||
|
@ -104,8 +104,8 @@ func (w *Frame) computePacked(e render.Engine) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
x += pack.PadX
|
x += pack.PadX * xDirection
|
||||||
y += pack.PadY
|
y += pack.PadY * yDirection
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// point = child.Point()
|
// point = child.Point()
|
||||||
|
@ -150,8 +150,8 @@ func (w *Frame) computePacked(e render.Engine) {
|
||||||
if len(expanded) > 0 && !frameSize.IsZero() && frameSize.Bigger(computedSize) {
|
if len(expanded) > 0 && !frameSize.IsZero() && frameSize.Bigger(computedSize) {
|
||||||
// Divy up the size available.
|
// Divy up the size available.
|
||||||
growBy := render.Rect{
|
growBy := render.Rect{
|
||||||
W: ((frameSize.W - computedSize.W) / int32(len(expanded))), // - w.BoxThickness(2),
|
W: ((frameSize.W - computedSize.W) / int32(len(expanded))) - w.BoxThickness(4),
|
||||||
H: ((frameSize.H - computedSize.H) / int32(len(expanded))), // - w.BoxThickness(2),
|
H: ((frameSize.H - computedSize.H) / int32(len(expanded))) - w.BoxThickness(4),
|
||||||
}
|
}
|
||||||
for _, pw := range expanded {
|
for _, pw := range expanded {
|
||||||
pw.widget.ResizeBy(growBy)
|
pw.widget.ResizeBy(growBy)
|
||||||
|
|
|
@ -91,7 +91,7 @@ func (w *Label) Compute(e render.Engine) {
|
||||||
)
|
)
|
||||||
|
|
||||||
if !w.FixedSize() {
|
if !w.FixedSize() {
|
||||||
w.resizeAuto(render.Rect{
|
w.ResizeAuto(render.Rect{
|
||||||
W: maxRect.W + (padX * 2),
|
W: maxRect.W + (padX * 2),
|
||||||
H: maxRect.H + (padY * 2),
|
H: maxRect.H + (padY * 2),
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"git.kirsle.net/apps/doodle/lib/render"
|
"git.kirsle.net/apps/doodle/lib/render"
|
||||||
"git.kirsle.net/apps/doodle/lib/ui/theme"
|
"git.kirsle.net/apps/doodle/lib/ui/theme"
|
||||||
)
|
)
|
||||||
|
@ -29,6 +31,7 @@ type Widget interface {
|
||||||
BoxSize() render.Rect // Return the full size including the border and outline.
|
BoxSize() render.Rect // Return the full size including the border and outline.
|
||||||
Resize(render.Rect)
|
Resize(render.Rect)
|
||||||
ResizeBy(render.Rect)
|
ResizeBy(render.Rect)
|
||||||
|
ResizeAuto(render.Rect)
|
||||||
Rect() render.Rect // Return the full absolute rect combining the Size() and Point()
|
Rect() render.Rect // Return the full absolute rect combining the Size() and Point()
|
||||||
|
|
||||||
Handle(Event, func(render.Point))
|
Handle(Event, func(render.Point))
|
||||||
|
@ -249,8 +252,14 @@ func (w *BaseWidget) ResizeBy(v render.Rect) {
|
||||||
w.height += v.H
|
w.height += v.H
|
||||||
}
|
}
|
||||||
|
|
||||||
// resizeAuto sets the size of the widget but doesn't set the fixedSize flag.
|
// ResizeAuto sets the size of the widget but doesn't set the fixedSize flag.
|
||||||
func (w *BaseWidget) resizeAuto(v render.Rect) {
|
func (w *BaseWidget) ResizeAuto(v render.Rect) {
|
||||||
|
if w.ID() == "Frame<Window Body>" {
|
||||||
|
fmt.Printf("%s: ResizeAuto Called: %+v\n",
|
||||||
|
w.ID(),
|
||||||
|
v,
|
||||||
|
)
|
||||||
|
}
|
||||||
w.width = v.W
|
w.width = v.W
|
||||||
w.height = v.H
|
w.height = v.H
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,9 @@ func (s *EditorScene) Setup(d *Doodle) error {
|
||||||
s.debSwatch = new(string)
|
s.debSwatch = new(string)
|
||||||
s.debWorldIndex = new(string)
|
s.debWorldIndex = new(string)
|
||||||
customDebugLabels = []debugLabel{
|
customDebugLabels = []debugLabel{
|
||||||
{"Pixel", s.debWorldIndex},
|
{"Pixel:", s.debWorldIndex},
|
||||||
{"Tool", s.debTool},
|
{"Tool:", s.debTool},
|
||||||
{"Swatch", s.debSwatch},
|
{"Swatch:", s.debSwatch},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the user interface. It references the palette and such so it
|
// Initialize the user interface. It references the palette and such so it
|
||||||
|
|
|
@ -17,11 +17,12 @@ type GUITestScene struct {
|
||||||
// Private widgets.
|
// Private widgets.
|
||||||
Frame *ui.Frame
|
Frame *ui.Frame
|
||||||
Window *ui.Frame
|
Window *ui.Frame
|
||||||
|
body *ui.Frame
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name of the scene.
|
// Name of the scene.
|
||||||
func (s *GUITestScene) Name() string {
|
func (s *GUITestScene) Name() string {
|
||||||
return "Main"
|
return "GUITest"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the scene.
|
// Setup the scene.
|
||||||
|
@ -64,6 +65,7 @@ func (s *GUITestScene) Setup(d *Doodle) error {
|
||||||
Anchor: ui.N,
|
Anchor: ui.N,
|
||||||
Expand: true,
|
Expand: true,
|
||||||
})
|
})
|
||||||
|
s.body = body
|
||||||
|
|
||||||
// Left Frame
|
// Left Frame
|
||||||
leftFrame := ui.NewFrame("Left Frame")
|
leftFrame := ui.NewFrame("Left Frame")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user