MCPcopy
hub / github.com/g3n/engine / buildDropDown

Function buildDropDown

gui/builder_panel.go:321–358  ·  view source on GitHub ↗

buildDropDown builds a gui object of type: DropDown

(b *Builder, am map[string]interface{})

Source from the content-addressed store, hash-verified

319
320// buildDropDown builds a gui object of type: DropDown
321func buildDropDown(b *Builder, am map[string]interface{}) (IPanel, error) {
322
323 // If image label attribute defined use it, otherwise
324 // uses default value.
325 var imglabel *ImageLabel
326 if iv := am[AttribImageLabel]; iv != nil {
327 imgl := iv.(map[string]interface{})
328 imgl[AttribType] = TypeImageLabel
329 ipan, err := b.build(imgl, nil)
330 if err != nil {
331 return nil, err
332 }
333 imglabel = ipan.(*ImageLabel)
334 } else {
335 imglabel = NewImageLabel("")
336 }
337
338 // Builds drop down and set common attributes
339 dd := NewDropDown(0, imglabel)
340 err := b.SetAttribs(am, dd)
341 if err != nil {
342 return nil, err
343 }
344
345 // Builds children
346 if am[AttribItems] != nil {
347 items := am[AttribItems].([]map[string]interface{})
348 for i := 0; i < len(items); i++ {
349 item := items[i]
350 child, err := b.build(item, dd)
351 if err != nil {
352 return nil, err
353 }
354 dd.Add(child.(*ImageLabel))
355 }
356 }
357 return dd, nil
358}
359
360// buildMenu builds a gui object of type: Menu or MenuBar from the
361// specified panel descriptor.

Callers

nothing calls this directly

Calls 5

AddMethod · 0.95
NewImageLabelFunction · 0.85
NewDropDownFunction · 0.85
buildMethod · 0.80
SetAttribsMethod · 0.80

Tested by

no test coverage detected