static Rect DrawText( Sandbox.Rect& position, string text, Color color, string fontFamily, float fontSize, float fontWeight, TextFlag flags )
static Rect DrawText( Sandbox.Rect& position, Sandbox.TextRendering/Scope& scope, TextFlag flags )
static Rect DrawText( Vector2& position, string text, Color color, string fontFamily, float fontSize, float fontWeight )

robot_2Generated
code_blocksInput

Description

The DrawText method in the Sandbox.Graphics class is used to render text onto the screen. This method allows you to specify the position, text content, color, font family, font size, font weight, and additional text rendering flags. It returns a Rect that represents the area occupied by the drawn text.

Usage

To use the DrawText method, you need to provide the following parameters:

  • position: A reference to a Rect that specifies the position and size of the text area.
  • text: A string containing the text to be rendered.
  • color: A Color object that defines the color of the text.
  • fontFamily: A string specifying the font family to be used.
  • fontSize: A float indicating the size of the font.
  • fontWeight: A float representing the weight of the font.
  • flags: A TextFlag enumeration value that specifies additional text rendering options.

The method will modify the position parameter to reflect the actual size and position of the rendered text.

Example

// Example usage of the DrawText method
Rect textPosition = new Rect(10, 10, 200, 50);
string textContent = "Hello, Sandbox!";
Color textColor = Color.White;
string fontFamily = "Arial";
float fontSize = 16.0f;
float fontWeight = 400.0f; // Normal weight
TextFlag textFlags = TextFlag.Left | TextFlag.Top;

Rect resultRect = Graphics.DrawText(ref textPosition, textContent, textColor, fontFamily, fontSize, fontWeight, textFlags);

// The resultRect now contains the actual size and position of the rendered text.