fn compute_rows(&mut self, size: Vec2) {
        let mut content = self.content.lock().unwrap();
        if content.is_cache_valid(size) {
            return;
        }

        // Completely bust the cache
        // Just in case we fail, we don't want to leave a bad cache.
        content.size_cache = None;

        if size.x == 0 {
            // Nothing we can do at this point.
            return;
        }

        // First attempt: naively hope that we won't need a scrollbar_width
        // (This means we try to use the entire available width for text).
        self.rows = LinesIterator::new(&content.content, size.x).collect();

        // Width taken by the scrollbar. Without a scrollbar, it's 0.
        let mut scrollbar_width = 0;

        if self.scrollable && self.rows.len() > size.y {
            // We take 1 column for the bar itself + 1 spacing column
            scrollbar_width = 2;

            // If we're too high, include a scrollbar_width
            let available = match size.x.checked_sub(scrollbar_width) {
                Some(s) => s,
                None => return,
            };

            self.rows =
                LinesIterator::new(&content.content, available).collect();

            if self.rows.is_empty() && !content.content.is_empty() {
                // We have some content, we we didn't find any row for it?
                // This probably means we couldn't even make a single row
                // (for instance we only have 1 column and we have a wide
                // character).
                return;
            }
        }

        // Desired width, including the scrollbar_width.
        self.width = self.rows
            .iter()
            .map(|row| row.width)
            .max()
            .map(|w| w + scrollbar_width);

        // The entire "virtual" size (includes all rows)
        let mut my_size = Vec2::new(self.width.unwrap_or(0), self.rows.len());

        // If we're scrolling, cap the the available size.
        if self.scrollable && my_size.y > size.y {
            my_size.y = size.y;
        }

        // Build a fresh cache.
        content.size_cache = Some(SizeCache::build(my_size, size));
    }
// This must be non-destructive, as it may be called
// multiple times during layout.
This must be non-destructive, as it may be called
multiple times during layout.
This must be non - destructive as it may be called multiple times during layout .
fn compute_rows(&mut self, size: Vec2) {
        let mut content = self.content.lock().unwrap();
        if content.is_cache_valid(size) {
            return;
        }
        // Completely bust the cache
        // Just in case we fail, we don't want to leave a bad cache.
        content.size_cache = None;
        if size.x == 0 {
            // Nothing we can do at this point.
            return;
        }
        // First attempt: naively hope that we won't need a scrollbar_width
        // (This means we try to use the entire available width for text).
        self.rows = LinesIterator::new(&content.content, size.x).collect();
        // Width taken by the scrollbar. Without a scrollbar, it's 0.
        let mut scrollbar_width = 0;
        if self.scrollable && self.rows.len() > size.y {
            // We take 1 column for the bar itself + 1 spacing column
            scrollbar_width = 2;
            // If we're too high, include a scrollbar_width
            let available = match size.x.checked_sub(scrollbar_width) {
                Some(s) => s,
                None => return,
            };
            self.rows =
                LinesIterator::new(&content.content, available).collect();
            if self.rows.is_empty() && !content.content.is_empty() {
                // We have some content, we we didn't find any row for it?
                // This probably means we couldn't even make a single row
                // (for instance we only have 1 column and we have a wide
                // character).
                return;
            }
        }
        // Desired width, including the scrollbar_width.
        self.width = self.rows
            .iter()
            .map(|row| row.width)
            .max()
            .map(|w| w + scrollbar_width);
        // The entire "virtual" size (includes all rows)
        let mut my_size = Vec2::new(self.width.unwrap_or(0), self.rows.len());
        // If we're scrolling, cap the the available size.
        if self.scrollable && my_size.y > size.y {
            my_size.y = size.y;
        }
        // Build a fresh cache.
        content.size_cache = Some(SizeCache::build(my_size, size));
    }
fn compute_rows ( & mut self , size : Vec2 ) { let mut content = self . content . lock ( ) . unwrap ( ) ; if content . is_cache_valid ( size ) { return ; } // Completely bust the cache // Just in case we fail, we don't want to leave a bad cache. content . size_cache = None ; if size . x == 0 { // Nothing we can do at this point. return ; } // First attempt: naively hope that we won't need a scrollbar_width // (This means we try to use the entire available width for text). self . rows = LinesIterator :: new ( & content . content , size . x ) . collect ( ) ; // Width taken by the scrollbar. Without a scrollbar, it's 0. let mut scrollbar_width = 0 ; if self . scrollable && self . rows . len ( ) > size . y { // We take 1 column for the bar itself + 1 spacing column scrollbar_width = 2 ; // If we're too high, include a scrollbar_width let available = match size . x . checked_sub ( scrollbar_width ) { Some ( s ) => s , None => return , } ; self . rows = LinesIterator :: new ( & content . content , available ) . collect ( ) ; if self . rows . is_empty ( ) && ! content . content . is_empty ( ) { // We have some content, we we didn't find any row for it? // This probably means we couldn't even make a single row // (for instance we only have 1 column and we have a wide // character). return ; } } // Desired width, including the scrollbar_width. self . width = self . rows . iter ( ) . map ( | row | row . width ) . max ( ) . map ( | w | w + scrollbar_width ) ; // The entire "virtual" size (includes all rows) let mut my_size = Vec2 :: new ( self . width . unwrap_or ( 0 ) , self . rows . len ( ) ) ; // If we're scrolling, cap the the available size. if self . scrollable && my_size . y > size . y { my_size . y = size . y ; } // Build a fresh cache. content . size_cache = Some ( SizeCache :: build ( my_size , size ) ) ; }
This must be non-destructive, as it may be called
multiple times during layout.
This must be non - destructive as it may be called multiple times during layout .
&mut self
size
Vec2
&mut self
size
Vec2