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.
418 419 420 421 422 |
# File 'lib/tuile/component/list.rb', line 418 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>
441 442 443 |
# File 'lib/tuile/component/list.rb', line 441 def candidate_positions(line_count) @positions.select { it < line_count } end |
#handle_mouse(line, event, _line_count) ⇒ Boolean
428 429 430 431 432 433 434 435 436 437 |
# File 'lib/tuile/component/list.rb', line 428 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 |