[haiku-3rdparty-dev] Re: Know size of DrawString?

  • From: Rene Gollent <anevilyak@xxxxxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Tue, 15 Nov 2011 08:07:34 -0500

On Tue, Nov 15, 2011 at 7:45 AM, hey68 you <hey68you@xxxxxxxxx> wrote:
> The string contents will change and I need to adjust the size of the BView
> based on the new string size.

You want StringWidth(text) . It returns a float giving you the width
of the string
in the current font.

> While we're at it, what about a way to center-align the drawn string within
> the BView?

That's quite easy though, given the above width calculation:
float stringWidth = StringWidth(yourtext);
DrawString(yourtext, BPoint((Bounds().Width() - stringWidth) / 2.0, 5.0));



Other related posts: