pub fn wrap(&mut self, text_id: TextId, max_width: f32) -> (f32, f32) {
        let layout = &mut self.layouts[text_id];

        if layout.single_line_width == 0. {
            return (0., 0.)
        }

        if layout.break_hints.is_empty() {
            return (layout.single_line_width, layout.line_height)
        }

        // TODO: skip if no work is needed

        // TODO: stretch calls measure multiple times, which is not what we expect
        // first time it's with real value but second and third time it's unconstrained

        let mut width = 0.;
        let mut offset = 0.;
        layout.breaks.clear();

        // go through hints, make a break each time it overflows
        for (i, xend) in &layout.break_hints {
            if (xend - offset) > max_width {
                let line_width = layout.xs[*i] - offset;

                if line_width > width {
                    width = line_width;
                }

                layout.breaks.push(*i);
                offset = layout.xs[*i];
            }
        }

        if layout.breaks.len() == 0 {
            return (layout.single_line_width, layout.line_height)
        }

        (width, (layout.breaks.len() + 1) as f32 * layout.line_height)
    }
/// Wrap/reflow existing text layout to a new max_width
/// and report a new size
///
/// Expected to be called during measure.
/// If the `Text` is changed & relayouted, wrapping is reset but
/// the box layout should again call measure which should again
/// call the `wrap` so it should be fine (if the wrap is necessary at all)
Wrap/reflow existing text layout to a new max_width
and report a new size

Expected to be called during measure.
If the `Text` is changed & relayouted, wrapping is reset but
the box layout should again call measure which should again
call the `wrap` so it should be fine (if the wrap is necessary at all)
Wrap / reflow existing text layout to a new max_width and report a new size Expected to be called during measure . If the ` Text ` is changed & relayouted wrapping is reset but the box layout should again call measure which should again call the ` wrap ` so it should be fine ( if the wrap is necessary at all )
pub fn wrap(&mut self, text_id: TextId, max_width: f32) -> (f32, f32) {
        let layout = &mut self.layouts[text_id];
        if layout.single_line_width == 0. {
            return (0., 0.)
        }
        if layout.break_hints.is_empty() {
            return (layout.single_line_width, layout.line_height)
        }
        // TODO: skip if no work is needed
        // TODO: stretch calls measure multiple times, which is not what we expect
        // first time it's with real value but second and third time it's unconstrained
        let mut width = 0.;
        let mut offset = 0.;
        layout.breaks.clear();
        // go through hints, make a break each time it overflows
        for (i, xend) in &layout.break_hints {
            if (xend - offset) > max_width {
                let line_width = layout.xs[*i] - offset;
                if line_width > width {
                    width = line_width;
                }
                layout.breaks.push(*i);
                offset = layout.xs[*i];
            }
        }
        if layout.breaks.len() == 0 {
            return (layout.single_line_width, layout.line_height)
        }
        (width, (layout.breaks.len() + 1) as f32 * layout.line_height)
    }
pub fn wrap ( & mut self , text_id : TextId , max_width : f32 ) -> ( f32 , f32 ) { let layout = & mut self . layouts [ text_id ] ; if layout . single_line_width == 0. { return ( 0. , 0. ) } if layout . break_hints . is_empty ( ) { return ( layout . single_line_width , layout . line_height ) } // TODO: skip if no work is needed // TODO: stretch calls measure multiple times, which is not what we expect // first time it's with real value but second and third time it's unconstrained let mut width = 0. ; let mut offset = 0. ; layout . breaks . clear ( ) ; // go through hints, make a break each time it overflows for ( i , xend ) in & layout . break_hints { if ( xend - offset ) > max_width { let line_width = layout . xs [ * i ] - offset ; if line_width > width { width = line_width ; } layout . breaks . push ( * i ) ; offset = layout . xs [ * i ] ; } } if layout . breaks . len ( ) == 0 { return ( layout . single_line_width , layout . line_height ) } ( width , ( layout . breaks . len ( ) + 1 ) as f32 * layout . line_height ) }
Wrap/reflow existing text layout to a new max_width
and report a new size
Wrap / reflow existing text layout to a new max_width and report a new size
&mut self
text_id
TextId
max_width
f32
&mut self
text_id
TextId
max_width
f32