class Core::GUI::Textfield
Displays text in the given font and alignment
Attributes
max_width[RW]
Public Class Methods
new(x, y, w, h, txt="", size=20, align=:left, fixed=true, maxw=w)
click to toggle source
Calls superclass method
Core::GUI::Element::new
# File lib/gui/textfield.rb, line 8 def initialize(x, y, w, h, txt="", size=20, align=:left, fixed=true, maxw=w) super(x, y, w, h) @bg = Core.sprite("gui/container_background") @font = Core.font(Core::DEFAULT_FONT, size) @align = align @fixed = fixed @max_width = maxw set_text(txt) end
Public Instance Methods
draw()
click to toggle source
# File lib/gui/textfield.rb, line 35 def draw @bg.draw(@x+@xoff, @y+@yoff, Core::GUI_Z + @zoff, (@w)/@bg.width.to_f, @h/@bg.height.to_f) y = 0 if @text.size == 1 y += 4 end i = 0 @text.each { |line| case @align when :center @font.draw(line, @x + @xoff + (@w/2) - (@fws[i]/2), @y + @yoff + (@font.height/9) + y, Core::GUI_Z + 10 + @zoff, 1, 1, Gosu::Color::BLACK) when :left @font.draw(line, @x + @xoff + 4, @y + @yoff + (@font.height/9) + y, Core::GUI_Z + 10 + @zoff, 1, 1, Gosu::Color::BLACK) when :right @font.draw(line, @x + @xoff + (@w-@fws[i]), @y + @yoff + (@font.height/9) + y, Core::GUI_Z + 10 + @zoff, 1, 1, Gosu::Color::BLACK) end y += @font.height i += 1 } end
text=(text)
click to toggle source
# File lib/gui/textfield.rb, line 18 def text=(text) if !@fixed @w = @max_width end @text = Core.multiline(text, @w, @font) if !@fixed @w = 8 + @font.text_width(@text.sort_by { |line| line.length}.reverse!.first) @h = 8 + @text.size * (@font.height) end @fws = [] @text.each { |line| @fws.push(@font.text_width(line)) } end
Also aliased as: set_text