Class: Tuile::Component::List::Cursor::Limited
- Inherits:
-
Cursor
- Object
- Cursor
- Tuile::Component::List::Cursor::Limited
- Defined in:
- lib/tuile/component/list.rb,
sig/tuile.rbs
Overview
Cursor which can only land on specific allowed lines.
Instance Method Summary collapse
-
#candidate_positions(line_count) ⇒ ::Array[Integer]
@param
line_count. -
#go_down_by(lines, line_count) ⇒ Boolean
@param
lines. - #go_to_first ⇒ Boolean
-
#go_to_last(_line_count) ⇒ Boolean
@param
_line_count. -
#go_up_by(lines) ⇒ Boolean
@param
lines. -
#handle_mouse(line, event, _line_count) ⇒ Boolean
@param
line. -
#initialize(positions, position: ) ⇒ Limited
constructor
@param
positions— allowed positions.
Constructor Details
#initialize(positions, position: ) ⇒ Limited
@param positions — allowed positions. Must not be empty.
@param position — initial position.
428 429 430 431 432 433 434 |
# File 'lib/tuile/component/list.rb', line 428 def initialize(positions, position: positions[0]) raise "positions are empty" if positions.empty? @positions = positions.sort position = @positions[@positions.rindex { _1 < position } || 0] unless @positions.include?(position) super(position: position) end |
Instance Method Details
#candidate_positions(line_count) ⇒ ::Array[Integer]
@param line_count
453 454 455 |
# File 'lib/tuile/component/list.rb', line 453 def candidate_positions(line_count) @positions.select { _1 < line_count } end |
#go_down_by(lines, line_count) ⇒ Boolean
@param lines
@param line_count
468 469 470 471 472 473 |
# File 'lib/tuile/component/list.rb', line 468 def go_down_by(lines, line_count) next_pos = @positions.find { _1 >= @position + lines } return go_to_last(line_count) if next_pos.nil? go(next_pos) end |
#go_to_first ⇒ Boolean
485 486 487 |
# File 'lib/tuile/component/list.rb', line 485 def go_to_first go(@positions.first) end |
#go_to_last(_line_count) ⇒ Boolean
@param _line_count
459 460 461 |
# File 'lib/tuile/component/list.rb', line 459 def go_to_last(_line_count) go(@positions.last) end |
#go_up_by(lines) ⇒ Boolean
@param lines
477 478 479 480 481 482 |
# File 'lib/tuile/component/list.rb', line 477 def go_up_by(lines) prev_pos = @positions.reverse_each.find { _1 <= @position - lines } return go_to_first if prev_pos.nil? go(prev_pos) end |
#handle_mouse(line, event, _line_count) ⇒ Boolean
@param line
@param event
@param _line_count
440 441 442 443 444 445 446 447 448 449 |
# File 'lib/tuile/component/list.rb', line 440 def handle_mouse(line, event, _line_count) if event. == :left prev_pos = @positions.reverse_each.find { _1 <= line } return go_to_first if prev_pos.nil? go(prev_pos) else false end end |