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

Function buildImagePanel

gui/builder_panel.go:39–85  ·  view source on GitHub ↗

buildImagePanel builds a gui object of type ImagePanel

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

Source from the content-addressed store, hash-verified

37
38// buildImagePanel builds a gui object of type ImagePanel
39func buildImagePanel(b *Builder, am map[string]interface{}) (IPanel, error) {
40
41 // Checks imagefile attribute
42 if am[AttribImageFile] == nil {
43 return nil, b.err(am, AttribImageFile, "Must be supplied")
44 }
45
46 // If path is not absolute join with user supplied image base path
47 imagefile := am[AttribImageFile].(string)
48 if !filepath.IsAbs(imagefile) {
49 imagefile = filepath.Join(b.imgpath, imagefile)
50 }
51
52 // Builds panel and set common attributes
53 panel, err := NewImage(imagefile)
54 if err != nil {
55 return nil, err
56 }
57 err = b.SetAttribs(am, panel)
58 if err != nil {
59 return nil, err
60 }
61
62 // Sets optional AspectWidth attribute
63 if aw := am[AttribAspectWidth]; aw != nil {
64 panel.SetContentAspectWidth(aw.(float32))
65 }
66
67 // Sets optional AspectHeight attribute
68 if ah := am[AttribAspectHeight]; ah != nil {
69 panel.SetContentAspectHeight(ah.(float32))
70 }
71
72 // Builds children recursively
73 if am[AttribItems] != nil {
74 items := am[AttribItems].([]map[string]interface{})
75 for i := 0; i < len(items); i++ {
76 item := items[i]
77 child, err := b.build(item, panel)
78 if err != nil {
79 return nil, err
80 }
81 panel.Add(child)
82 }
83 }
84 return panel, nil
85}
86
87// buildLabel builds a gui object of type Label
88func buildLabel(b *Builder, am map[string]interface{}) (IPanel, error) {

Callers

nothing calls this directly

Calls 7

NewImageFunction · 0.85
errMethod · 0.80
SetAttribsMethod · 0.80
SetContentAspectWidthMethod · 0.80
buildMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected