Description
The Pre
field of the WhiteSpace
enum in the Sandbox.UI
namespace specifies that sequences of white space characters are preserved, and lines are only broken at newline characters in the source. This behavior is similar to the CSS white-space: pre;
property, where text is displayed exactly as it is written in the source code, including spaces and line breaks.
Usage
Use WhiteSpace.Pre
when you want to maintain the exact formatting of text as it appears in the source, including all spaces and line breaks. This is useful for displaying preformatted text, such as code snippets or poetry, where the original formatting is important.
Example
// Example of using WhiteSpace.Pre in a UI component
var textComponent = new TextComponent();
textComponent.WhiteSpace = WhiteSpace.Pre;
textComponent.Text = "This is a\npreformatted\ntext block.";
// The text will be displayed with line breaks and spaces preserved as in the source.