rev |
line source |
jbe/bsw@0
|
1 --[[--
|
jbe/bsw@0
|
2 ui.container{
|
jbe/bsw@0
|
3 auto_args = auto_args,
|
jbe/bsw@0
|
4 attr = attr, -- HTML attributes for the surrounding div or fieldset
|
jbe/bsw@0
|
5 label = label, -- text to be used as label
|
jbe/bsw@0
|
6 label_for = label_for, -- DOM id of element to which the label should refer
|
jbe/bsw@0
|
7 label_attr = label_attr, -- extra HTML attributes for a label tag
|
jbe/bsw@0
|
8 legend = legend, -- text to be used as legend
|
jbe/bsw@0
|
9 legend_attr = legend_attr, -- HTML attributes for a legend tag
|
jbe/bsw@0
|
10 content_first = content_first, -- set to true to place label or legend after the content
|
jbe/bsw@0
|
11 content = function()
|
jbe/bsw@14
|
12 ...
|
jbe/bsw@0
|
13 end
|
jbe/bsw@0
|
14 }
|
jbe/bsw@0
|
15
|
jbe/bsw@0
|
16 This function encloses content in a div element (or a fieldset element, if 'legend' is given). An additional 'label' or 'legend' can be placed before the content or after the content. The argument 'auto_args' is set by other ui helper functions when calling ui.container automatically.
|
jbe/bsw@0
|
17
|
jbe/bsw@0
|
18 --]]--
|
jbe/bsw@0
|
19
|
jbe/bsw@0
|
20 function ui.container(args)
|
jbe@534
|
21 local attr, label, label_attr, legend, legend_attr, content
|
jbe/bsw@0
|
22 local auto_args = args.auto_args
|
jbe/bsw@0
|
23 if auto_args then
|
jbe/bsw@0
|
24 attr = auto_args.container_attr
|
jbe/bsw@0
|
25 label = auto_args.label
|
jbe/bsw@0
|
26 label_attr = auto_args.label_attr
|
jbe/bsw@0
|
27 legend = auto_args.legend
|
jbe/bsw@0
|
28 legend_attr = auto_args.legend_attr
|
jbe/bsw@0
|
29 if label and auto_args.attr and auto_args.attr.id then
|
jbe/bsw@0
|
30 label_attr = table.new(label_attr)
|
jbe/bsw@0
|
31 label_attr["for"] = auto_args.attr.id
|
jbe/bsw@0
|
32 end
|
jbe/bsw@0
|
33 else
|
jbe/bsw@0
|
34 attr = args.attr
|
jbe/bsw@0
|
35 label = args.label
|
jbe/bsw@0
|
36 label_attr = args.label_attr or {}
|
jbe/bsw@0
|
37 legend = args.legend
|
jbe/bsw@0
|
38 legend_attr = args.legend_attr
|
jbe/bsw@0
|
39 content = content
|
jbe/bsw@0
|
40 if args.label_for then
|
jbe/bsw@0
|
41 label_attr["for"] = args.label_for
|
jbe/bsw@0
|
42 end
|
jbe/bsw@0
|
43 end
|
jbe/bsw@0
|
44 local content = args.content
|
jbe/bsw@0
|
45 if label and not legend then
|
jbe/bsw@0
|
46 return ui.tag {
|
jbe/bsw@0
|
47 tag = "div",
|
jbe/bsw@0
|
48 attr = attr,
|
jbe/bsw@0
|
49 content = function()
|
jbe/bsw@0
|
50 if not args.content_first then
|
jbe/bsw@0
|
51 ui.tag{ tag = "label", attr = label_attr, content = label }
|
jbe/bsw@0
|
52 slot.put(" ")
|
jbe/bsw@0
|
53 end
|
jbe/bsw@0
|
54 if type(content) == "function" then
|
jbe@534
|
55 content()
|
jbe/bsw@0
|
56 elseif content then
|
jbe/bsw@0
|
57 slot.put(encode.html(content))
|
jbe/bsw@0
|
58 end
|
jbe/bsw@0
|
59 if args.content_first then
|
jbe/bsw@0
|
60 slot.put(" ")
|
jbe/bsw@0
|
61 ui.tag{ tag = "label", attr = label_attr, content = label }
|
jbe/bsw@0
|
62 end
|
jbe/bsw@0
|
63 end
|
jbe/bsw@0
|
64 }
|
jbe/bsw@0
|
65 elseif legend and not label then
|
jbe/bsw@0
|
66 return ui.tag {
|
jbe/bsw@0
|
67 tag = "fieldset",
|
jbe/bsw@0
|
68 attr = attr,
|
jbe/bsw@0
|
69 content = function()
|
jbe/bsw@0
|
70 if not args.content_first then
|
jbe/bsw@0
|
71 ui.tag{ tag = "legend", attr = legend_attr, content = legend }
|
jbe/bsw@0
|
72 slot.put(" ")
|
jbe/bsw@0
|
73 end
|
jbe/bsw@0
|
74 if type(content) == "function" then
|
jbe/bsw@0
|
75 content()
|
jbe/bsw@0
|
76 elseif content then
|
jbe/bsw@0
|
77 slot.put(encode.html(content))
|
jbe/bsw@0
|
78 end
|
jbe/bsw@0
|
79 if args.content_first then
|
jbe/bsw@0
|
80 slot.put(" ")
|
jbe/bsw@0
|
81 ui.tag{ tag = "legend", attr = legend_attr, content = legend }
|
jbe/bsw@0
|
82 end
|
jbe/bsw@0
|
83 end
|
jbe/bsw@0
|
84 }
|
bsw@475
|
85 elseif legend and label then
|
jbe/bsw@0
|
86 error("ui.container{...} may either get a label or a legend.")
|
jbe/bsw@0
|
87 else
|
jbe/bsw@0
|
88 return ui.tag{ tag = "div", attr = attr, content = content }
|
jbe/bsw@0
|
89 end
|
jbe/bsw@0
|
90 end
|