Class: LUIT::TextArea
- Inherits:
-
LUITElement
- Object
- LUITElement
- LUIT::TextArea
- Defined in:
- lib/luit.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Attributes inherited from LUITElement
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #draw(x = 0, y = 0) ⇒ Object
-
#initialize(holder, id, x, y, maxChar, h) ⇒ TextArea
constructor
A new instance of TextArea.
- #update(x = 0, y = 0) ⇒ Object
Methods inherited from LUITElement
#draw_rel, #updateHover, #update_rel
Constructor Details
#initialize(holder, id, x, y, maxChar, h) ⇒ TextArea
Returns a new instance of TextArea.
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/luit.rb', line 113 def initialize(holder, id, x, y, maxChar, h) h = [10, h].max @font = Gosu::Font.new(h) w = @font.text_width("W" * maxChar) + 20 @maxChar = maxChar super(holder, id, x, y, w, h + 20) @typing = false @field = Gosu::TextInput.new @window = LUIT.window end |
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
112 113 114 |
# File 'lib/luit.rb', line 112 def text @text end |
Instance Method Details
#button_down(id) ⇒ Object
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/luit.rb', line 128 def (id) if @hover @typing = true else if @typing @typing = false @holder.onClick(@id) end end end |
#draw(x = 0, y = 0) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/luit.rb', line 139 def draw(x = 0, y = 0) x = x + @x y = y + @y Gosu::draw_rect(x, y, @w, @h, @typing ? 0xff_ffffff : LUIT.uiColor, LUIT.z) @font.draw(@field.text, x + 10, y + 10, LUIT.z + 1, 1, 1, 0xff000000) end |
#update(x = 0, y = 0) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/luit.rb', line 146 def update(x = 0, y = 0) super x += @x y += @y updateHover(x, y) if @field.text.size > @maxChar @field.text = @field.text[0..@maxChar] end if @typing @window.text_input = @field elsif @window.text_input == @field @window.text_input = nil end if Gosu::(Gosu::KbReturn) && @typing @typing = false @window.text_input = nil @holder.onClick(@id) end end |