Class: Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/rodo/rodolib.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(journal) ⇒ Cursor

Returns a new instance of Cursor.



209
210
211
212
213
214
215
216
# 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

Instance Attribute Details

#dayObject

Returns the value of attribute day.



207
208
209
# File 'lib/rodo/rodolib.rb', line 207

def day
  @day
end

#journalObject

Returns the value of attribute journal.



206
207
208
# File 'lib/rodo/rodolib.rb', line 206

def journal
  @journal
end

Instance Method Details

#lineObject



236
237
238
# File 'lib/rodo/rodolib.rb', line 236

def line
  @line
end

#line=(line) ⇒ Object



224
225
226
227
228
# 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

#xObject



240
241
242
# File 'lib/rodo/rodolib.rb', line 240

def x
  @x
end

#x=(x) ⇒ Object



230
231
232
233
234
# 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