/
tab.go
60 lines (54 loc) · 1.68 KB
/
tab.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
package widget
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
)
func init() {
Regist("tab", tab{})
}
type tab struct{}
func (t tab) Create(conf Config, childs []fyne.CanvasObject) (fyne.CanvasObject, error) {
w := container.NewAppTabs()
if conf.Width > 1 && conf.Height > 1 {
w.Resize(fyne.NewSize(conf.Width, conf.Height))
}
autoBox := conf.Params["auto_box"]
for i, it := range childs {
key := fmt.Sprintf("tab%d", i)
name, ok := conf.Params[key]
if !ok {
name = key
}
if autoBox == "true" {
box := container.NewVBox(it, layout.NewSpacer())
w.Append(container.NewTabItem(name, box))
} else {
w.Append(container.NewTabItem(name, it))
}
}
switch conf.Params["layout"] {
case "top", "t":
w.SetTabLocation(container.TabLocationTop)
case "bottom", "b":
w.SetTabLocation(container.TabLocationBottom)
case "left", "leading", "l":
w.SetTabLocation(container.TabLocationLeading)
case "right", "trailing", "r":
w.SetTabLocation(container.TabLocationTrailing)
default:
w.SetTabLocation(container.TabLocationTop)
}
return w, nil
}
func (t tab) Help() string {
out := fmt.Sprintln("type:tab")
out += fmt.Sprintln(" describtion: new tab.")
out += fmt.Sprintln(" Params.layout: omitempty, top(default);bottom/b;left/leading/l;right/trailing/r")
out += fmt.Sprintln(" Params.auto_box: omitempty, enable set to true, it will new box to indeude child widget. true=>child.size.auto;false=>child.size.max")
out += fmt.Sprintln(" Params.tab0: omitempty, the label of tab name")
out += fmt.Sprintln(" Params.tab1: omitempty, the label of tab name")
out += fmt.Sprintln(" Params.tab$i$: omitempty, the label of tab name")
return out
}