Align
IAlign wraps a single child and positions it left / centre / right within the available width. Useful for centring a panel, justifying a markup label, or forcing a child to sit on the right edge.
When to use
- Centring a fixed-width widget (logo, panel, calendar) in the middle of the terminal.
- Right-aligning a status line or footer.
For per-line text alignment, Markup and Paragraph carry their own WithAlignment setters; reach for Align only when you want to position a whole widget horizontally.
Basic usage
pascal
AnsiConsole.Write(
Widgets.Align(Widgets.Markup('[bold]centered[/]'), TAlignment.Center));
AnsiConsole.Write(
Widgets.Align(Widgets.Markup('[italic]right[/]'), TAlignment.Right));1
2
3
4
5
2
3
4
5
In a wider container the difference becomes obvious - the left edge of the child moves accordingly.
Configuration
| Method | Purpose |
|---|---|
WithAlignment(value) | Change horizontal alignment — TAlignment.Left / Center / Right. |
WithVerticalAlignment(value) | Vertical positioning when the parent has slack — TVerticalAlignment.Top / Middle / Bottom. |
pascal
AnsiConsole.Write(
Widgets.Align(panel, TAlignment.Center)
.WithVerticalAlignment(TVerticalAlignment.Middle));1
2
3
2
3