Class: LUIT::TextArea
Instance Attribute Summary collapse
Attributes inherited from LUITElement
#h, #hover, #id, #w, #x, #y
Instance Method Summary
collapse
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
#field ⇒ Object
Returns the value of attribute field.
112
113
114
|
# File 'lib/luit.rb', line 112
def field
@field
end
|
Instance Method Details
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/luit.rb', line 128
def button_down(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 ? 0xffffffff : LUIT.uiColor, LUIT.z)
@font.draw(@field.text, x + 10, y + 10, LUIT.z + 1, 1, 1, 0xff000000)
end
|
#text ⇒ Object
124
125
126
|
# File 'lib/luit.rb', line 124
def text
return @field.text
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::button_down?(Gosu::KbReturn) && @typing
@typing = false
@window.text_input = nil
@holder.onClick(@id)
end
end
|