func (g *Grid) regrid() { g.reflex() _, minXs, maxXs := g.hflex.constrain(g.Size.X) _, minYs, maxYs := g.vflex.constrain(g.Size.Y) for child, csh := range g.ChildrenHints { bd := g.childrenBlockData[child] gridBounds := geom.Rect{ Min: geom.Coord{ X: minXs[bd.GridX], Y: minYs[bd.GridY], }, Max: geom.Coord{ X: maxXs[bd.GridX+bd.ExtraX], Y: maxYs[bd.GridY+bd.ExtraY], }, } gridSizeX, gridSizeY := gridBounds.Size() if gridSizeX > csh.MaxSize.X { diff := gridSizeX - csh.MaxSize.X if bd.AnchorX&AnchorMin != 0 && bd.AnchorX&AnchorMax != 0 { gridBounds.Min.X += diff / 2 gridBounds.Max.X -= diff / 2 } else if bd.AnchorX&AnchorMin != 0 { gridBounds.Max.X -= diff } else if bd.AnchorX&AnchorMax != 0 { gridBounds.Min.X += diff } } if gridSizeY > csh.MaxSize.Y { diff := gridSizeY - csh.MaxSize.Y if bd.AnchorY&AnchorMin == 0 && bd.AnchorY&AnchorMax == 0 { gridBounds.Min.Y += diff / 2 gridBounds.Max.Y -= diff / 2 } else if bd.AnchorY&AnchorMin != 0 { gridBounds.Max.Y -= diff } else if bd.AnchorY&AnchorMax != 0 { gridBounds.Min.Y += diff } } gridSizeX, gridSizeY = gridBounds.Size() if gridSizeX > csh.PreferredSize.X { diff := gridSizeX - csh.PreferredSize.X if bd.AnchorX&AnchorMin != 0 && bd.AnchorX&AnchorMax != 0 { gridBounds.Min.X += diff / 2 gridBounds.Max.X -= diff / 2 } else if bd.AnchorX&AnchorMin != 0 { gridBounds.Max.X -= diff } else if bd.AnchorX&AnchorMax != 0 { gridBounds.Min.X += diff } } if gridSizeY > csh.PreferredSize.Y { diff := gridSizeY - csh.PreferredSize.Y if bd.AnchorY&AnchorMin == 0 && bd.AnchorY&AnchorMax == 0 { gridBounds.Min.Y += diff / 2 gridBounds.Max.Y -= diff / 2 } else if bd.AnchorY&AnchorMin != 0 { gridBounds.Max.Y -= diff } else if bd.AnchorY&AnchorMax != 0 { gridBounds.Min.Y += diff } } g.ChildrenBounds[child] = gridBounds gridSizeX, gridSizeY = gridBounds.Size() child.UserEventsIn <- uik.ResizeEvent{ Size: geom.Coord{gridSizeX, gridSizeY}, } } g.Invalidate() }
func (g *GridEngine) GetLayout(size geom.Coord) (layout Layout) { layout = make(Layout) _, minXs, maxXs := g.hflex.constrain(size.X) _, minYs, maxYs := g.vflex.constrain(size.Y) // if g.Block.ID == 2 { // uik.Report("regrid", g.Block.ID, g.Size, whs, wvs) // } for child, csh := range g.childrenHints { bd := g.childrenGridComponents[child] gridBounds := geom.Rect{ Min: geom.Coord{ X: minXs[bd.GridX], Y: minYs[bd.GridY], }, Max: geom.Coord{ X: maxXs[bd.GridX+bd.ExtraX], Y: maxYs[bd.GridY+bd.ExtraY], }, } gridSizeX, gridSizeY := gridBounds.Size() if gridSizeX > csh.MaxSize.X { diff := gridSizeX - csh.MaxSize.X if !bd.AnchorLeft && !bd.AnchorRight { gridBounds.Min.X += diff / 2 gridBounds.Max.X -= diff / 2 } if bd.AnchorLeft && !bd.AnchorRight { gridBounds.Max.X -= diff } if !bd.AnchorLeft && bd.AnchorRight { gridBounds.Min.X += diff } } if gridSizeY > csh.MaxSize.Y { diff := gridSizeY - csh.MaxSize.Y if !bd.AnchorTop && !bd.AnchorBottom { gridBounds.Min.Y += diff / 2 gridBounds.Max.Y -= diff / 2 } if bd.AnchorTop && !bd.AnchorBottom { gridBounds.Max.Y -= diff } if !bd.AnchorTop && bd.AnchorBottom { gridBounds.Min.Y += diff } } gridSizeX, gridSizeY = gridBounds.Size() if gridSizeX > csh.PreferredSize.X { diff := gridSizeX - csh.PreferredSize.X if !bd.AnchorLeft && !bd.AnchorRight { gridBounds.Min.X += diff / 2 gridBounds.Max.X -= diff / 2 } if bd.AnchorLeft && !bd.AnchorRight { gridBounds.Max.X -= diff } if !bd.AnchorLeft && bd.AnchorRight { gridBounds.Min.X += diff } } if gridSizeY > csh.PreferredSize.Y { diff := gridSizeY - csh.PreferredSize.Y if !bd.AnchorTop && !bd.AnchorBottom { gridBounds.Min.Y += diff / 2 gridBounds.Max.Y -= diff / 2 } if bd.AnchorTop && !bd.AnchorBottom { gridBounds.Max.Y -= diff } if !bd.AnchorTop && bd.AnchorBottom { gridBounds.Min.Y += diff } } layout[child] = gridBounds } return }