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

        let scale = Scale::uniform(text_size);

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

            if c.is_control() {
                if c == '\n' {
                    caret.x = 0.0;
                }
                // 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;

            if caret.x > max_x { max_x = caret.x } 
        }

        max_x
    }
/// Calculates the width in pixels of the given string if it where to be rendered at the given
/// size. This takes newlines into acount. 
Calculates the width in pixels of the given string if it where to be rendered at the given
size. This takes newlines into acount.
Calculates the width in pixels of the given string if it where to be rendered at the given size . This takes newlines into acount .
pub fn width(&self, text: &str, text_size: f32) -> f32 {
        let mut prev_glyph: Option<GlyphId> = None; 
        let mut caret = Vec2::ZERO;
        let mut max_x = 0.0;
        let scale = Scale::uniform(text_size);
        for c in text.chars() {
            let glyph = if let Some(glyph) = self.font.glyph(c) {
                glyph
            } else {
                continue;
            }; 
            if c.is_control() {
                if c == '\n' {
                    caret.x = 0.0;
                }
                // 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;
            if caret.x > max_x { max_x = caret.x } 
        }
        max_x
    }
pub fn width ( & self , text : & str , text_size : f32 ) -> f32 { let mut prev_glyph : Option < GlyphId > = None ; let mut caret = Vec2 :: ZERO ; let mut max_x = 0.0 ; let scale = Scale :: uniform ( text_size ) ; for c in text . chars ( ) { let glyph = if let Some ( glyph ) = self . font . glyph ( c ) { glyph } else { continue ; } ; if c . is_control ( ) { if c == '\n' { caret . x = 0.0 ; } // 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 ; if caret . x > max_x { max_x = caret . x } } max_x }
Calculates the width in pixels of the given string if it where to be rendered at the given
size.
Calculates the width in pixels of the given string if it where to be rendered at the given size .
&self
text
&str
text_size
f32
&self
text
&str
text_size
f32