If you use bounding_box instead of draw_text , you can specify the width of the bounding box for the text. Then, if you center the text, you must specify the exact x coordinate for the middle. (this is the x-position of the window plus half the width)
Say you have a dot at the x-coordinate of 72, and you want to label "hello world!". therefore, the center of the word is the same x-coordinate. You do not know how widespread the word "hello" is, but you are sure that it will be placed in a box with a width of 500.
72 - (500/2) = -178
bounding_box([-178, 100], :width => 500) do text "hello world!", align => :center end
source share