Skip to main content

grp

Function grp 

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

Wraps a layout to control group breaking behavior.

The grp constructor creates a group where all breakable elements within the group either break together or stay together. This is essential for maintaining consistent formatting in structures like argument lists, array elements, or object properties.

§Parameters

  • layout - The layout to treat as a breaking group

§Returns

A boxed Layout::Grp that controls group breaking behavior.

§Examples

use typeset::*;

// Group function arguments - they break together or not at all
let args = grp(join_with_commas(vec![
    text_str("arg1"),
    text_str("arg2"),
    text_str("arg3")
]));

let func_call = comp(
    text_str("function"),
    parens(args),
    false, false
);

// With enough width: "function(arg1, arg2, arg3)"
// When narrow, all arguments break:
// function(
//   arg1,
//   arg2,
//   arg3
// )

§Behavior

  • All compositions within the group make breaking decisions together
  • Prevents partial breaking that could result in inconsistent formatting
  • Essential for maintaining visual consistency in structured data

§See Also

  • seq - For sequential breaking where one break forces all breaks
  • fix - For preventing any breaking
  • nest - For adding indentation to broken groups