Created
August 21, 2025 01:08
-
-
Save metatablecat/f579323ce0ccfaded41966bde106e582 to your computer and use it in GitHub Desktop.
Small module for converting Luau code to Stylesheet instances.r
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return { | |
| Name = "BaseStyleSheet", | |
| DeriveFromBase = false, | |
| Rules = { | |
| CanvasGroup = { | |
| Priority = 9, | |
| BackgroundColor3 = Color3.new(1,1,1), | |
| BorderColor3 = Color3.new(0,0,0), | |
| BorderSizePixel = 0, | |
| Size = UDim2.fromOffset(100, 100) | |
| }, | |
| Frame = { | |
| Priority = 0, | |
| BackgroundColor3 = Color3.new(1,1,1), | |
| BorderColor3 = Color3.new(0,0,0), | |
| BorderSizePixel = 0, | |
| Size = UDim2.fromOffset(100, 100) | |
| }, | |
| ImageButton = { | |
| Priority = 5, | |
| BackgroundColor3 = Color3.new(1,1,1), | |
| BorderColor3 = Color3.new(0,0,0), | |
| BorderSizePixel = 0, | |
| Image = "rbxasset://textures/ui/GuiImagePlaceholder.png", | |
| Size = UDim2.fromOffset(100, 100) | |
| }, | |
| ImageLabel = { | |
| Priority = 5, | |
| BackgroundColor3 = Color3.new(1,1,1), | |
| BorderColor3 = Color3.new(0,0,0), | |
| BorderSizePixel = 0, | |
| Image = "rbxasset://textures/ui/GuiImagePlaceholder.png", | |
| Size = UDim2.fromOffset(100, 100) | |
| }, | |
| ScrollingFrame = { | |
| Priority = 1, | |
| Active = true, | |
| BackgroundColor3 = Color3.new(1,1,1), | |
| BorderColor3 = Color3.new(0,0,0), | |
| BorderSizePixel = 0, | |
| ScrollBarImageColor3 = Color3.new(0,0,0), | |
| Size = UDim2.fromOffset(100, 100) | |
| }, | |
| TextBox = { | |
| Priority = 4, | |
| BackgroundColor3 = Color3.new(1,1,1), | |
| BorderColor3 = Color3.new(0,0,0), | |
| BorderSizePixel = 0, | |
| FontFace = Font.fromEnum(Enum.Font.SourceSans), | |
| Size = UDim2.fromOffset(200, 50), | |
| TextColor3 = Color3.new(0,0,0), | |
| TextSize = 14 | |
| }, | |
| TextButton = { | |
| Priority = 3, | |
| BackgroundColor3 = Color3.new(1,1,1), | |
| BorderColor3 = Color3.new(0,0,0), | |
| BorderSizePixel = 0, | |
| FontFace = Font.fromEnum(Enum.Font.SourceSans), | |
| Size = UDim2.fromOffset(200, 50), | |
| TextColor3 = Color3.new(0,0,0), | |
| TextSize = 14 | |
| }, | |
| TextLabel = { | |
| Priority = 2, | |
| BackgroundColor3 = Color3.new(1,1,1), | |
| BorderColor3 = Color3.new(0,0,0), | |
| BorderSizePixel = 0, | |
| FontFace = Font.fromEnum(Enum.Font.SourceSans), | |
| Size = UDim2.fromOffset(200, 50), | |
| TextColor3 = Color3.new(0,0,0), | |
| TextSize = 14 | |
| }, | |
| UIGridLayout = { | |
| Priority = 11, | |
| SortOrder = Enum.SortOrder.LayoutOrder | |
| }, | |
| UIListLayout = { | |
| Priority = 10, | |
| SortOrder = Enum.SortOrder.LayoutOrder | |
| }, | |
| UIPageLayout = { | |
| Priority = 12, | |
| SortOrder = Enum.SortOrder.LayoutOrder | |
| }, | |
| UITableLayout = { | |
| Priority = 13, | |
| SortOrder = Enum.SortOrder.LayoutOrder | |
| }, | |
| VideoFrame = { | |
| Priority = 8, | |
| BackgroundColor3 = Color3.new(1,1,1), | |
| BorderColor3 = Color3.new(0,0,0), | |
| BorderSizePixel = 0, | |
| Size = UDim2.fromOffset(100, 100) | |
| }, | |
| ViewportFrame = { | |
| Priority = 7, | |
| BackgroundColor3 = Color3.new(1,1,1), | |
| BorderColor3 = Color3.new(0,0,0), | |
| BorderSizePixel = 0, | |
| Size = UDim2.fromOffset(100, 100) | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- This is temporary until we get a proper way to build stylesheets directly | |
| -- from a file that isn't Luau. | |
| type Rule = { | |
| Priority: number?, | |
| Nested: {[string]: Rule}?, | |
| [string|number]: any | |
| } | |
| type StylesheetDoc = { | |
| -- rule: | |
| Name: string, | |
| DeriveFromBase: boolean, | |
| Rules: {[string]: Rule}?, | |
| Tokens: {[string]: any}? | |
| } | |
| local baseSheetModule = require(script.Parent.BaseStyleSheet)::StylesheetDoc | |
| local baseStyleSheet: StyleSheet | |
| local function makeRules(rules: {[string]: Rule}, parent: StyleSheet|StyleRule) | |
| for selector, rule: Rule in rules do | |
| local ruleEntry = Instance.new("StyleRule") | |
| ruleEntry.Archivable = false | |
| ruleEntry.Name = selector | |
| ruleEntry.Selector = selector | |
| if rule.Priority then | |
| ruleEntry.Priority = rule.Priority | |
| rule.Priority = nil | |
| end | |
| if rule.Nested then | |
| makeRules(rule.Nested, ruleEntry) | |
| rule.Nested = nil | |
| end | |
| ruleEntry:SetProperties(rule) | |
| ruleEntry.Parent = parent | |
| end | |
| end | |
| local function makeStyleSheet(t: StylesheetDoc): StyleSheet | |
| local sheet = Instance.new("StyleSheet") | |
| sheet.Archivable = false | |
| sheet.Name = t.Name | |
| if t.DeriveFromBase then | |
| local derive = Instance.new("StyleDerive") | |
| derive.Archivable = false | |
| derive.StyleSheet = baseStyleSheet | |
| derive.Name = "BaseDerive" | |
| derive.Parent = sheet | |
| end | |
| if t.Tokens then | |
| for tokenName, token in t.Tokens do | |
| sheet:SetAttribute(tokenName, token) | |
| end | |
| end | |
| if t.Rules then makeRules(t.Rules, sheet) end | |
| return sheet | |
| end | |
| baseStyleSheet = makeStyleSheet(baseSheetModule) | |
| baseStyleSheet.Parent = script | |
| return makeStyleSheet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment