Skip to main content

fix

Function fix 

Source
pub fn fix(layout: Box<Layout>) -> Box<Layout>
Expand description

Wraps a layout to prevent it from breaking across lines.

The fix constructor treats its content as a fixed unit that must appear on a single line. This is useful for preserving the structure of code elements that should never be broken, such as operators, keywords, or small expressions.

§Parameters

  • layout - The layout to treat as fixed

§Returns

A boxed Layout::Fix that prevents line breaking within the wrapped layout.

§Examples

use typeset::*;

// Ensure an operator stays on one line
let operator = fix(text_str(" -> "));

// Fix can prevent breaking of compound expressions
let expr = fix(comp(
    text_str("a"),
    comp(text_str(" + "), text_str("b"), false, false),
    false, false
));

// The expression will always render as "a + b" on one line
assert_eq!(format_layout(expr, 2, 10), "a + b");

§Behavior

  • Fixed layouts never break, regardless of width constraints
  • Use sparingly - over-fixing can create layouts that exceed line width
  • Compositions marked with fix=true behave similarly

§See Also

  • grp - For layouts that break together as a group
  • [comp] - The fix parameter controls breaking behavior
  • [fix_pad], [fix_unpad] - Composition shortcuts with fixing