pub fn dimensions(&self, text: &str, text_size: f32, wrap_width: Option<f32>) -> (Vec2<f32>, f32) {
        let mut prev_glyph: Option<GlyphId> = None; 
        let mut first_line = true;
        let mut first_ascent = 0.0;
        let mut caret = Vec2::ZERO;
        let mut max_x = 0.0;

        let scale = Scale::uniform(text_size);
        let v_metrics = self.font.v_metrics(scale);
        let vertical_advance = v_metrics.ascent - v_metrics.descent + v_metrics.line_gap; 

        for c in text.chars() {
            let glyph = if let Some(glyph) = self.font.glyph(c) {
                glyph
            } else {
                continue;
            };

            // Move to new line
            if c.is_control() {
                if c == '\n' {
                    first_line = false;
                    max_x = f32::max(max_x, caret.x);
                    caret.x = 0.0;
                    caret.y += vertical_advance;
                    prev_glyph = None; //No kerning after newline
                }
                // Align to next tab stop
                if c == '\t' {
                    let tab_width = TAB_WIDTH*text_size;
                    caret.x /= tab_width;
                    caret.x = (caret.x + 1.0).round();
                    caret.x *= tab_width;
                }
                continue;
            }

            // Apply kerning
            if let Some(prev) = prev_glyph.take() {
                caret.x += self.font.pair_kerning(scale, prev, glyph.id());
            }
            prev_glyph = Some(glyph.id());

            let glyph = glyph.scaled(scale);
            caret.x += glyph.h_metrics().advance_width;

            // Wrap if line is to long
            if let Some(width) = wrap_width {
                if caret.x > width {
                    max_x = f32::max(max_x, caret.x);
                    caret.x = 0.0;
                    caret.y += vertical_advance;
                    prev_glyph = None;
                }
            }

            if first_line {
                if let Some(bounding) = glyph.exact_bounding_box() {
                    first_ascent = f32::max(first_ascent, -bounding.min.y);
                }
            }
        }

        max_x = f32::max(max_x, caret.x);
        if let Some(width) = wrap_width {
            max_x = f32::min(max_x, width);
        }

        (Vec2::new(max_x, caret.y + first_ascent), first_ascent)
    }
/// Calculates the dimensions, in pixels, of the given string if it where to be rendered at the
/// given size. This takes newlines into acount. 
/// Returns the size of the string, in addition to the ascent of the first line. If the text is
/// offset downwards by this amount the top of the text will be at the previous baseline.
Calculates the dimensions, in pixels, of the given string if it where to be rendered at the
given size. This takes newlines into acount.
Returns the size of the string, in addition to the ascent of the first line. If the text is
offset downwards by this amount the top of the text will be at the previous baseline.
Calculates the dimensions in pixels of the given string if it where to be rendered at the given size . This takes newlines into acount . Returns the size of the string in addition to the ascent of the first line . If the text is offset downwards by this amount the top of the text will be at the previous baseline .
pub fn dimensions(&self, text: &str, text_size: f32, wrap_width: Option<f32>) -> (Vec2<f32>, f32) {
        let mut prev_glyph: Option<GlyphId> = None; 
        let mut first_line = true;
        let mut first_ascent = 0.0;
        let mut caret = Vec2::ZERO;
        let mut max_x = 0.0;
        let scale = Scale::uniform(text_size);
        let v_metrics = self.font.v_metrics(scale);
        let vertical_advance = v_metrics.ascent - v_metrics.descent + v_metrics.line_gap; 
        for c in text.chars() {
            let glyph = if let Some(glyph) = self.font.glyph(c) {
                glyph
            } else {
                continue;
            };
            // Move to new line
            if c.is_control() {
                if c == '\n' {
                    first_line = false;
                    max_x = f32::max(max_x, caret.x);
                    caret.x = 0.0;
                    caret.y += vertical_advance;
                    prev_glyph = None; //No kerning after newline
                }
                // Align to next tab stop
                if c == '\t' {
                    let tab_width = TAB_WIDTH*text_size;
                    caret.x /= tab_width;
                    caret.x = (caret.x + 1.0).round();
                    caret.x *= tab_width;
                }
                continue;
            }
            // Apply kerning
            if let Some(prev) = prev_glyph.take() {
                caret.x += self.font.pair_kerning(scale, prev, glyph.id());
            }
            prev_glyph = Some(glyph.id());
            let glyph = glyph.scaled(scale);
            caret.x += glyph.h_metrics().advance_width;
            // Wrap if line is to long
            if let Some(width) = wrap_width {
                if caret.x > width {
                    max_x = f32::max(max_x, caret.x);
                    caret.x = 0.0;
                    caret.y += vertical_advance;
                    prev_glyph = None;
                }
            }
            if first_line {
                if let Some(bounding) = glyph.exact_bounding_box() {
                    first_ascent = f32::max(first_ascent, -bounding.min.y);
                }
            }
        }
        max_x = f32::max(max_x, caret.x);
        if let Some(width) = wrap_width {
            max_x = f32::min(max_x, width);
        }
        (Vec2::new(max_x, caret.y + first_ascent), first_ascent)
    }
pub fn dimensions ( & self , text : & str , text_size : f32 , wrap_width : Option < f32 > ) -> ( Vec2 < f32 > , f32 ) { let mut prev_glyph : Option < GlyphId > = None ; let mut first_line = true ; let mut first_ascent = 0.0 ; let mut caret = Vec2 :: ZERO ; let mut max_x = 0.0 ; let scale = Scale :: uniform ( text_size ) ; let v_metrics = self . font . v_metrics ( scale ) ; let vertical_advance = v_metrics . ascent - v_metrics . descent + v_metrics . line_gap ; for c in text . chars ( ) { let glyph = if let Some ( glyph ) = self . font . glyph ( c ) { glyph } else { continue ; } ; // Move to new line if c . is_control ( ) { if c == '\n' { first_line = false ; max_x = f32 :: max ( max_x , caret . x ) ; caret . x = 0.0 ; caret . y += vertical_advance ; prev_glyph = None ; //No kerning after newline } // Align to next tab stop if c == '\t' { let tab_width = TAB_WIDTH * text_size ; caret . x /= tab_width ; caret . x = ( caret . x + 1.0 ) . round ( ) ; caret . x *= tab_width ; } continue ; } // Apply kerning if let Some ( prev ) = prev_glyph . take ( ) { caret . x += self . font . pair_kerning ( scale , prev , glyph . id ( ) ) ; } prev_glyph = Some ( glyph . id ( ) ) ; let glyph = glyph . scaled ( scale ) ; caret . x += glyph . h_metrics ( ) . advance_width ; // Wrap if line is to long if let Some ( width ) = wrap_width { if caret . x > width { max_x = f32 :: max ( max_x , caret . x ) ; caret . x = 0.0 ; caret . y += vertical_advance ; prev_glyph = None ; } } if first_line { if let Some ( bounding ) = glyph . exact_bounding_box ( ) { first_ascent = f32 :: max ( first_ascent , - bounding . min . y ) ; } } } max_x = f32 :: max ( max_x , caret . x ) ; if let Some ( width ) = wrap_width { max_x = f32 :: min ( max_x , width ) ; } ( Vec2 :: new ( max_x , caret . y + first_ascent ) , first_ascent ) }
Calculates the dimensions, in pixels, of the given string if it where to be rendered at the
given size.
Calculates the dimensions in pixels of the given string if it where to be rendered at the given size .
&self
text
&str
text_size
f32
wrap_width
Option<f32>
&self
text
&str
text_size
f32
wrap_width
Option<f32>