Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Centering text in a rectange
Re: Centering text in a rectange [message #35341 is a reply to message #35340] Fri, 03 February 2012 17:21 Go to previous messageGo to previous message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

This is how I would do it. The gurus out here might have simpler ways to achieve the same

1- Get size of text to be displayed. You will use the GetTextSize() function to achieve this

2- Get the size of the rectangle using GetSize()

3- X position centered text will start at
PosX = (Rect_X_extent-Text_x_extent)/2
PosY = (Rect_Y_extent-Text_Y_extent)/2

4- put the text there.

You might need to consider rotation of text differently.

Maybe there are utility functions that achieve the same, but, I do not know as I'm a relative newbie
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to use the same .iml from multiple source files.
Next Topic: Bug: Missing width in DrawArc on X11
Goto Forum:
  


Current Time: Sun Apr 28 12:40:33 CEST 2024

Total time taken to generate the page: 0.02127 seconds