Hgy29 WidgetKit WIP

From GiderosMobile
Revision as of 14:29, 13 July 2023 by Hgy29 (talk | contribs) (Text replacement - "</source>" to "</syntaxhighlight>")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

[Full screen here]

local Button=UI.Factory.new(
	{ class="UI.Panel", Alpha=0, layoutModel={}, 
		Border={class=UI.Border.Basic, params={ radius=3, bgColor=0x8080FF, bgAlpha=1}},
		name="tfConnect", 
		children={
			{ class="UI.Label", layout={}, name="tfLabel" }
		}
	},
	function (b,d) 
		b.tfLabel:setText(d.Text)
	end
)

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)