class Gosu::Font

Add a measure to return both width and height for a text and a way to centre a piece of text in a rectangle.

Public Instance Methods

centered_in(text, rect)

Synonym for centred_in, allowing for centre to be spelled center.

  • text [String] String to centre

  • rect [Size] Rectangular area size

Alias for: centred_in
centred_in(text, rect) click to toggle source

Return the co-ordnates needed to place a given string in the centre of an area, both vertically and horizontally.

  • text [String] String to centre

  • rect [Size] Rectangular area size

return
Point

The point to write the string, expressed as an offset

from the top-left corner of the rectangle.

# File lib/gosu_enhanced/enhanced.rb, line 67
def centred_in(text, rect)
  size = measure(text)

  Point((rect.width - size.width) / 2, (rect.height - size.height) / 2)
end
Also aliased as: centered_in
measure(text) click to toggle source

Return the width and height of a given string

  • text String to measure

return
Size

The height and width of the string.

# File lib/gosu_enhanced/enhanced.rb, line 54
def measure(text)
  Size.new(text_width(text, 1), height)
end