DrawSkinText

Syntax

Success = DrawSkinText(Widget, Component$, x.d, y.d, Width.d, Height.d, Text$)

Description

Draws text onto the current drawing target using the text styling definitions currently defined within the active skin state of the specified widget. This function automatically applies all text-related CSS-like properties (e.g., font-family, font-size, color, text-align, font-weight) assigned to the widget’s skin component.

Parameters

Widget
The handle of the ProGUI widget whose skin defines the text styling.

Component$
The specific component name of the skin to pull the text style from (e.g., "" for the base widget, "title", "thumb", etc.). An empty string ("") refers to the main widget element.

x.d
The horizontal coordinate of the text layout’s top-left corner in device-independent pixels (DIPs) relative to the current drawing target.

y.d
The vertical coordinate of the text layout’s top-left corner in DIPs.

Width.d
The maximum width in DIPs to constrain the text layout to. Text wrapping and alignment will adhere to this boundary.

Height.d
The maximum height in DIPs to constrain the text layout to.

Text$
The string of text to draw.

Return Value

Returns #True if the text styles were successfully extracted from the skin and rendered, or #False if the widget handle was invalid or no text properties were found for the widget’s current state and component.

Remarks

This command is typically called within the widget’s #PG_Event_Draw event handler to render its text label or content with dynamic state adjustments. It automatically adapts to skin transitions (such as smoothly animating colors or font sizes between states).

If certain text properties are not explicitly defined in the widget’s skin, it will attempt to inherit properties up the layout tree or fall back to the default system font and size. It internally handles the creation and scaling of the text objects according to the current output’s DPI.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

; Define text skin properties for a custom widget class named "myTextWidget"
SkinSetValue("myTextWidget", "", "", "color", "darkblue")
SkinSetValue("myTextWidget", "", "", "font-family", "Arial")
SkinSetValue("myTextWidget", "", "", "font-size", "24px")
SkinSetValue("myTextWidget", "", "", "font-weight", "bold")
SkinSetValue("myTextWidget", "", "", "text-align", "center")
SkinSetValue("myTextWidget", "", "", "vertical-align", "center")
SkinSetValue("myTextWidget", "", "", "transition", "color 0.5s ease-out, font-size 0.5s ease-out")

; Define a "hover" state for the same class with changed text properties
SkinSetValue("myTextWidget", "hover", "", "color", "crimson")
SkinSetValue("myTextWidget", "hover", "", "font-size", "32px")

Procedure DrawTextWidget(Widget, EventType, *EventData.PG_EventDraw, *UserData)
  
  ; Optional: Draw a background so we can see the widget bounds
  DrawBox(0, 0, *EventData\width, *EventData\height, RGB(230, 230, 230))
  DrawBoxStroke(0, 0, *EventData\width, *EventData\height, RGB(180, 180, 180))

  ; Draw the text using the skin definitions of the current state
  DrawSkinText(Widget, "", 0, 0, *EventData\width, *EventData\height, "Hover Me!")

EndProcedure

Procedure MouseTextWidget(Widget, EventType, *EventData.PG_EventMouse, *UserData)
  Select EventType
    Case #PG_Event_MouseEnter
      ; Transition to the 'hover' state (triggers animation)
      WidgetSetSkinState(Widget, "hover")
    Case #PG_Event_MouseLeave
      ; Transition back to the default state (triggers animation)
      WidgetSetSkinState(Widget, "")
  EndSelect
EndProcedure

MyWindow = CreateWindow(0, 0, 400, 200, "DrawSkinText Example")
LayoutSetPadding(#Null, 40)

If MyWindow
  ; Create the widget and assign our custom skin class
  TextWidget = CreateWidget(0, 0, 320, 80)
  WidgetSetClass(TextWidget, "myTextWidget")
  
  ; Attach drawing and mouse interaction event handlers
  AddEventHandler(TextWidget, #PG_Event_Draw, @DrawTextWidget())
  AddEventHandler(TextWidget, #PG_Event_MouseEnter, @MouseTextWidget())
  AddEventHandler(TextWidget, #PG_Event_MouseLeave, @MouseTextWidget())

  WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)

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

StopProGUI()

See Also

DrawSkinBackground, DrawTxt, WidgetGetSkinData, WidgetSetSkinState, SkinSetValue

Supported OS

Windows, Linux