WidgetGetSkinColor

Syntax

Success = WidgetGetSkinColor(Widget, Component$, Property$, *Color.Long, *Opacity.Float)

Description

Retrieves the color and opacity defined by the skin for the specified widget, component, and property. This function specifically looks for properties whose parsed value corresponds to a color definition (e.g., `background-color`, `color`, `border-color`).

Parameters

Widget
The handle of the ProGUI widget.

Component$
The name of the component part of the widget (e.g., "", "thumb").

Property$
The name of the skin property that defines the color (e.g., "background-color", "color").

*Color.Long
A pointer to a Long variable that will receive the RGB color value (format $BBGGRR). Initialized to 0.

*Opacity.Float
A pointer to a Float variable that will receive the opacity value (0.0 to 1.0). Initialized to 1.0.

Return Value

Returns #True if a valid color definition was found in the skin for the given widget, component, state, and property, and the values were written to the provided pointers. Returns #False otherwise.

Remarks

This function simplifies retrieving color values from the skin. It internally uses WidgetGetSkinData() and checks if the returned data type is #PG_Skin_Type_Color or #PG_Skin_Type_Background (extracting the color part from the background). The retrieved color and opacity depend on the widget's current state set via WidgetSetSkinState(). If the property is not found or doesn't define a color, the variables pointed to by `*Color` and `*Opacity` remain unchanged from their initial values (0 and 1.0 respectively, as set by this function before attempting retrieval).

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

; Define some skin properties
SkinSetValue("myColorWidget", "", "", "background-color", "rgba(0, 0, 255, 0.5)") ; Blue at 50% opacity
SkinSetValue("myColorWidget", "", "", "color", "white") ; Text color
SkinSetValue("myColorWidget", "hover", "", "background-color", "green") ; Solid green on hover

Procedure DrawColorWidget(Widget, EventType, *EventData.PG_EventDraw, *UserData)
  ; Get background color and opacity from skin
  WidgetGetSkinColor(Widget, "", "background-color", @bgColor.l, @bgOpacity.f)
  ; Get text color and opacity from skin
  WidgetGetSkinColor(Widget, "", "color", @textColor.l, @textOpacity.f)

  ; Draw background using retrieved values
  DrawBox(0, 0, *EventData\width, *EventData\height, bgColor, bgOpacity)

  ; Draw text using retrieved values
  Shared MyTextObj ; Static text object for efficiency
  If MyTextObj = 0 : MyTextObj = CreateText("Color", "Arial", 14) : EndIf
  TextSetWidth(MyTextObj, *EventData\width)
  TextSetHeight(MyTextObj, *EventData\height)
  DrawTxt(MyTextObj, 0, 0, textColor, textOpacity)
EndProcedure

Procedure MouseColorWidget(Widget, EventType, *EventData.PG_EventMouse)
  Select EventType
    Case #PG_Event_MouseEnter : WidgetSetSkinState(Widget, "hover")
    Case #PG_Event_MouseLeave : WidgetSetSkinState(Widget, "")
  EndSelect
EndProcedure

MyWindow = CreateWindow(0, 0, 200, 100, "Get Skin Color")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetPadding(RootLayout, 10)

If MyWindow
  ColorWidget = CreateWidget(0, 0, #PG_Widget_FitContent, #PG_Widget_FitContent)
  WidgetSetMinWidth(ColorWidget, 50)
  WidgetSetMinHeight(ColorWidget, 30)
  WidgetSetClass(ColorWidget, "myColorWidget")
  AddEventHandler(ColorWidget, #PG_Event_Draw, @DrawColorWidget())
  AddEventHandler(ColorWidget, #PG_Event_MouseEnter, @MouseColorWidget())
  AddEventHandler(ColorWidget, #PG_Event_MouseLeave, @MouseColorWidget())

  WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

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

StopProGUI()

See Also

WidgetGetSkinData, WidgetGetSkinBorder, WidgetSetSkinState, SkinSetValue

Supported OS

Windows, Linux