Class: Charming::Components::Viewport::Position
- Inherits:
-
Object
- Object
- Charming::Components::Viewport::Position
- Defined in:
- lib/charming/presentation/components/viewport/position.rb
Overview
Position owns the viewport’s mutable row and column offsets.
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
Instance Method Summary collapse
- #clamp(bounds) ⇒ Object
- #end_at(bounds) ⇒ Object
- #home ⇒ Object
-
#initialize(offset:, column:) ⇒ Position
constructor
A new instance of Position.
- #move_to(row, bounds) ⇒ Object
- #page_down(page_size, bounds) ⇒ Object
- #page_up(page_size, bounds) ⇒ Object
- #scroll_down(bounds) ⇒ Object
- #scroll_left(bounds) ⇒ Object
- #scroll_right(bounds) ⇒ Object
- #scroll_up(bounds) ⇒ Object
Constructor Details
#initialize(offset:, column:) ⇒ Position
Returns a new instance of Position.
10 11 12 13 |
# File 'lib/charming/presentation/components/viewport/position.rb', line 10 def initialize(offset:, column:) @offset = offset @column = column end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
8 9 10 |
# File 'lib/charming/presentation/components/viewport/position.rb', line 8 def column @column end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
8 9 10 |
# File 'lib/charming/presentation/components/viewport/position.rb', line 8 def offset @offset end |
Instance Method Details
#clamp(bounds) ⇒ Object
60 61 62 63 |
# File 'lib/charming/presentation/components/viewport/position.rb', line 60 def clamp(bounds) @offset = offset.clamp(0, bounds.fetch(:max_offset)) @column = column.clamp(0, bounds.fetch(:max_column)) end |
#end_at(bounds) ⇒ Object
40 41 42 43 |
# File 'lib/charming/presentation/components/viewport/position.rb', line 40 def end_at(bounds) @offset = bounds.fetch(:max_offset) @column = bounds.fetch(:max_column) end |
#home ⇒ Object
35 36 37 38 |
# File 'lib/charming/presentation/components/viewport/position.rb', line 35 def home @offset = 0 @column = 0 end |
#move_to(row, bounds) ⇒ Object
55 56 57 58 |
# File 'lib/charming/presentation/components/viewport/position.rb', line 55 def move_to(row, bounds) @offset = row clamp(bounds) end |
#page_down(page_size, bounds) ⇒ Object
30 31 32 33 |
# File 'lib/charming/presentation/components/viewport/position.rb', line 30 def page_down(page_size, bounds) @offset += page_size clamp(bounds) end |
#page_up(page_size, bounds) ⇒ Object
25 26 27 28 |
# File 'lib/charming/presentation/components/viewport/position.rb', line 25 def page_up(page_size, bounds) @offset -= page_size clamp(bounds) end |
#scroll_down(bounds) ⇒ Object
20 21 22 23 |
# File 'lib/charming/presentation/components/viewport/position.rb', line 20 def scroll_down(bounds) @offset += 1 clamp(bounds) end |
#scroll_left(bounds) ⇒ Object
45 46 47 48 |
# File 'lib/charming/presentation/components/viewport/position.rb', line 45 def scroll_left(bounds) @column -= 1 clamp(bounds) end |
#scroll_right(bounds) ⇒ Object
50 51 52 53 |
# File 'lib/charming/presentation/components/viewport/position.rb', line 50 def scroll_right(bounds) @column += 1 clamp(bounds) end |
#scroll_up(bounds) ⇒ Object
15 16 17 18 |
# File 'lib/charming/presentation/components/viewport/position.rb', line 15 def scroll_up(bounds) @offset -= 1 clamp(bounds) end |