Start work on plugin UI, this is pretty painful

This commit is contained in:
Lucien Greathouse
2019-01-03 18:06:24 -08:00
parent b7a28aa511
commit 5816bb64dc
5 changed files with 348 additions and 13 deletions

View File

@@ -0,0 +1,63 @@
local Roact = require(script:FindFirstAncestor("Rojo").Roact)
local e = Roact.createElement
local function merge(...)
local output = {}
for i = 1, select("#", ...) do
local source = select(i, ...)
if source ~= nil then
for key, value in pairs(source) do
output[key] = value
end
end
end
return output
end
local FitList = Roact.Component:extend("FitList")
function FitList:init()
self.sizeBinding, self.setSize = Roact.createBinding(UDim2.new())
end
function FitList:render()
local containerProps = self.props.containerProps
local layoutProps = self.props.layoutProps
local paddingProps = self.props.paddingProps
local padding
if paddingProps ~= nil then
padding = e("UIPadding", paddingProps)
end
local children = merge(self.props[Roact.Children], {
["$Layout"] = e("UIListLayout", merge({
SortOrder = Enum.SortOrder.LayoutOrder,
[Roact.Change.AbsoluteContentSize] = function(instance)
local size = instance.AbsoluteContentSize
if paddingProps ~= nil then
size = size + Vector2.new(
paddingProps.PaddingLeft.Offset + paddingProps.PaddingRight.Offset,
paddingProps.PaddingTop.Offset + paddingProps.PaddingBottom.Offset)
end
self.setSize(UDim2.new(0, size.X, 0, size.Y))
end,
}, layoutProps)),
["$Padding"] = padding,
})
local fullContainerProps = merge(containerProps, {
Size = self.sizeBinding,
})
return e("Frame", fullContainerProps, children)
end
return FitList