SkinSetTheme

Syntax

Success = SkinSetTheme(ThemeName$, Skin=#Null)

Description

Sets the active theme for the specified skin. This determines which theme-specific rules (e.g., rules defined with a "dark:" prefix) will be applied during style resolution.

Parameters

ThemeName$
The name of the theme to activate (e.g., "dark", "contrast"). An empty string ("") activates the base (default) theme, meaning only rules without a theme prefix will be primarily considered.

Skin (optional)
The handle of the skin object whose theme should be set. If #Null, the current default skin is modified. Default is #Null.

Return Value

Returns #True if the theme was successfully set, or #False if the skin handle was invalid.

Remarks

Changing the active theme invalidates the internal skin cache for all widgets using that skin, potentially triggering redraws or requiring a manual update (WindowUpdate(0)) to reflect the changes visually across the application. Theme names are typically derived from the filenames of the `.css` files loaded for the skin (e.g., `dark.css` corresponds to the "dark" theme).

Example

IncludeFile "ProGUI_PB.pbi"
StartProGUI()

MySkin = CreateSkin("ThemeTest")
SkinSetDefault(MySkin)

; Define base style
SkinSetValue("button", "", "", "background-color", "lightgrey")
; Define style for "dark" theme
SkinSetValue("dark:button", "", "", "background-color", "darkgrey")

MyWindow = CreateWindow(0, 0, 200, 100, "Theme Test")
MyButton = CreateWidget(10, 10, 100, 30)
WidgetSetClass(MyButton, "button") ; Will use lightgrey initially

WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
MessageRequester("Info", "Button should be light grey. Click OK to switch theme.", #PB_MessageRequester_Info)

; Set the theme to "dark"
SkinSetTheme("dark")
Debug "Theme set to: " + SkinGetTheme()

; Force an update to see the change
WindowUpdate(0)

MessageRequester("Info", "Button should now be dark grey.", #PB_MessageRequester_Info)

Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow

StopProGUI()

See Also

SkinGetTheme, LoadSkin, SkinSetValue, WindowUpdate

Supported OS

Windows, Linux