API Referenceglobal
Drawclass
To be used inside `Sandbox.UI.Panel.OnDraw` to add custom shapes, textures and text to a panel. These draw calls will be batched together with the panel's CSS-styled content for efficient rendering. public override void OnDraw() { Draw.Rect( new Rect( 0, 0, 100, 100 ), Color.Red, cornerRadius: 8 ); Draw.Text( "Hello", new Rect( 10, 10, 80, 20 ), 14, Color.White ); }
object→Draw
Methods7
Showing 7 methods
public static void Circle(Vector2 center, float radius, Color color)
Draws a filled circle.
| Parameter | Type | Description |
|---|---|---|
| center | Vector2 | Center position in panel-local coordinates. |
| radius | float | Circle radius in pixels. |
| color | Color | Fill color. |
Returns:
void—public static void Outline(Sandbox.Rect rect, Color color, float width, float cornerRadius = 0, float offset = 0)
Draws an outline (stroke) around a rectangle.
| Parameter | Type | Description |
|---|---|---|
| rect | Rect | The rectangle to outline, in panel-local coordinates. |
| color | Color | Outline color. |
| width | float | Outline thickness in pixels. |
| cornerRadius = 0 | float | Corner radius to match rounded rectangles. |
| offset = 0 | float | Outline offset. Positive values push the outline outward, negative values pull it inward. |
Returns:
void—public static void Shadow(Sandbox.Rect rect, Color color, float blur = 0, float spread = 0, Vector2 offset = null, float cornerRadius = 0, bool inset = False)
Draws a box shadow (drop shadow or inset shadow).
| Parameter | Type | Description |
|---|---|---|
| rect | Rect | The rectangle to cast the shadow from, in panel-local coordinates. |
| color | Color | Shadow color. |
| blur = 0 | float | Blur radius in pixels. Higher values produce softer shadows. |
| spread = 0 | float | Spread distance in pixels. Positive values expand the shadow, negative values shrink it. |
| offset = null | Vector2 | Shadow offset from the rectangle position. |
| cornerRadius = 0 | float | Corner radius to match rounded rectangles. |
| inset = False | bool | If true, draws an inner shadow instead of a drop shadow. |
Returns:
void—public static void Text(string text, Sandbox.Rect rect, float size, Color color, Sandbox.TextFlag flags = 33, string font = Roboto)
Draws a text string within the given rectangle.
| Parameter | Type | Description |
|---|---|---|
| text | string | The text to render. |
| rect | Rect | Bounding rectangle for text layout, in panel-local coordinates. |
| size | float | Font size in pixels. |
| color | Color | Text color. |
| flags = 33 | TextFlag | Text alignment and layout flags. Defaults to `Sandbox.TextFlag.LeftTop`. |
| font = Roboto | string | Font family name. Defaults to "Roboto". |
Returns:
void—No results match this filter.