pub fn rebuild_if_needed(&mut self, factory: &mut PietText, env: &Env) {
        if let Some(text) = &self.text {
            if self.layout.is_none() {
                let font = self.font.resolve(env);
                let color = self.text_color.resolve(env);
                let size_override = self.text_size_override.as_ref().map(|key| key.resolve(env));

                let descriptor = if let Some(size) = size_override {
                    font.with_size(size)
                } else {
                    font
                };

                let builder = factory
                    .new_text_layout(text.clone())
                    .max_width(self.wrap_width)
                    .alignment(self.alignment)
                    .font(descriptor.family.clone(), descriptor.size)
                    .default_attribute(descriptor.weight)
                    .default_attribute(descriptor.style)
                    .default_attribute(TextAttribute::TextColor(color));
                let layout = text.add_attributes(builder, env).build().unwrap();

                self.links = text
                    .links()
                    .iter()
                    .enumerate()
                    .flat_map(|(i, link)| {
                        layout
                            .rects_for_range(link.range())
                            .into_iter()
                            .map(move |rect| (rect, i))
                    })
                    .collect();

                self.layout = Some(layout);
            }
        }
    }
/// Rebuild the inner layout as needed.
///
/// This `TextLayout` object manages a lower-level layout object that may
/// need to be rebuilt in response to changes to the text or attributes
/// like the font.
///
/// This method should be called whenever any of these things may have changed.
/// A simple way to ensure this is correct is to always call this method
/// as part of your widget's [`layout`] method.
///
/// [`layout`]: trait.Widget.html#method.layout
Rebuild the inner layout as needed.
This `TextLayout` object manages a lower-level layout object that may
need to be rebuilt in response to changes to the text or attributes
like the font.

This method should be called whenever any of these things may have changed.
A simple way to ensure this is correct is to always call this method
as part of your widget's [`layout`] method.


Rebuild the inner layout as needed . This ` TextLayout ` object manages a lower - level layout object that may need to be rebuilt in response to changes to the text or attributes like the font . This method should be called whenever any of these things may have changed . A simple way to ensure this is correct is to always call this method as part of your widget ' s [ ` layout ` ] method .
pub fn rebuild_if_needed(&mut self, factory: &mut PietText, env: &Env) {
        if let Some(text) = &self.text {
            if self.layout.is_none() {
                let font = self.font.resolve(env);
                let color = self.text_color.resolve(env);
                let size_override = self.text_size_override.as_ref().map(|key| key.resolve(env));
                let descriptor = if let Some(size) = size_override {
                    font.with_size(size)
                } else {
                    font
                };
                let builder = factory
                    .new_text_layout(text.clone())
                    .max_width(self.wrap_width)
                    .alignment(self.alignment)
                    .font(descriptor.family.clone(), descriptor.size)
                    .default_attribute(descriptor.weight)
                    .default_attribute(descriptor.style)
                    .default_attribute(TextAttribute::TextColor(color));
                let layout = text.add_attributes(builder, env).build().unwrap();
                self.links = text
                    .links()
                    .iter()
                    .enumerate()
                    .flat_map(|(i, link)| {
                        layout
                            .rects_for_range(link.range())
                            .into_iter()
                            .map(move |rect| (rect, i))
                    })
                    .collect();
                self.layout = Some(layout);
            }
        }
    }
pub fn rebuild_if_needed ( & mut self , factory : & mut PietText , env : & Env ) { if let Some ( text ) = & self . text { if self . layout . is_none ( ) { let font = self . font . resolve ( env ) ; let color = self . text_color . resolve ( env ) ; let size_override = self . text_size_override . as_ref ( ) . map ( | key | key . resolve ( env ) ) ; let descriptor = if let Some ( size ) = size_override { font . with_size ( size ) } else { font } ; let builder = factory . new_text_layout ( text . clone ( ) ) . max_width ( self . wrap_width ) . alignment ( self . alignment ) . font ( descriptor . family . clone ( ) , descriptor . size ) . default_attribute ( descriptor . weight ) . default_attribute ( descriptor . style ) . default_attribute ( TextAttribute :: TextColor ( color ) ) ; let layout = text . add_attributes ( builder , env ) . build ( ) . unwrap ( ) ; self . links = text . links ( ) . iter ( ) . enumerate ( ) . flat_map ( | ( i , link ) | { layout . rects_for_range ( link . range ( ) ) . into_iter ( ) . map ( move | rect | ( rect , i ) ) } ) . collect ( ) ; self . layout = Some ( layout ) ; } } }
Rebuild the inner layout as needed.
Rebuild the inner layout as needed .
&mut self
factory
&mut PietText
env
&Env
&mut self
factory
&mut PietText
env
&Env