Class: RubyCurses::TabularWidget::Circular

Inherits:
Struct
  • Object
show all
Defined in:
lib/rbcurse/core/widgets/tabularwidget.rb

Overview

a structure that maintains position and gives next and previous taking max index into account. it also circles. Can be used for traversing next component in a form, or container, or columns in a table.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(m, c = 0) ⇒ Circular

Returns a new instance of Circular.



1048
1049
1050
1051
1052
1053
# File 'lib/rbcurse/core/widgets/tabularwidget.rb', line 1048

def initialize  m, c=0
  raise "max index cannot be nil" unless m
  @max_index = m
  @current_index = c
  @last_index = c
end

Instance Attribute Details

#current_indexObject

Returns the value of attribute current_index

Returns:

  • (Object)

    the current value of current_index



1045
1046
1047
# File 'lib/rbcurse/core/widgets/tabularwidget.rb', line 1045

def current_index
  @current_index
end

#last_indexObject (readonly)

Returns the value of attribute last_index.



1046
1047
1048
# File 'lib/rbcurse/core/widgets/tabularwidget.rb', line 1046

def last_index
  @last_index
end

Instance Method Details

#is_last?Boolean

Returns:

  • (Boolean)


1070
1071
1072
# File 'lib/rbcurse/core/widgets/tabularwidget.rb', line 1070

def is_last?
  @current_index == @max_index
end

#nextObject



1054
1055
1056
1057
1058
1059
1060
1061
# File 'lib/rbcurse/core/widgets/tabularwidget.rb', line 1054

def next
  @last_index = @current_index
  if @current_index + 1 > @max_index
    @current_index = 0
  else
    @current_index += 1
  end
end

#previousObject



1062
1063
1064
1065
1066
1067
1068
1069
# File 'lib/rbcurse/core/widgets/tabularwidget.rb', line 1062

def previous
  @last_index = @current_index
  if @current_index - 1 < 0
    @current_index = @max_index
  else
    @current_index -= 1
  end
end