Class
StyleSheet
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#
| GetDerives | Returns an array of other StyleSheets from which the StyleSheet is
deriving StyleRules and token definitions. |
| SetDerives | Sets 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 otherStyleSheets.
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.
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
endNote 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.
| Name | Type | Default | Description |
|---|---|---|---|
derives | Instances | Array of other StyleSheets to derive StyleRules
and token definitions from. |
Returns
()
Inherited members#
Inherited from Instance 58
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild