# Sandbox.Painter.MeasureText

## Overload 1

```csharp
Vector2 MeasureText(string text, Vector2 maxSize = null)
```

Measures text with the current TextStyle, including glyph overhang, in the same coordinates as Painter.Text.
maxSize supplies the same layout bounds as a drawing rectangle; default uses Painter.Text's unconstrained bounds.
The result includes ScaleToScreen but excludes Painter.Transform, clipping and opacity. Empty text returns zero.
Prepares cached layout without recording a draw or allocating a bitmap or GPU texture. A later draw reuses the layout.

### Parameters

- `text` (`string`)
- `maxSize` (`Vector2`), default `null`

### Returns

`Vector2`

## Overload 2

```csharp
Rect MeasureText(string text, Rect rect)
```

Returns the aligned, pixel-rounded rectangle that Painter.Text(text, rect) will use with the current TextStyle.
Measures before Painter.Transform or clipping. Empty text produces an empty rectangle at rect.Position.

### Parameters

- `text` (`string`)
- `rect` (`Rect`)

### Returns

`Rect`

Declared in [Sandbox.Painter](/api/Sandbox.Painter).
Assembly: `Sandbox.Engine`.
