Procházet zdrojové kódy

removed attribute set parameter from gui.Builder.SetAttribs()

leonsal před 8 roky
rodič
revize
452bbe0047
2 změnil soubory, kde provedl 34 přidání a 53 odebrání
  1. 14 33
      gui/builder.go
  2. 20 20
      gui/builder_panel.go

+ 14 - 33
gui/builder.go

@@ -150,23 +150,6 @@ const (
 	AttribVisible        = "visible"       // bool
 )
 
-const (
-	aPOS         = 1 << iota                                                         // attribute position
-	aSIZE        = 1 << iota                                                         // attribute size
-	aNAME        = 1 << iota                                                         // attribute name
-	aMARGINS     = 1 << iota                                                         // attribute margins widths
-	aBORDERS     = 1 << iota                                                         // attribute borders widths
-	aBORDERCOLOR = 1 << iota                                                         // attribute border color
-	aPADDINGS    = 1 << iota                                                         // attribute paddings widths
-	aCOLOR       = 1 << iota                                                         // attribute panel bgcolor
-	aENABLED     = 1 << iota                                                         // attribute enabled for events
-	aRENDER      = 1 << iota                                                         // attribute renderable
-	aVISIBLE     = 1 << iota                                                         // attribute visible
-	aUSERDATA    = 1 << iota                                                         // attribute userdata
-	asPANEL      = 0xFFFFFFF                                                         // attribute set for panels
-	asWIDGET     = aPOS | aNAME | aMARGINS | aSIZE | aENABLED | aVISIBLE | aUSERDATA // attribute set for widgets
-)
-
 // maps align name with align parameter
 var mapAlignh = map[string]Align{
 	"none":   AlignNone,
@@ -544,69 +527,67 @@ func (b *Builder) build(am map[string]interface{}, iparent IPanel) (IPanel, erro
 }
 
 // SetAttribs sets common attributes from the description to the specified panel
-// The attributes which are set can be specified by the specified bitmask.
-func (b *Builder) SetAttribs(am map[string]interface{}, ipan IPanel, attr uint) error {
+func (b *Builder) SetAttribs(am map[string]interface{}, ipan IPanel) error {
 
 	panel := ipan.GetPanel()
-	log.Error("SetAttribs:%v -> %v", am[AttribType], am[AttribName])
 	// Set optional position
-	if attr&aPOS != 0 && am[AttribPosition] != nil {
+	if am[AttribPosition] != nil {
 		va := am[AttribPosition].([]float32)
 		panel.SetPosition(va[0], va[1])
 	}
 
 	// Set optional panel width
-	if attr&aSIZE != 0 && am[AttribWidth] != nil {
+	if am[AttribWidth] != nil {
 		panel.SetWidth(am[AttribWidth].(float32))
 	}
 
 	// Sets optional panel height
-	if attr&aSIZE != 0 && am[AttribHeight] != nil {
+	if am[AttribHeight] != nil {
 		panel.SetHeight(am[AttribHeight].(float32))
 	}
 
 	// Set optional margin sizes
-	if attr&aMARGINS != 0 && am[AttribMargins] != nil {
+	if am[AttribMargins] != nil {
 		panel.SetMarginsFrom(am[AttribMargins].(*BorderSizes))
 	}
 
 	// Set optional border sizes
-	if attr&aBORDERS != 0 && am[AttribBorders] != nil {
+	if am[AttribBorders] != nil {
 		panel.SetBordersFrom(am[AttribBorders].(*BorderSizes))
 	}
 
 	// Set optional border color
-	if attr&aBORDERCOLOR != 0 && am[AttribBorderColor] != nil {
+	if am[AttribBorderColor] != nil {
 		panel.SetBordersColor4(am[AttribBorderColor].(*math32.Color4))
 	}
 
 	// Set optional paddings sizes
-	if attr&aPADDINGS != 0 && am[AttribPaddings] != nil {
+	if am[AttribPaddings] != nil {
 		panel.SetPaddingsFrom(am[AttribPaddings].(*BorderSizes))
 	}
 
 	// Set optional panel color
-	if attr&aCOLOR != 0 && am[AttribColor] != nil {
+	if am[AttribColor] != nil {
 		panel.SetColor4(am[AttribColor].(*math32.Color4))
 	}
 
-	if attr&aNAME != 0 && am[AttribName] != nil {
+	if am[AttribName] != nil {
 		panel.SetName(am[AttribName].(string))
 	}
 
-	if attr&aVISIBLE != 0 && am[AttribVisible] != nil {
+	if am[AttribVisible] != nil {
 		panel.SetVisible(am[AttribVisible].(bool))
 	}
 
-	if attr&aENABLED != 0 && am[AttribEnabled] != nil {
+	if am[AttribEnabled] != nil {
 		panel.SetEnabled(am[AttribEnabled].(bool))
 	}
 
-	if attr&aRENDER != 0 && am[AttribRender] != nil {
+	if am[AttribRender] != nil {
 		panel.SetRenderable(am[AttribRender].(bool))
 	}
 
-	if attr&aUSERDATA != 0 && am[AttribUserData] != nil {
+	if am[AttribUserData] != nil {
 		panel.SetUserData(am[AttribUserData])
 	}
 

+ 20 - 20
gui/builder_panel.go

@@ -15,7 +15,7 @@ import (
 func buildPanel(b *Builder, am map[string]interface{}) (IPanel, error) {
 
 	pan := NewPanel(0, 0)
-	err := b.SetAttribs(am, pan, asPANEL)
+	err := b.SetAttribs(am, pan)
 	if err != nil {
 		return nil, err
 	}
@@ -54,7 +54,7 @@ func buildImagePanel(b *Builder, am map[string]interface{}) (IPanel, error) {
 	if err != nil {
 		return nil, err
 	}
-	err = b.SetAttribs(am, panel, asPANEL)
+	err = b.SetAttribs(am, panel)
 	if err != nil {
 		return nil, err
 	}
@@ -97,7 +97,7 @@ func buildLabel(b *Builder, am map[string]interface{}) (IPanel, error) {
 	}
 
 	// Sets common attributes
-	err := b.SetAttribs(am, label, asPANEL)
+	err := b.SetAttribs(am, label)
 	if err != nil {
 		return nil, err
 	}
@@ -139,7 +139,7 @@ func buildImageLabel(b *Builder, am map[string]interface{}) (IPanel, error) {
 		text = am[AttribText].(string)
 	}
 	imglabel := NewImageLabel(text)
-	err := b.SetAttribs(am, imglabel, asPANEL)
+	err := b.SetAttribs(am, imglabel)
 	if err != nil {
 		return nil, err
 	}
@@ -174,7 +174,7 @@ func buildButton(b *Builder, am map[string]interface{}) (IPanel, error) {
 		text = am[AttribText].(string)
 	}
 	button := NewButton(text)
-	err := b.SetAttribs(am, button, asWIDGET)
+	err := b.SetAttribs(am, button)
 	if err != nil {
 		return nil, err
 	}
@@ -213,7 +213,7 @@ func buildEdit(b *Builder, am map[string]interface{}) (IPanel, error) {
 		placeholder = ph.(string)
 	}
 	edit := NewEdit(int(width), placeholder)
-	err := b.SetAttribs(am, edit, asWIDGET)
+	err := b.SetAttribs(am, edit)
 	if err != nil {
 		return nil, err
 	}
@@ -229,7 +229,7 @@ func buildCheckBox(b *Builder, am map[string]interface{}) (IPanel, error) {
 		text = am[AttribText].(string)
 	}
 	cb := NewCheckBox(text)
-	err := b.SetAttribs(am, cb, asWIDGET)
+	err := b.SetAttribs(am, cb)
 	if err != nil {
 		return nil, err
 	}
@@ -250,7 +250,7 @@ func buildRadioButton(b *Builder, am map[string]interface{}) (IPanel, error) {
 		text = am[AttribText].(string)
 	}
 	rb := NewRadioButton(text)
-	err := b.SetAttribs(am, rb, asWIDGET)
+	err := b.SetAttribs(am, rb)
 	if err != nil {
 		return nil, err
 	}
@@ -272,7 +272,7 @@ func buildVList(b *Builder, am map[string]interface{}) (IPanel, error) {
 
 	// Builds list and set commont attributes
 	list := NewVList(0, 0)
-	err := b.SetAttribs(am, list, asWIDGET)
+	err := b.SetAttribs(am, list)
 	if err != nil {
 		return nil, err
 	}
@@ -297,7 +297,7 @@ func buildHList(b *Builder, am map[string]interface{}) (IPanel, error) {
 
 	// Builds list and set commont attributes
 	list := NewHList(0, 0)
-	err := b.SetAttribs(am, list, asWIDGET)
+	err := b.SetAttribs(am, list)
 	if err != nil {
 		return nil, err
 	}
@@ -337,7 +337,7 @@ func buildDropDown(b *Builder, am map[string]interface{}) (IPanel, error) {
 
 	// Builds drop down and set common attributes
 	dd := NewDropDown(0, imglabel)
-	err := b.SetAttribs(am, dd, asWIDGET)
+	err := b.SetAttribs(am, dd)
 	if err != nil {
 		return nil, err
 	}
@@ -377,7 +377,7 @@ func buildMenu(b *Builder, am map[string]interface{}) (IPanel, error) {
 			ptype = ti.(string)
 		}
 		if ptype != TypeMenu && ptype != TypeMenuBar {
-			err := b.SetAttribs(am, menu, asWIDGET)
+			err := b.SetAttribs(am, menu)
 			if err != nil {
 				return nil, err
 			}
@@ -440,7 +440,7 @@ func buildSlider(b *Builder, am map[string]interface{}) (IPanel, error) {
 	}
 
 	// Sets common attributes
-	err := b.SetAttribs(am, slider, asWIDGET)
+	err := b.SetAttribs(am, slider)
 	if err != nil {
 		return nil, err
 	}
@@ -472,7 +472,7 @@ func buildSplitter(b *Builder, am map[string]interface{}) (IPanel, error) {
 	}
 
 	// Sets common attributes
-	err := b.SetAttribs(am, splitter, asWIDGET)
+	err := b.SetAttribs(am, splitter)
 	if err != nil {
 		return nil, err
 	}
@@ -492,7 +492,7 @@ func buildSplitter(b *Builder, am map[string]interface{}) (IPanel, error) {
 		}
 		pattr := ipattribs.(map[string]interface{})
 		// Set panel attributes
-		err := b.SetAttribs(pattr, pan, asPANEL)
+		err := b.SetAttribs(pattr, pan)
 		if err != nil {
 			return nil
 		}
@@ -529,7 +529,7 @@ func buildTree(b *Builder, am map[string]interface{}) (IPanel, error) {
 
 	// Builds tree and sets its common attributes
 	tree := NewTree(0, 0)
-	err := b.SetAttribs(am, tree, asWIDGET)
+	err := b.SetAttribs(am, tree)
 	if err != nil {
 		return nil, err
 	}
@@ -597,7 +597,7 @@ func buildWindow(b *Builder, am map[string]interface{}) (IPanel, error) {
 
 	// Builds window and sets its common attributes
 	win := NewWindow(0, 0)
-	err := b.SetAttribs(am, win, asWIDGET)
+	err := b.SetAttribs(am, win)
 	if err != nil {
 		return nil, err
 	}
@@ -632,7 +632,7 @@ func buildChart(b *Builder, am map[string]interface{}) (IPanel, error) {
 
 	// Builds window and sets its common attributes
 	chart := NewChart(0, 0)
-	err := b.SetAttribs(am, chart, asPANEL)
+	err := b.SetAttribs(am, chart)
 	if err != nil {
 		return nil, err
 	}
@@ -788,7 +788,7 @@ func buildTable(b *Builder, am map[string]interface{}) (IPanel, error) {
 	if err != nil {
 		return nil, err
 	}
-	err = b.SetAttribs(am, table, asPANEL)
+	err = b.SetAttribs(am, table)
 	if err != nil {
 		return nil, err
 	}
@@ -806,7 +806,7 @@ func buildTabBar(b *Builder, am map[string]interface{}) (IPanel, error) {
 
 	// Creates TabBar and set common attributes
 	tabbar := NewTabBar(0, 0)
-	err := b.SetAttribs(am, tabbar, asPANEL)
+	err := b.SetAttribs(am, tabbar)
 	if err != nil {
 		return nil, err
 	}