Layout: review r2 fixes
This commit is contained in:
7 files changed
+105
-30
No files matched your search
+7
-6
@@ -1,6 +1,10 @@
|
||||
package mujica
|
||||
|
||||
import "github.com/egoist/mygo/ui"
|
||||
import (
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"mujicaui/internal"
|
||||
)
|
||||
|
||||
// AspectRatioOptions configure an AspectRatio.
|
||||
type AspectRatioOptions struct {
|
||||
@@ -22,6 +26,7 @@ func AspectRatio(c *ui.Context, opts AspectRatioOptions, child func()) *ui.Eleme
|
||||
}
|
||||
outer := ui.Box(c).Fill().Center()
|
||||
room := outer.Bounds()
|
||||
internal.Remeasure(c, outer, room.W, room.H)
|
||||
return outer.Children(func() {
|
||||
frame := ui.Box(c).AspectRatio(r).Shrink(0).Center().Clip()
|
||||
was := frame.Bounds()
|
||||
@@ -31,12 +36,8 @@ func AspectRatio(c *ui.Context, opts AspectRatioOptions, child func()) *ui.Eleme
|
||||
w = min(w, room.H*r)
|
||||
}
|
||||
if w <= 0 {
|
||||
// Not laid out yet: lay out once, then size from the room.
|
||||
// Not laid out yet: Remeasure rebuilds once the room is known.
|
||||
frame.WidthPercent(100)
|
||||
if first := ui.Local(outer, "aspect_ratio.first", func() bool { return true }); *first {
|
||||
*first = false
|
||||
c.Invalidate()
|
||||
}
|
||||
} else {
|
||||
frame.Width(w)
|
||||
if w-was.W > 0.5 || was.W-w > 0.5 {
|
||||
|
||||
Reference in new issue
Block a user