class Cursor

Encapsulates the position of the cursor in the following dimensions:

- which *x* position the cursor is on, on a particular *line*
- which *line* the cursor is on, on a particular *day*
- which *day* is currently shown on the main screen
- which *x* position would be on ('shadow x'), if the line would be longer
- which *line* the cursor would be on ('shadow line'), if the current day would have more lines

Attributes

day[RW]
journal[RW]

Public Class Methods

new(journal) click to toggle source
# File lib/rodo/rodolib.rb, line 209
def initialize(journal)
  @journal = journal
  @shadow_line = 0
  @shadow_x = 0
  self.day = @journal.most_recent_index
  # self.line = 0
  # self.x = 0
end

Public Instance Methods

day=(day) click to toggle source
# File lib/rodo/rodolib.rb, line 218
def day=(day)
  @day = [[0, day].max, @journal.days.size - 1].min
  @line = [@journal.days[@day].lines.size - 1, @shadow_line].min
  @x = [@journal.days[@day].lines[@line].size, @shadow_x].min
end
line() click to toggle source
# File lib/rodo/rodolib.rb, line 236
def line
  @line
end
line=(line) click to toggle source
# File lib/rodo/rodolib.rb, line 224
def line=(line)
  line = [[0, line].max, @journal.days[@day].lines.size - 1].min
  @line = @shadow_line = line
  @x = [@journal.days[@day].lines[@line].size, @shadow_x].min
end
x() click to toggle source
# File lib/rodo/rodolib.rb, line 240
def x
  @x
end
x=(x) click to toggle source
# File lib/rodo/rodolib.rb, line 230
def x=(x)
  # note x is clamped 1 character beyond the length of the line
  x = [[0, x].max, @journal.days[@day].lines[@line].size].min
  @x = @shadow_x = x
end