Difference between revisions of "Hgy29 WidgetKit WIP"
From GiderosMobile
| Line 1: | Line 1: | ||
| {{#widget:GApp|app=UIDemo.GApp|plugins=json|width=800|height=600}} | {{#widget:GApp|app=UIDemo.GApp|plugins=json|width=800|height=600}} | ||
| + | |||
| + | <source lang="lua"> | ||
| + | local demo=UI.Builder({ | ||
| + | 		class="UI.Panel", Color=0xc0c0c0, Alpha=0,  | ||
| + | 		Border=UI.Border.Basic.new{ thickness=3, radius=10, bgColor=0xc0ffc0,bgAlpha=1,fgColor=0x000000,fgAlpha=1 }, | ||
| + | 		layoutModel=UI.Layout.Vertical, | ||
| + | 		children={ | ||
| + | 			{ class="UI.Label", Text="Gideros WidgetKit demo" }, | ||
| + | 			{ class="UI.Panel", Alpha=0, layoutModel=UI.Layout.Horizontal, layout={weighty=1,weightx=1,insetBottom=2}, | ||
| + | 				children={ | ||
| + | 					--Directory Tree | ||
| + | 					{ class=UI.Viewport, layout={weightx=1,fill=1}, | ||
| + | 						Content={ class="UI.Tree", name="dirTree", layout={anchor=Sprite.LAYOUT_ANCHOR_NORTHWEST},  | ||
| + | 						selection=UI.Selection.SINGLE, | ||
| + | 						dataMapper=function(item)  | ||
| + | 							if type(item)=="string" then  | ||
| + | 								return item | ||
| + | 							else | ||
| + | 								return item.name,item.sub | ||
| + | 							end | ||
| + | 						end, data={ | ||
| + | 							"A", | ||
| + | 							"B", | ||
| + | 							{ name="C", sub={ | ||
| + | 								"1", | ||
| + | 								{ name="2", sub={"a","b"}}, | ||
| + | 								"3"}}, | ||
| + | 							"D" | ||
| + | 						}}, | ||
| + | 					}, | ||
| + | 					--Right side | ||
| + | 					{ class="UI.Panel", Alpha=0, layoutModel=UI.Layout.Vertical, layout={weightx=3}, | ||
| + | 						children={ | ||
| + | 							{ class=UI.Checkbox,Label="This is a checkbox",  }, | ||
| + | 							{ class="UI.Panel", Alpha=0, layoutModel=UI.Layout.Horizontal, layout={ fill=Sprite.LAYOUT_FILL_NONE,anchor=Sprite.LAYOUT_ANCHOR_WEST}, | ||
| + | 								children={ | ||
| + | 									{ class=UI.Radio,Label="Radio 1", Group="RadioA" }, | ||
| + | 									{ class=UI.Radio,Label="Radio 2", Group="RadioA" }, | ||
| + | 									{ class=UI.Radio,Label="Radio 3", Group="RadioA" }, | ||
| + | 								}, | ||
| + | 							}, | ||
| + | 							{ class="UI.Panel", Alpha=0, layoutModel=UI.Layout.Horizontal, layout={ fill=Sprite.LAYOUT_FILL_NONE,anchor=Sprite.LAYOUT_ANCHOR_WEST}, | ||
| + | 								children={ | ||
| + | 									{ class="UI.Label", Text="Editable Text:" }, | ||
| + | 									{ class="UI.TextField", layout={minWidth=300,prefWidth=300} }, | ||
| + | 								}, | ||
| + | 							}, | ||
| + | 							{ class="UI.Panel", Alpha=0, layoutModel=UI.Layout.Horizontal, layout={ fill=Sprite.LAYOUT_FILL_NONE,anchor=Sprite.LAYOUT_ANCHOR_WEST}, | ||
| + | 								children={ | ||
| + | 									{ class="UI.Label", Text="Editable Password:" }, | ||
| + | 									{ class="UI.TextField", Password="•", layout={minWidth=200,prefWidth=200} }, | ||
| + | 								}, | ||
| + | 							}, | ||
| + | 							{ class="UI.Label", Text="Multiline Text:" }, | ||
| + | 							{ class="UI.TextField", layout={fill=1, TextLayout={ flags=FontBase.TLF_TOP, multiline=true},minHeight=80, prefHeight=80 }}, | ||
| + | 							{ class="UI.Label", Text="Table:" }, | ||
| + | 							{ class=UI.Viewport,  layout={weighty=1,fill=1}, | ||
| + | 								Content={ class="UI.Table", name="fileTable", layout={fill=Sprite.LAYOUT_FILL_HORIZONTAL,anchor=Sprite.LAYOUT_ANCHOR_NORTHWEST}, | ||
| + | 								selection=UI.Selection.MULTIPLE, | ||
| + | 								Columns={ | ||
| + | 									{ name="First name",field="first",weight=2}, | ||
| + | 									{ name="Last name",field="last",weight=2}, | ||
| + | 									{ name="Song",field="song",weight=3}}, | ||
| + | 								data={ | ||
| + | 									{ first="John", last="Lennon", song="Imagine"}, | ||
| + | 									{ first="Paul", last="McCartney", song="Maybe I'm Amazed"}, | ||
| + | 									{ first="George", last="Harrison", song="My Sweet Lord"}, | ||
| + | 									{ first="Ringo", last="Starr", song="Photograph"}, | ||
| + | 								}	}, | ||
| + | 							}, | ||
| + | 						}, | ||
| + | 					}, | ||
| + | 				} | ||
| + | 			}, | ||
| + | 			{ class="UI.Panel", Alpha=0, layoutModel=UI.Layout.Horizontal, | ||
| + | 				children={ | ||
| + | 					{ class=UI.Panel,Alpha=0,layout={weightx=1} }, --Filler | ||
| + | 					{ factory=Button, name="btOK", Text="OK",layout={insets=10} }, | ||
| + | 					{ factory=Button, name="btCancel", Text="Cancel",layout={insets=10} }, | ||
| + | 				}, | ||
| + | 			} | ||
| + | 		} | ||
| + | 	}) | ||
| + | stage:addChild(demo) | ||
| + | |||
| + | </source> | ||
Revision as of 16:09, 23 December 2019
local demo=UI.Builder({
		class="UI.Panel", Color=0xc0c0c0, Alpha=0, 
		Border=UI.Border.Basic.new{ thickness=3, radius=10, bgColor=0xc0ffc0,bgAlpha=1,fgColor=0x000000,fgAlpha=1 },
		layoutModel=UI.Layout.Vertical,
		children={
			{ class="UI.Label", Text="Gideros WidgetKit demo" },
			{ class="UI.Panel", Alpha=0, layoutModel=UI.Layout.Horizontal, layout={weighty=1,weightx=1,insetBottom=2},
				children={
					--Directory Tree
					{ class=UI.Viewport, layout={weightx=1,fill=1},
						Content={ class="UI.Tree", name="dirTree", layout={anchor=Sprite.LAYOUT_ANCHOR_NORTHWEST}, 
						selection=UI.Selection.SINGLE,
						dataMapper=function(item) 
							if type(item)=="string" then 
								return item
							else
								return item.name,item.sub
							end
						end, data={
							"A",
							"B",
							{ name="C", sub={
								"1",
								{ name="2", sub={"a","b"}},
								"3"}},
							"D"
						}},
					},
					--Right side
					{ class="UI.Panel", Alpha=0, layoutModel=UI.Layout.Vertical, layout={weightx=3},
						children={
							{ class=UI.Checkbox,Label="This is a checkbox",  },
							{ class="UI.Panel", Alpha=0, layoutModel=UI.Layout.Horizontal, layout={ fill=Sprite.LAYOUT_FILL_NONE,anchor=Sprite.LAYOUT_ANCHOR_WEST},
								children={
									{ class=UI.Radio,Label="Radio 1", Group="RadioA" },
									{ class=UI.Radio,Label="Radio 2", Group="RadioA" },
									{ class=UI.Radio,Label="Radio 3", Group="RadioA" },
								},
							},
							{ class="UI.Panel", Alpha=0, layoutModel=UI.Layout.Horizontal, layout={ fill=Sprite.LAYOUT_FILL_NONE,anchor=Sprite.LAYOUT_ANCHOR_WEST},
								children={
									{ class="UI.Label", Text="Editable Text:" },
									{ class="UI.TextField", layout={minWidth=300,prefWidth=300} },
								},
							},
							{ class="UI.Panel", Alpha=0, layoutModel=UI.Layout.Horizontal, layout={ fill=Sprite.LAYOUT_FILL_NONE,anchor=Sprite.LAYOUT_ANCHOR_WEST},
								children={
									{ class="UI.Label", Text="Editable Password:" },
									{ class="UI.TextField", Password="•", layout={minWidth=200,prefWidth=200} },
								},
							},
							{ class="UI.Label", Text="Multiline Text:" },
							{ class="UI.TextField", layout={fill=1, TextLayout={ flags=FontBase.TLF_TOP, multiline=true},minHeight=80, prefHeight=80 }},
							{ class="UI.Label", Text="Table:" },
							{ class=UI.Viewport,  layout={weighty=1,fill=1},
								Content={ class="UI.Table", name="fileTable", layout={fill=Sprite.LAYOUT_FILL_HORIZONTAL,anchor=Sprite.LAYOUT_ANCHOR_NORTHWEST},
								selection=UI.Selection.MULTIPLE,
								Columns={
									{ name="First name",field="first",weight=2},
									{ name="Last name",field="last",weight=2},
									{ name="Song",field="song",weight=3}},
								data={
									{ first="John", last="Lennon", song="Imagine"},
									{ first="Paul", last="McCartney", song="Maybe I'm Amazed"},
									{ first="George", last="Harrison", song="My Sweet Lord"},
									{ first="Ringo", last="Starr", song="Photograph"},
								}	},
							},
						},
					},
				}
			},
			{ class="UI.Panel", Alpha=0, layoutModel=UI.Layout.Horizontal,
				children={
					{ class=UI.Panel,Alpha=0,layout={weightx=1} }, --Filler
					{ factory=Button, name="btOK", Text="OK",layout={insets=10} },
					{ factory=Button, name="btCancel", Text="Cancel",layout={insets=10} },
				},
			}
		}
	})
stage:addChild(demo)
