Class: Input::Line
- Inherits:
-
Object
- Object
- Input::Line
- Defined in:
- mygame/lib/sprite_kit/vendor/input.rb
Instance Attribute Summary collapse
-
#clean_text ⇒ Object
readonly
Returns the value of attribute clean_text.
-
#end ⇒ Object
readonly
Returns the value of attribute end.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#new_line ⇒ Object
readonly
Returns the value of attribute new_line.
-
#number ⇒ Object
Returns the value of attribute number.
-
#start ⇒ Object
Returns the value of attribute start.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#wrapped ⇒ Object
readonly
Returns the value of attribute wrapped.
Instance Method Summary collapse
- #index_at(x) ⇒ Object
-
#initialize(number, start, text, wrapped, font_style) ⇒ Line
constructor
A new instance of Line.
- #inspect ⇒ Object
- #measure_to(index) ⇒ Object
- #new_line? ⇒ Boolean
- #to_s ⇒ Object
- #wrapped? ⇒ Boolean
Constructor Details
#initialize(number, start, text, wrapped, font_style) ⇒ Line
Returns a new instance of Line.
217 218 219 220 221 222 223 224 225 226 227 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 217 def initialize(number, start, text, wrapped, font_style) @number = number @start = start @text = text @clean_text = text.delete_prefix("\n") @length = text.length @end = start + @length @wrapped = wrapped @new_line = text[0] == "\n" @font_style = font_style end |
Instance Attribute Details
#clean_text ⇒ Object (readonly)
Returns the value of attribute clean_text.
214 215 216 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 214 def clean_text @clean_text end |
#end ⇒ Object (readonly)
Returns the value of attribute end.
214 215 216 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 214 def end @end end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
214 215 216 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 214 def length @length end |
#new_line ⇒ Object (readonly)
Returns the value of attribute new_line.
214 215 216 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 214 def new_line @new_line end |
#number ⇒ Object
Returns the value of attribute number.
215 216 217 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 215 def number @number end |
#start ⇒ Object
Returns the value of attribute start.
214 215 216 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 214 def start @start end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
214 215 216 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 214 def text @text end |
#wrapped ⇒ Object (readonly)
Returns the value of attribute wrapped.
214 215 216 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 214 def wrapped @wrapped end |
Instance Method Details
#index_at(x) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 258 def index_at(x) return @start if x <= 0 index = -1 width = 0 while (index += 1) < length char = @text[index, 1] char_w = char == "\n" ? 0 : @font_style.string_width(char) # TODO: Test `index_at` with multiple different fonts char_mid = char_w / 4 return index + @start if width + char_mid > x return index + 1 + @start if width + char_mid > x width += char_w end index + @start end |
#inspect ⇒ Object
246 247 248 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 246 def inspect "<Line##{@number} #{@start},#{@length} #{@text.gsub("\n", '\n')[0, 200]} #{@wrapped ? '\r' : '\n'}>" end |
#measure_to(index) ⇒ Object
250 251 252 253 254 255 256 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 250 def measure_to(index) if @text[0] == "\n" index < 1 ? 0 : @font_style.string_width(@text[1, index - 1].to_s) else @font_style.string_width(@text[0, index].to_s) end end |
#new_line? ⇒ Boolean
238 239 240 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 238 def new_line? @new_line end |
#to_s ⇒ Object
242 243 244 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 242 def to_s @text end |
#wrapped? ⇒ Boolean
234 235 236 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 234 def wrapped? @wrapped end |