forked from g3n/engine
/
builder_panel.go
858 lines (763 loc) · 19.5 KB
/
builder_panel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
// Copyright 2016 The G3N Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gui
import (
"path/filepath"
"github.com/g3n/engine/math32"
"github.com/g3n/engine/window"
)
// buildPanel builds an object of type Panel
func buildPanel(b *Builder, am map[string]interface{}) (IPanel, error) {
pan := NewPanel(0, 0)
err := b.SetAttribs(am, pan)
if err != nil {
return nil, err
}
// Builds children recursively
if am[AttribItems] != nil {
items := am[AttribItems].([]map[string]interface{})
for i := 0; i < len(items); i++ {
item := items[i]
child, err := b.build(item, pan)
if err != nil {
return nil, err
}
pan.Add(child)
}
}
return pan, nil
}
// buildImagePanel builds a gui object of type ImagePanel
func buildImagePanel(b *Builder, am map[string]interface{}) (IPanel, error) {
// Checks imagefile attribute
if am[AttribImageFile] == nil {
return nil, b.err(am, AttribImageFile, "Must be supplied")
}
// If path is not absolute join with user supplied image base path
imagefile := am[AttribImageFile].(string)
if !filepath.IsAbs(imagefile) {
imagefile = filepath.Join(b.imgpath, imagefile)
}
// Builds panel and set common attributes
panel, err := NewImage(imagefile)
if err != nil {
return nil, err
}
err = b.SetAttribs(am, panel)
if err != nil {
return nil, err
}
// Sets optional AspectWidth attribute
if aw := am[AttribAspectWidth]; aw != nil {
panel.SetContentAspectWidth(aw.(float32))
}
// Sets optional AspectHeight attribute
if ah := am[AttribAspectHeight]; ah != nil {
panel.SetContentAspectHeight(ah.(float32))
}
// Builds children recursively
if am[AttribItems] != nil {
items := am[AttribItems].([]map[string]interface{})
for i := 0; i < len(items); i++ {
item := items[i]
child, err := b.build(item, panel)
if err != nil {
return nil, err
}
panel.Add(child)
}
}
return panel, nil
}
// buildLabel builds a gui object of type Label
func buildLabel(b *Builder, am map[string]interface{}) (IPanel, error) {
var label *Label
if am[AttribIcon] != nil {
label = NewIcon(am[AttribIcon].(string))
} else if am[AttribText] != nil {
label = NewLabel(am[AttribText].(string))
} else {
label = NewLabel("")
}
// Sets common attributes
err := b.SetAttribs(am, label)
if err != nil {
return nil, err
}
// Set optional background color
if bgc := am[AttribBgColor]; bgc != nil {
label.SetBgColor4(bgc.(*math32.Color4))
}
// Set optional font color
if fc := am[AttribFontColor]; fc != nil {
label.SetColor4(fc.(*math32.Color4))
}
// Sets optional font size
if fs := am[AttribFontSize]; fs != nil {
label.SetFontSize(float64(fs.(float32)))
}
// Sets optional font dpi
if fdpi := am[AttribFontDPI]; fdpi != nil {
label.SetFontDPI(float64(fdpi.(float32)))
}
// Sets optional line spacing
if ls := am[AttribLineSpacing]; ls != nil {
label.SetLineSpacing(float64(ls.(float32)))
}
return label, nil
}
// buildImageLabel builds a gui object of type: ImageLabel
func buildImageLabel(b *Builder, am map[string]interface{}) (IPanel, error) {
// Builds image label and set common attributes
var text string
if am[AttribText] != nil {
text = am[AttribText].(string)
}
imglabel := NewImageLabel(text)
err := b.SetAttribs(am, imglabel)
if err != nil {
return nil, err
}
// Sets optional icon(s)
if icon := am[AttribIcon]; icon != nil {
imglabel.SetIcon(icon.(string))
}
// Sets optional image from file
// If path is not absolute join with user supplied image base path
if imgf := am[AttribImageFile]; imgf != nil {
path := imgf.(string)
if !filepath.IsAbs(path) {
path = filepath.Join(b.imgpath, path)
}
err := imglabel.SetImageFromFile(path)
if err != nil {
return nil, err
}
}
return imglabel, nil
}
// buildButton builds a gui object of type: Button
func buildButton(b *Builder, am map[string]interface{}) (IPanel, error) {
// Builds button and set commont attributes
var text string
if am[AttribText] != nil {
text = am[AttribText].(string)
}
button := NewButton(text)
err := b.SetAttribs(am, button)
if err != nil {
return nil, err
}
// Sets optional icon(s)
if icon := am[AttribIcon]; icon != nil {
button.SetIcon(icon.(string))
}
// Sets optional image from file
// If path is not absolute join with user supplied image base path
if imgf := am[AttribImageFile]; imgf != nil {
path := imgf.(string)
if !filepath.IsAbs(path) {
path = filepath.Join(b.imgpath, path)
}
err := button.SetImage(path)
if err != nil {
return nil, err
}
}
return button, nil
}
// buildEdit builds a gui object of type: "Edit"
func buildEdit(b *Builder, am map[string]interface{}) (IPanel, error) {
// Builds button and set attributes
var width float32
var placeholder string
if aw := am[AttribWidth]; aw != nil {
width = aw.(float32)
}
if ph := am[AttribPlaceHolder]; ph != nil {
placeholder = ph.(string)
}
edit := NewEdit(int(width), placeholder)
err := b.SetAttribs(am, edit)
if err != nil {
return nil, err
}
return edit, nil
}
// buildCheckBox builds a gui object of type: CheckBox
func buildCheckBox(b *Builder, am map[string]interface{}) (IPanel, error) {
// Builds check box and set commont attributes
var text string
if am[AttribText] != nil {
text = am[AttribText].(string)
}
cb := NewCheckBox(text)
err := b.SetAttribs(am, cb)
if err != nil {
return nil, err
}
// Sets optional checked value
if checked := am[AttribChecked]; checked != nil {
cb.SetValue(checked.(bool))
}
return cb, nil
}
// buildRadioButton builds a gui object of type: RadioButton
func buildRadioButton(b *Builder, am map[string]interface{}) (IPanel, error) {
// Builds check box and set commont attributes
var text string
if am[AttribText] != nil {
text = am[AttribText].(string)
}
rb := NewRadioButton(text)
err := b.SetAttribs(am, rb)
if err != nil {
return nil, err
}
// Sets optional radio button group
if gr := am[AttribGroup]; gr != nil {
rb.SetGroup(gr.(string))
}
// Sets optional checked value
if checked := am[AttribChecked]; checked != nil {
rb.SetValue(checked.(bool))
}
return rb, nil
}
// buildVList builds a gui object of type: VList
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)
if err != nil {
return nil, err
}
// Builds children
if am[AttribItems] != nil {
items := am[AttribItems].([]map[string]interface{})
for i := 0; i < len(items); i++ {
item := items[i]
child, err := b.build(item, list)
if err != nil {
return nil, err
}
list.Add(child)
}
}
return list, nil
}
// buildHList builds a gui object of type: VList
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)
if err != nil {
return nil, err
}
// Builds children
if am[AttribItems] != nil {
items := am[AttribItems].([]map[string]interface{})
for i := 0; i < len(items); i++ {
item := items[i]
child, err := b.build(item, list)
if err != nil {
return nil, err
}
list.Add(child)
}
}
return list, nil
}
// buildDropDown builds a gui object of type: DropDown
func buildDropDown(b *Builder, am map[string]interface{}) (IPanel, error) {
// If image label attribute defined use it, otherwise
// uses default value.
var imglabel *ImageLabel
if iv := am[AttribImageLabel]; iv != nil {
imgl := iv.(map[string]interface{})
imgl[AttribType] = TypeImageLabel
ipan, err := b.build(imgl, nil)
if err != nil {
return nil, err
}
imglabel = ipan.(*ImageLabel)
} else {
imglabel = NewImageLabel("")
}
// Builds drop down and set common attributes
dd := NewDropDown(0, imglabel)
err := b.SetAttribs(am, dd)
if err != nil {
return nil, err
}
// Builds children
if am[AttribItems] != nil {
items := am[AttribItems].([]map[string]interface{})
for i := 0; i < len(items); i++ {
item := items[i]
child, err := b.build(item, dd)
if err != nil {
return nil, err
}
dd.Add(child.(*ImageLabel))
}
}
return dd, nil
}
// buildMenu builds a gui object of type: Menu or MenuBar from the
// specified panel descriptor.
func buildMenu(b *Builder, am map[string]interface{}) (IPanel, error) {
// Builds menu bar or menu
var menu *Menu
if am[AttribType].(string) == TypeMenuBar {
menu = NewMenuBar()
} else {
menu = NewMenu()
}
// Only sets attribs for top level menus
if pi := am[AttribParentInternal]; pi != nil {
par := pi.(map[string]interface{})
ptype := ""
if ti := par[AttribType]; ti != nil {
ptype = ti.(string)
}
if ptype != TypeMenu && ptype != TypeMenuBar {
err := b.SetAttribs(am, menu)
if err != nil {
return nil, err
}
}
}
// Builds and adds menu items
if am[AttribItems] != nil {
items := am[AttribItems].([]map[string]interface{})
for i := 0; i < len(items); i++ {
// Get the item optional type and text
item := items[i]
itype := ""
itext := ""
if iv := item[AttribType]; iv != nil {
itype = iv.(string)
}
if iv := item[AttribText]; iv != nil {
itext = iv.(string)
}
// Item is another menu
if itype == TypeMenu {
subm, err := buildMenu(b, item)
if err != nil {
return nil, err
}
menu.AddMenu(itext, subm.(*Menu))
continue
}
// Item is a separator
if itext == TypeSeparator {
menu.AddSeparator()
continue
}
// Item must be a menu option
mi := menu.AddOption(itext)
// Set item optional icon(s)
if icon := item[AttribIcon]; icon != nil {
mi.SetIcon(icon.(string))
}
// Sets optional menu item shortcut
if sci := item[AttribShortcut]; sci != nil {
sc := sci.([]int)
mi.SetShortcut(window.ModifierKey(sc[0]), window.Key(sc[1]))
}
}
}
return menu, nil
}
// buildSlider builds a gui object of type: HSlider or VSlider
func buildSlider(b *Builder, am map[string]interface{}) (IPanel, error) {
// Builds horizontal or vertical slider
var slider *Slider
if am[AttribType].(string) == TypeHSlider {
slider = NewHSlider(0, 0)
} else {
slider = NewVSlider(0, 0)
}
// Sets common attributes
err := b.SetAttribs(am, slider)
if err != nil {
return nil, err
}
// Sets optional text
if itext := am[AttribText]; itext != nil {
slider.SetText(itext.(string))
}
// Sets optional scale factor
if isf := am[AttribScaleFactor]; isf != nil {
slider.SetScaleFactor(isf.(float32))
}
// Sets optional value
if iv := am[AttribValue]; iv != nil {
slider.SetValue(iv.(float32))
}
return slider, nil
}
// buildSplitter builds a gui object of type: HSplitterr or VSplitter
func buildSplitter(b *Builder, am map[string]interface{}) (IPanel, error) {
// Builds horizontal or vertical splitter
var splitter *Splitter
if am[AttribType].(string) == TypeHSplitter {
splitter = NewHSplitter(0, 0)
} else {
splitter = NewVSplitter(0, 0)
}
// Sets common attributes
err := b.SetAttribs(am, splitter)
if err != nil {
return nil, err
}
// Sets optional split value
if v := am[AttribSplit]; v != nil {
splitter.SetSplit(v.(float32))
}
// Internal function to set each of the splitter's panel attributes and items
setpan := func(attrib string, pan *Panel) error {
// Get internal panel attributes
ipattribs := am[attrib]
if ipattribs == nil {
return nil
}
pattr := ipattribs.(map[string]interface{})
// Set panel attributes
err := b.SetAttribs(pattr, pan)
if err != nil {
return nil
}
// Builds panel children
if pattr[AttribItems] != nil {
items := pattr[AttribItems].([]map[string]interface{})
for i := 0; i < len(items); i++ {
item := items[i]
child, err := b.build(item, pan)
if err != nil {
return err
}
pan.Add(child)
}
}
return nil
}
// Set optional splitter panel's attributes
err = setpan(AttribPanel0, &splitter.P0)
if err != nil {
return nil, err
}
err = setpan(AttribPanel1, &splitter.P1)
if err != nil {
return nil, err
}
return splitter, nil
}
// buildTree builds a gui object of type: Tree
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)
if err != nil {
return nil, err
}
// Internal function to build tree nodes recursively
var buildItems func(am map[string]interface{}, pnode *TreeNode) error
buildItems = func(am map[string]interface{}, pnode *TreeNode) error {
v := am[AttribItems]
if v == nil {
return nil
}
items := v.([]map[string]interface{})
for i := 0; i < len(items); i++ {
// Get the item type
item := items[i]
itype := ""
if v := item[AttribType]; v != nil {
itype = v.(string)
}
itext := ""
if v := item[AttribText]; v != nil {
itext = v.(string)
}
// Item is a tree node
if itype == "" || itype == TypeTreeNode {
var node *TreeNode
if pnode == nil {
node = tree.AddNode(itext)
} else {
node = pnode.AddNode(itext)
}
err := buildItems(item, node)
if err != nil {
return err
}
continue
}
// Other controls
ipan, err := b.build(item, nil)
if err != nil {
return err
}
if pnode == nil {
tree.Add(ipan)
} else {
pnode.Add(ipan)
}
}
return nil
}
// Build nodes
err = buildItems(am, nil)
if err != nil {
return nil, err
}
return tree, nil
}
// buildWindow builds a gui object of type: Window
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)
if err != nil {
return nil, err
}
// Sets optional title
if title := am[AttribTitle]; title != nil {
win.SetTitle(title.(string))
}
// Set optional resizable borders
if resiz := am[AttribResizeBorders]; resiz != nil {
win.SetResizable(resiz.(bool))
}
// Builds window children
if v := am[AttribItems]; v != nil {
items := v.([]map[string]interface{})
for i := 0; i < len(items); i++ {
item := items[i]
child, err := b.build(item, win)
if err != nil {
return nil, err
}
win.Add(child)
}
}
return win, nil
}
// buildChart builds a gui object of type: Chart
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)
if err != nil {
return nil, err
}
// Sets optional title
if title := am[AttribTitle]; title != nil {
chart.SetTitle(title.(string), 14)
}
// Sets x scale attibutes
if v := am[AttribScalex]; v != nil {
sx := v.(map[string]interface{})
// Sets optional x scale margin
if mx := sx[AttribMargin]; mx != nil {
chart.SetMarginX(mx.(float32))
}
// Sets optional x scale format
if fx := sx[AttribFormat]; fx != nil {
chart.SetFormatX(fx.(string))
}
// Sets optional x scale font size
if fsize := sx[AttribFontSize]; fsize != nil {
chart.SetFontSizeX(float64(fsize.(float32)))
}
// Number of lines
lines := 4
if v := sx[AttribLines]; v != nil {
lines = v.(int)
}
// Lines color
color4 := math32.NewColor4("Black")
if v := sx[AttribColor]; v != nil {
color4 = v.(*math32.Color4)
}
color := color4.ToColor()
chart.SetScaleX(lines, &color)
// Range first
firstX := float32(0)
if v := sx[AttribFirstx]; v != nil {
firstX = v.(float32)
}
// Range step
stepX := float32(1)
if v := sx[AttribStepx]; v != nil {
stepX = v.(float32)
}
// Range count step
countStepX := float32(1)
if v := sx[AttribStepx]; v != nil {
countStepX = v.(float32)
}
chart.SetRangeX(firstX, stepX, countStepX)
}
// Sets y scale attibutes
if v := am[AttribScaley]; v != nil {
sy := v.(map[string]interface{})
// Sets optional y scale margin
if my := sy[AttribMargin]; my != nil {
chart.SetMarginY(my.(float32))
}
// Sets optional y scale format
if fy := sy[AttribFormat]; fy != nil {
chart.SetFormatY(fy.(string))
}
// Sets optional y scale font size
if fsize := sy[AttribFontSize]; fsize != nil {
chart.SetFontSizeY(float64(fsize.(float32)))
}
// Number of lines
lines := 4
if v := sy[AttribLines]; v != nil {
lines = v.(int)
}
// Lines color
color4 := math32.NewColor4("Black")
if v := sy[AttribColor]; v != nil {
color4 = v.(*math32.Color4)
}
color := color4.ToColor()
chart.SetScaleY(lines, &color)
// Range min
rmin := float32(-10)
if v := sy[AttribRangeMin]; v != nil {
rmin = v.(float32)
}
// Range max
rmax := float32(10)
if v := sy[AttribRangeMax]; v != nil {
rmax = v.(float32)
}
chart.SetRangeY(rmin, rmax)
// Range auto
if rauto := sy[AttribRangeAuto]; rauto != nil {
chart.SetRangeYauto(v.(bool))
}
}
return chart, nil
}
// buildTable builds a gui object of type: Table
func buildTable(b *Builder, am map[string]interface{}) (IPanel, error) {
// Internal function to build a TableColumn from its attribute map
buildTableCol := func(b *Builder, am map[string]interface{}) (*TableColumn, error) {
tc := &TableColumn{}
if iv := am[AttribId]; iv != nil {
tc.Id = iv.(string)
}
if iv := am[AttribHeader]; iv != nil {
tc.Header = iv.(string)
}
if iv := am[AttribWidth]; iv != nil {
tc.Width = iv.(float32)
}
if iv := am[AttribMinwidth]; iv != nil {
tc.Minwidth = iv.(float32)
}
if iv := am[AttribHidden]; iv != nil {
tc.Hidden = iv.(bool)
}
if iv := am[AttribFormat]; iv != nil {
tc.Format = iv.(string)
}
if iv := am[AttribExpand]; iv != nil {
tc.Expand = iv.(float32)
}
if iv := am[AttribResize]; iv != nil {
tc.Resize = iv.(bool)
}
if iv := am[AttribSortType]; iv != nil {
tc.Sort = iv.(TableSortType)
}
return tc, nil
}
// Builds table columns array
tableCols := []TableColumn{}
if iv := am[AttribColumns]; iv != nil {
cols := iv.([]map[string]interface{})
for _, c := range cols {
tc, err := buildTableCol(b, c)
if err != nil {
return nil, err
}
tableCols = append(tableCols, *tc)
}
}
// Creates table and set common attributes
table, err := NewTable(0, 0, tableCols)
if err != nil {
return nil, err
}
err = b.SetAttribs(am, table)
if err != nil {
return nil, err
}
// Sets optional show header attribute
if show := am[AttribShowHeader]; show != nil {
table.ShowHeader(show.(bool))
}
return table, nil
}
// buildTabBar builds a gui object of type: TabBare
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)
if err != nil {
return nil, err
}
v := am[AttribItems]
// For each tab
if v != nil {
items := v.([]map[string]interface{})
for _, item := range items {
// Creates Tab
text := ""
if v := item[AttribText]; v != nil {
text = v.(string)
}
tab := tabbar.AddTab(text)
// Sets optional icon
if v := item[AttribIcon]; v != nil {
tab.SetIcon(v.(string))
}
// Sets optional image
if v := item[AttribImageFile]; v != nil {
// If path is not absolute join with user supplied image base path
imagefile := v.(string)
if !filepath.IsAbs(imagefile) {
imagefile = filepath.Join(b.imgpath, imagefile)
}
err := tab.SetImage(imagefile)
if err != nil {
return nil, err
}
}
// Sets content panel
if v := item[AttribContent]; v != nil {
am := v.(map[string]interface{})
content, err := b.build(am, nil)
if err != nil {
return nil, err
}
tab.SetContent(content)
}
// Sets pinned state
if v := item[AttribPinned]; v != nil {
tab.SetPinned(v.(bool))
}
}
}
return tabbar, nil
}