Class: Tuile::Component::List::Cursor::Limited
- Inherits:
-
Tuile::Component::List::Cursor
- Object
- Tuile::Component::List::Cursor
- Tuile::Component::List::Cursor::Limited
- Defined in:
- lib/tuile/component/list.rb
Overview
Cursor which can only land on specific allowed lines.
Instance Attribute Summary
Attributes inherited from Tuile::Component::List::Cursor
Instance Method Summary collapse
- #candidate_positions(line_count) ⇒ Array<Integer>
- #handle_mouse(line, event, _line_count) ⇒ Boolean
-
#initialize(positions, position: ) ⇒ Limited
constructor
A new instance of Limited.
Methods inherited from Tuile::Component::List::Cursor
Constructor Details
#initialize(positions, position: ) ⇒ Limited
Returns a new instance of Limited.
372 373 374 375 376 |
# File 'lib/tuile/component/list.rb', line 372 def initialize(positions, position: positions[0]) @positions = positions.sort position = @positions[@positions.rindex { it < position } || 0] unless @positions.include?(position) super(position: position) end |
Instance Method Details
#candidate_positions(line_count) ⇒ Array<Integer>
395 396 397 |
# File 'lib/tuile/component/list.rb', line 395 def candidate_positions(line_count) @positions.select { it < line_count } end |
#handle_mouse(line, event, _line_count) ⇒ Boolean
382 383 384 385 386 387 388 389 390 391 |
# File 'lib/tuile/component/list.rb', line 382 def handle_mouse(line, event, _line_count) if event. == :left prev_pos = @positions.reverse_each.find { it <= line } return go_to_first if prev_pos.nil? go(prev_pos) else false end end |