Roblox UtilitiesDevlHub Roblox Documentation

Class

StyleSheet

Inherits
StyleBase › Instance › Object
Memory category
Gui

Aggregates StyleRules and can be linked to DataModel trees to apply style properties to instances.

Aggregates StyleRules and can be linked to DataModel trees to apply style properties to instances. Note that a StyleSheet may exist outside the DataModel, but it cannot be derived or linked to a DataModel tree in such a case.

Methods 2#

GetDerivesReturns an array of other StyleSheets from which the StyleSheet is deriving StyleRules and token definitions.
SetDerivesSets the StyleSheet to derive StyleRules and token definitions from one or more other StyleSheets.

GetDerives(): List<StyleSheet>#

Returns an array of other StyleSheets from which the StyleSheet is deriving StyleRules and token definitions.

Returns
  • List<StyleSheet> — Array of other StyleSheets.

SetDerives(derives: Instances): ()#

Sets the StyleSheet to derive StyleRules and token definitions from one or more other StyleSheets in the order they are listed. This method spawns the appropriate StyleDerive instances and sets their priorities to establish the specified derivations.

Luau
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")

-- Create a tokens style sheet
local tokensSheet = Instance.new("StyleSheet")
tokensSheet.Name = "Tokens"
tokensSheet.Parent = ReplicatedStorage
-- Set tokens (attributes) on tokens sheet
tokensSheet:SetAttribute("LightGray", Color3.new(0.9, 0.9, 0.9))
tokensSheet:SetAttribute("DarkGray", Color3.new(0.2, 0.2, 0.2))

-- Create theme style sheets
local lightThemeSheet = Instance.new("StyleSheet")
lightThemeSheet.Name = "LightTheme"
lightThemeSheet:SetAttribute("Background", "$LightGray")
lightThemeSheet.Parent = ReplicatedStorage
local darkThemeSheet = Instance.new("StyleSheet")
darkThemeSheet.Name = "DarkTheme"
darkThemeSheet:SetAttribute("Background", "$DarkGray")
darkThemeSheet.Parent = ReplicatedStorage

-- Set theme sheets to derive from tokens sheet
lightThemeSheet:SetDerives({ tokensSheet })
darkThemeSheet:SetDerives({ tokensSheet })

local themeDerive = Instance.new("StyleDerive")
themeDerive.Parent = coreSheet
themeDerive.StyleSheet = lightThemeSheet

-- Function to dynamically change the derived theme for the core sheet
local function changeTheme()
	if themeDerive.StyleSheet == lightThemeSheet then
		themeDerive.StyleSheet = darkThemeSheet
	elseif themeDerive.StyleSheet == darkThemeSheet then
		themeDerive.StyleSheet = lightThemeSheet
	end
end

Note that if you've created a design using the Style Editor, the StyleSheet sheet in the Design folder of ReplicatedStorage will contain a StyleDerive to the BaseStyleSheet also in the Design folder. When setting derives with SetDerives(), be sure to include the base style sheet in the spot of least priority in relation to other StyleSheets in the derives array.

NameTypeDefaultDescription
derivesInstancesArray of other StyleSheets to derive StyleRules and token definitions from.
Returns
  • ()

Inherited members#

Inherited from StyleBase 4
Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed