SkinSetValue

Syntax

Success = SkinSetValue(Path$, State$, Component$, Property$, Value$, Skin=#Null)

Description

Defines or modifies a styling rule within a specified skin object. This is the core function for programmatically building or altering skin definitions. It associates a value with a specific property, considering the widget's class path, state, and component part.

Parameters

Path$
The widget class selector path, using dot notation for hierarchy (e.g., "window.container.button", "mylistview"). Can optionally include a theme prefix (e.g., "dark:button", "light:window.list").

State$
The widget state to which this rule applies (e.g., "", "hover", "active", "disabled"). An empty string targets the base (default) state.

Component$
The specific component part within the widget to style (e.g., "", "thumb", "trackbar", "header"). An empty string targets the main widget element.

Property$
The name of the CSS-like property to set (e.g., "background-color", "border", "font-size", "transition", "border-top-left-radius").

Value$
The string value for the property (e.g., "red", "#FF0000", "10px", "solid blue 2px", "url('image.png')", "0.5s ease-in"). The string will be parsed internally based on the property name.

Skin (optional)
The handle of the skin object to modify. If #Null, the current default skin is used. Default is #Null.

Return Value

Returns #True if the value was successfully set or updated in the skin object. Returns #False if any of the required parameters (Path$, Property$) are empty, if the state/component/property names contain invalid characters (like ':'), or if the skin handle is invalid.

Remarks

This function adds or replaces a rule in the skin's internal storage. The `Value$` string is parsed based on the `Property$` name (e.g., "color" properties expect color values, "border-width" expects pixel values). Invalid value formats for a given property might lead to errors or unexpected behavior during rendering or data retrieval. Modifying skin values invalidates the internal skin cache for affected widgets, potentially requiring a redraw (WindowUpdate(0)) to see the changes. ProGUI defines handlers for known CSS properties; attempting to set an unknown property might store the value but have no visual effect.

Example

IncludeFile "ProGUI_PB.pbi"
StartProGUI()

MySkin = CreateSkin("ProgrammaticSkin")
If MySkin
SkinSetDefault(MySkin)

; Set base style for a widget with class "myButton"
SkinSetValue("myButton", "", "", "background-color", "rgb(200, 200, 200)")
SkinSetValue("myButton", "", "", "border", "1px solid grey")
SkinSetValue("myButton", "", "", "border-radius", "5px")
SkinSetValue("myButton", "", "", "color", "black") ; Text color

; Set hover state style
SkinSetValue("myButton", "hover", "", "background-color", "lightblue")
SkinSetValue("myButton", "hover", "", "border-color", "blue")

; Set active state style
SkinSetValue("myButton", "active", "", "background-color", "darkblue")
SkinSetValue("myButton", "active", "", "color", "white")

; Add a transition
SkinSetValue("myButton", "", "", "transition", "background-color 0.3s ease, color 0.3s ease")

; --- Create window and widgets ---
MyWindow = CreateWindow(0, 0, 200, 100, "SetValue Example")
Layout = WindowGetLayout(MyWindow)
LayoutSetPadding(Layout, 10)
MyButton = CreateWidget(0, 0, 100, 30)
WidgetSetClass(MyButton, "myButton") ; Assign the class

WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

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

Else
Debug "Failed to create skin."
EndIf

StopProGUI()

See Also

SkinGetValue, SkinGetData, CreateSkin, LoadSkin, WidgetSetClass, WidgetSetSkinState

Supported OS

Windows, Linux