Sfoglia il codice sorgente

changed gui panel z coordinate calculation.
It is executed now every time a panel is added to its parent.

leonsal 8 anni fa
parent
commit
fa8e0b9814
4 ha cambiato i file con 48 aggiunte e 32 eliminazioni
  1. 0 3
      gui/dropdown.go
  2. 0 3
      gui/folder.go
  3. 33 25
      gui/panel.go
  4. 15 1
      gui/root.go

+ 0 - 3
gui/dropdown.go

@@ -40,8 +40,6 @@ type DropDownStyles struct {
 	Disabled *DropDownStyle
 }
 
-const dropDownZ = -0.5
-
 // NewDropDown creates and returns a pointer to a new drop down widget with the specified width.
 func NewDropDown(width float32, item *ImageLabel) *DropDown {
 
@@ -67,7 +65,6 @@ func NewDropDown(width float32, item *ImageLabel) *DropDown {
 	/// Create list
 	dd.list = NewVList(0, 0)
 	dd.list.bounded = false
-	dd.list.SetPositionZ(dropDownZ)
 	dd.list.dropdown = true
 	dd.list.SetVisible(false)
 

+ 0 - 3
gui/folder.go

@@ -35,8 +35,6 @@ type FolderStyles struct {
 	Disabled *FolderStyle
 }
 
-const folderZ = -0.6
-
 // NewFolder creates and returns a pointer to a new folder widget
 // with the specified text and initial width
 func NewFolder(text string, width float32, contentPanel IPanel) *Folder {
@@ -66,7 +64,6 @@ func (f *Folder) Initialize(text string, width float32, contentPanel IPanel) {
 	f.contentPanel = contentPanel
 	contentPanel.GetPanel().bounded = false
 	contentPanel.GetPanel().SetVisible(false)
-	contentPanel.GetPanel().SetPositionZ(folderZ)
 	f.Panel.Add(f.contentPanel)
 
 	// Set event callbacks

+ 33 - 25
gui/panel.go

@@ -84,7 +84,8 @@ type Panel struct {
 }
 
 const (
-	deltaZ = -0.00001
+	deltaZ    = -0.00001      // delta Z for bounded panels
+	deltaZunb = deltaZ * 1000 // delta Z for unbounded panels
 )
 
 // NewPanel creates and returns a pointer to a new panel with the
@@ -485,7 +486,10 @@ func (p *Panel) Add(ichild IPanel) *Panel {
 	p.Node.Add(ichild)
 	node := ichild.GetPanel()
 	node.SetParent(p)
-	ichild.SetRoot(p.root)
+	if p.root != nil {
+		ichild.SetRoot(p.root)
+		p.root.setChildrenZ()
+	}
 	if p.layout != nil {
 		p.layout.Recalc(p)
 	}
@@ -526,7 +530,6 @@ func (p *Panel) UpdateMatrixWorld() {
 	par := p.Parent()
 	if par == nil {
 		p.updateBounds(nil)
-		p.setZ(0)
 		// Panel has parent
 	} else {
 		parpan := par.(*Panel)
@@ -538,28 +541,6 @@ func (p *Panel) UpdateMatrixWorld() {
 	}
 }
 
-// setZ sets the Z coordinate for this panel and its children recursively
-// starting at the specified nextZ coordinate.
-// The Z coordinate is set so panels added later are closed to the screen
-// For unbounded panels it is used the unbounded panel coordinate to
-// set the Z coordinate of its children.
-func (p *Panel) setZ(nextZ float32) float32 {
-
-	z := nextZ
-	if !p.bounded {
-		z = p.Position().Z
-	}
-	p.SetPositionZ(z)
-	z += deltaZ
-	for _, ichild := range p.Children() {
-		z = ichild.(IPanel).GetPanel().setZ(z)
-	}
-	if !p.bounded {
-		return nextZ
-	}
-	return z
-}
-
 // ContainsPosition returns indication if this panel contains
 // the specified screen position in pixels.
 func (p *Panel) ContainsPosition(x, y float32) bool {
@@ -631,6 +612,33 @@ func (p *Panel) Pix2NDC(px, py float32) (nx, ny float32) {
 	return px / w, -py / h
 }
 
+// setZ sets the Z coordinate for this panel and its children recursively
+// starting at the specified z and zunb coordinates.
+// The z coordinate is used for bound panels and zunb for unbounded panels.
+// The z coordinate is set so panels added later are closer to the screen.
+// All unbounded panels and its children are closer than any of the bounded panels.
+func (p *Panel) setZ(z, zunb float32) (float32, float32) {
+
+	// Bounded panel
+	if p.bounded {
+		p.SetPositionZ(z)
+		z += deltaZ
+		for _, ichild := range p.Children() {
+			z, zunb = ichild.(IPanel).GetPanel().setZ(z, zunb)
+		}
+		return z, zunb
+		// Unbounded panel
+	} else {
+		p.SetPositionZ(zunb)
+		zchild := zunb + deltaZ
+		zunb += deltaZunb
+		for _, ichild := range p.Children() {
+			_, zunb = ichild.(IPanel).GetPanel().setZ(zchild, zunb)
+		}
+		return z, zunb
+	}
+}
+
 // updateBounds is called by UpdateMatrixWorld() and calculates this panel
 // bounds considering the bounds of its parent
 func (p *Panel) updateBounds(par *Panel) {

+ 15 - 1
gui/root.go

@@ -63,10 +63,15 @@ func (r *Root) SubscribeWin() {
 }
 
 // Add adds the specified panel to the root container list of children
+// Overrides the Panel version because it needs to set the root panel field
 func (r *Root) Add(ipan IPanel) {
 
+	// Sets the root panel field of the child
+	ipan.GetPanel().root = r
+	// Add this panel to the root panel children.
+	// This will also set the root panel for all the child children
+	// and the z coordinates of all the panel tree graph.
 	r.Panel.Add(ipan)
-	ipan.SetRoot(r)
 }
 
 // SetKeyFocus sets the panel which will receive all keyboard events
@@ -165,6 +170,15 @@ func (r *Root) SetCursorVResize() {
 	r.win.SetStandardCursor(window.VResizeCursor)
 }
 
+// setChildrenZ sets the z coordinates of all children of this root panel
+func (r *Root) setChildrenZ() {
+
+	if r == nil {
+		return
+	}
+	r.setZ(0, deltaZunb)
+}
+
 // onKey is called when key events are received
 func (r *Root) onKey(evname string, ev interface{}) {