Libgdx font size -


is formula calculate font size given ascent height? , same specific width of text? want draw string on screen specific height , width.

here code fit given width, if text long, label scale fit given width

public class mylabel extends label {  private float customscale = 1; //default scale if text's width < givenwidth private glyphlayout layout; private boolean iswrap; //if wrap, ignore fit private float defaultwidth; protected boolean autofit = false; //set true auto fit when text changed  @override public void draw(batch batch, float parentalpha) {     //draw background     if(background != null)         batch.draw(background, getx(), gety(), getoriginx(), getoriginy(), getwidth(), getheight(), getscalex(), getscaley(), getrotation());     else if(background9patch != null){         background9patch.draw(batch, getx(), gety(), getoriginx(), getoriginy(), getwidth(), getheight(), getscalex(), getscaley(), getrotation());     }     //draw text     super.draw(batch, parentalpha); }  @override public void settext(charsequence newtext) {     super.settext(newtext);     if(autofit){         float prefwidth = getprefwidth();         if(defaultwidth == 0 && getwidth() == 0){             setwidth(prefwidth);         } else {             if (layout != null && !iswrap)                 if (getwidth() > 0) {                     getstyle().font.getdata().setscale(customscale);                     layout.settext(getbitmapfontcache().getfont(), newtext);                     float textwidth = layout.width;                     if (textwidth > getwidth())                         setfontscale((getwidth() / textwidth));                     else                         setfontscale(customscale);                 }         }     } } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -