Class: RubyTUI::Widgets::TableState
- Inherits:
-
Object
- Object
- RubyTUI::Widgets::TableState
- Defined in:
- lib/rubytui/widgets/table.rb
Overview
TableState holds external state for the Table widget.
selected is the index of the selected row and offset the index of the
first visible row. RubyTUI::Widgets::Table#render clamps both in place.
Instance Attribute Summary collapse
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#selected ⇒ Object
Returns the value of attribute selected.
Instance Method Summary collapse
-
#initialize(selected: 0, offset: 0) ⇒ TableState
constructor
A new instance of TableState.
-
#select_next(total) ⇒ void
Select the next row, wrapping from the last row to the first.
-
#select_previous(total) ⇒ void
Select the previous row, wrapping from the first row to the last.
Constructor Details
#initialize(selected: 0, offset: 0) ⇒ TableState
Returns a new instance of TableState.
16 17 18 19 |
# File 'lib/rubytui/widgets/table.rb', line 16 def initialize(selected: 0, offset: 0) @selected = selected @offset = offset end |
Instance Attribute Details
#offset ⇒ Object
Returns the value of attribute offset.
12 13 14 |
# File 'lib/rubytui/widgets/table.rb', line 12 def offset @offset end |
#selected ⇒ Object
Returns the value of attribute selected.
12 13 14 |
# File 'lib/rubytui/widgets/table.rb', line 12 def selected @selected end |
Instance Method Details
#select_next(total) ⇒ void
This method returns an undefined value.
Select the next row, wrapping from the last row to the first.
Does nothing when total is 0 or negative.
27 28 29 |
# File 'lib/rubytui/widgets/table.rb', line 27 def select_next(total) @selected = (@selected + 1) % total if total > 0 end |
#select_previous(total) ⇒ void
This method returns an undefined value.
Select the previous row, wrapping from the first row to the last.
Does nothing when total is 0 or negative.
37 38 39 |
# File 'lib/rubytui/widgets/table.rb', line 37 def select_previous(total) @selected = (@selected - 1) % total if total > 0 end |