소스 검색

gui.Builder() accepts layoutparams type

leonsal 8 년 전
부모
커밋
2f69a70c2e
1개의 변경된 파일19개의 추가작업 그리고 12개의 파일을 삭제
  1. 19 12
      gui/builder.go

+ 19 - 12
gui/builder.go

@@ -651,21 +651,28 @@ func (b *Builder) setLayoutParams(am map[string]interface{}, ipan IPanel) error
 	}
 	lp := lpi.(map[string]interface{})
 
-	// Get layout type from parent
-	pi := am[AttribParentInternal]
-	if pi == nil {
-		return b.err(am, AttribType, "Panel has no parent")
-	}
-	par := pi.(map[string]interface{})
-	v := par[AttribLayout]
-	if v == nil {
-		return nil
+	// Checks if layout param specifies the layout type
+	// This is useful when the panel has no parent yet
+	var ltype string
+	if v := lp[AttribType]; v != nil {
+		ltype = v.(string)
+	} else {
+		// Get layout type from parent
+		pi := am[AttribParentInternal]
+		if pi == nil {
+			return b.err(am, AttribType, "Panel has no parent")
+		}
+		par := pi.(map[string]interface{})
+		v := par[AttribLayout]
+		if v == nil {
+			return b.err(am, AttribType, "Parent has no layout")
+		}
+		playout := v.(map[string]interface{})
+		ltype = playout[AttribType].(string)
 	}
-	playout := v.(map[string]interface{})
-	pltype := playout[AttribType].(string)
 
 	// Get layout builder and builds layout params
-	lbuilder := b.layouts[pltype]
+	lbuilder := b.layouts[ltype]
 	params, err := lbuilder.BuildParams(b, lp)
 	if err != nil {
 		return err