Class LayoutMode
The layout mode
Inheritance
- Object
- LayoutMode
Declaration
public sealed class LayoutMode : Enum
Fields
Default
The default layout mode, with one line of lookahead
Declaration
public const LayoutMode Default
Field Value
Type | Description |
---|---|
Simple
A fast-and-ugly layout mode. Tells the layout engine not to collapse any line breaks and to ignore all indentation and annotations. The resulting text contains fewer characters than the Default mode, so may be appropriate for machine-readable output in indentation-insensitive contexts.
Declaration
public const LayoutMode Simple
Field Value
Type | Description |
---|---|
Examples
var doc = Doc.Concat(
"abc", Doc.LineBreak,
Doc.Concat("def", Doc.LineBreak, "ghi").Nested()
);
var options = LayoutOptions.Default with
{
LayoutMode = LayoutMode.Simple
};
Console.WriteLine(doc.ToString(options));
// Output:
// abc
// def
// ghi
Smart
A "smart" layout mode, which can produce better layouts than Default under certain circumstances, at the expense of some performance.
The Default layout mode commits to rendering a Document<T> in a certain way if the rest of the current line fits within the page width. In other words, the Default layout mode has up to one line of lookahead.
However, this lookahead strategy can sometimes produce inefficient layouts when rendering Aligned() blocks. If the first line of an aligned block fits within the page width, the default layout mode commits to rendering the whole aligned block indented to the current column, even if that would cause a line later on in the block to overflow.
The Smart layout mode instructs the layout engine to look ahead further than a single line when rendering an aligned block; instead it looks ahead to the first de-indent. This means the smart layout algorithm might take a LineBreakHints preceding an aligned block, if doing so would prevent a line in the aligned block from overflowing.
Declaration
public const LayoutMode Smart
Field Value
Type | Description |
---|---|
Remarks
This layout mode generally performs worse (more backtracking) than the default layout mode, but can produce better layouts for documents featuring Aligned() blocks.
Examples
In this example, the second line of the aligned block causes an overflow in the Default layout mode. However, Smart layout mode decides to take the line break hint on the first line in order to prevent the overflow.
var doc = Doc.LineBreakHint
+ new Doc[] { "aligned block", "containing a long line after the first" }
.Separated(Doc.LineBreak)
.Aligned();
var defaultOptions = LayoutOptions.Default with { PageWidth = new(50) };
Console.WriteLine(("Default layout mode:" + doc).ToString(defaultOptions));
Console.WriteLine();
var smartOptions = defaultOptions with { LayoutMode = LayoutMode.Smart };
Console.WriteLine(("Smart layout mode:" + doc).ToString(smartOptions));
// Output:
// Default layout mode: aligned block
// containing a long line after the first
//
// Smart layout mode:
// aligned block
// containing a long line after the first
value__
Declaration
public int value__
Field Value
Type | Description |
---|---|