Added rendering of bounds in debug mode.
This commit is contained in:
parent
5a4dcd52b0
commit
764f2a0dd2
22
ui/debug.go
22
ui/debug.go
@ -77,8 +77,9 @@ func NewDebugOverlay(root Control) *debugOverlay {
|
|||||||
|
|
||||||
func (o *debugOverlay) renderControl(ctx Context, control Control) {
|
func (o *debugOverlay) renderControl(ctx Context, control Control) {
|
||||||
renderer := ctx.Renderer()
|
renderer := ctx.Renderer()
|
||||||
// bounds := control.Bounds()
|
|
||||||
// renderer.Rectangle(bounds, o.boundsColor, 1)
|
currentColor := zntg.MustHexColor("#FF0000")
|
||||||
|
parentColor := zntg.MustHexColor("#0000FF")
|
||||||
|
|
||||||
var maxY float32
|
var maxY float32
|
||||||
var renderHoverNode func(pos geom.PointF32, node *controlNode)
|
var renderHoverNode func(pos geom.PointF32, node *controlNode)
|
||||||
@ -96,6 +97,10 @@ func (o *debugOverlay) renderControl(ctx Context, control Control) {
|
|||||||
renderer.FillRectangle(pos.RectRel2D(nameTextureWidth, nameTextureHeight), color.Black)
|
renderer.FillRectangle(pos.RectRel2D(nameTextureWidth, nameTextureHeight), color.Black)
|
||||||
renderer.DrawTexturePoint(nameTexture, pos)
|
renderer.DrawTexturePoint(nameTexture, pos)
|
||||||
childPos := pos.Add2D(nameTextureWidth+ctx.Style().Dimensions.Margin, 0)
|
childPos := pos.Add2D(nameTextureWidth+ctx.Style().Dimensions.Margin, 0)
|
||||||
|
if len(node.Children) == 0 {
|
||||||
|
renderer.Rectangle(node.Parent.Bounds, parentColor, 1)
|
||||||
|
renderer.Rectangle(node.Bounds, currentColor, 1)
|
||||||
|
}
|
||||||
for _, child := range node.Children {
|
for _, child := range node.Children {
|
||||||
if childPos.Y == maxY {
|
if childPos.Y == maxY {
|
||||||
childPos.Y = maxY + nameTextureHeight
|
childPos.Y = maxY + nameTextureHeight
|
||||||
@ -114,15 +119,18 @@ func (o *debugOverlay) renderControl(ctx Context, control Control) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createHoverNodes(hover geom.PointF32, control Control) *controlNode {
|
func createHoverNodes(hover geom.PointF32, control Control) *controlNode {
|
||||||
if !hover.In(control.Bounds()) {
|
bounds := control.Bounds()
|
||||||
|
if !hover.In(bounds) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
node := &controlNode{Name: controlName(control)}
|
node := &controlNode{Name: controlName(control), Bounds: bounds}
|
||||||
for _, child := range controlChildren(control) {
|
for _, child := range controlChildren(control) {
|
||||||
childNode := createHoverNodes(hover, child)
|
childNode := createHoverNodes(hover, child)
|
||||||
if childNode != nil {
|
if childNode == nil {
|
||||||
node.Children = append(node.Children, childNode)
|
continue
|
||||||
}
|
}
|
||||||
|
childNode.Parent = node
|
||||||
|
node.Children = append(node.Children, childNode)
|
||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
@ -147,5 +155,7 @@ func (o *debugOverlay) Shown() {}
|
|||||||
|
|
||||||
type controlNode struct {
|
type controlNode struct {
|
||||||
Name string
|
Name string
|
||||||
|
Bounds geom.RectangleF32
|
||||||
|
Parent *controlNode
|
||||||
Children []*controlNode
|
Children []*controlNode
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user