Compare commits

..

1 Commits

Author SHA1 Message Date
e602a517f6 Supervisor, Frame Pack and Misc Fixes
* Button: do not call MoveTo inside of Compute().
* Label: do not call MoveTo inside of Compute().
* MainWindow: add OnLoop callback function support so you can run custom code
  each loop and react to the event.State before the UI updates.
* Supervisor: locate widgets using AbsolutePosition() instead of w.Point()
  to play nice with Frame and Window packed widgets.
* Widget interface: rename Adopt() to SetParent() which makes more sense for
  what the function actually does.
* Window: set itself as the parent of the body Frame so that the Supervisor
  can locate widgets anywhere inside a window's frames.

Frame packing fixes:

* Widgets with Expand:true grow their space with ResizeAuto to preserve the
  FixedSize() boolean, instead of being hard-resized to fill the Frame.
* Widgets that Fill their space are resized with ResizeAuto too.

Outstanding bugs:

* Labels don't expand (window title bars, etc.)
2019-12-28 23:56:00 -08:00

View File

@ -1,6 +1,8 @@
package ui
import (
"fmt"
"git.kirsle.net/go/render"
"git.kirsle.net/go/ui/theme"
)
@ -66,7 +68,7 @@ type Widget interface {
// child widgets and the parent.
Parent() (parent Widget, ok bool)
SetParent(parent Widget) // for the container to assign itself the parent
Children() []Widget // for containers to return their children
Children() []Widget // for containers to return their children
// Run any render computations; by the end the widget must know its
// Width and Height. For example the Label widget will render itself onto
@ -252,6 +254,12 @@ func (w *BaseWidget) ResizeBy(v render.Rect) {
// ResizeAuto sets the size of the widget but doesn't set the fixedSize flag.
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.height = v.H
}