Class: RubyTUI::Widgets::TableState

Inherits:
Object
  • Object
show all
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.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selected: 0, offset: 0) ⇒ TableState

Returns a new instance of TableState.

Parameters:

  • selected (Integer) (defaults to: 0) —

    initial selected row index (default: 0)

  • offset (Integer) (defaults to: 0) —

    initial scroll offset (default: 0)



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.

Parameters:

  • total (Integer) —

    number of rows in the table



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.

Parameters:

  • total (Integer) —

    number of rows in the table



37
38
39
# File 'lib/rubytui/widgets/table.rb', line 37

def select_previous(total)
  @selected = (@selected - 1) % total if total > 0
end