Class: QDA::GUI::CompositeText::TextTable
- Inherits:
-
Hash
- Object
- Hash
- QDA::GUI::CompositeText::TextTable
- Defined in:
- lib/weft/wxgui/controls/textcontrols.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
returns the object associated with the character point #key within the text table.
-
#[]=(key, value) ⇒ Object
returns the object associated with the character point #key within the text table.
- #fetch(key) ⇒ Object
-
#initialize(*args) ⇒ TextTable
constructor
A new instance of TextTable.
-
#range_to_vectors(start, length) ⇒ Object
given a range across the text
lengthcharacters long fromstart, returns an Array of Vectors describing it. -
#translate(docid, point) ⇒ Object
Returns the notional offset of the point
pointwithin the documentdocid, or nil if that point is not displayed.
Constructor Details
#initialize(*args) ⇒ TextTable
Returns a new instance of TextTable.
310 311 312 313 |
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 310 def initialize(*args) @reverse_table = {} super(*args) end |
Instance Method Details
#[](key) ⇒ Object
returns the object associated with the character point #key within the text table. Note that
317 318 319 320 |
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 317 def [] (key) keys.sort.each { | k | return super(k) if key < k } return nil end |
#[]=(key, value) ⇒ Object
returns the object associated with the character point #key within the text table. Note that
324 325 326 327 |
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 324 def []=(key, value) super(key, value) @reverse_table[ value.to_code() ] = key unless value.nil? end |
#fetch(key) ⇒ Object
329 330 331 332 333 334 335 336 337 338 |
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 329 def fetch(key) offset = 0 keys.sort.each do | k | if key < k return super(k), key - offset end offset = k end return nil end |
#range_to_vectors(start, length) ⇒ Object
given a range across the text length characters long from start, returns an Array of Vectors describing it
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 342 def range_to_vectors(start, length) offset = 0 results = QDA::CodeSet[] # at each iteration, offset is the position that we're starting from # k is the offset we're going to. keys.sort.each do | k | word = self[k] next unless word this_start = [ k, start ].max this_end = [ k + word.length, start + length ].min # they're not overlapping next if this_start >= this_end results.add( QDA::Code.new( word.docid, word.offset - k + this_start, this_end - this_start ) ) # break if k >= start + length offset = k end return results end |
#translate(docid, point) ⇒ Object
Returns the notional offset of the point point within the document docid, or nil if that point is not displayed. Note that this represents position within the notional underlying contents, not the actual display in text control. If you wish to use these to refer to text displayed within the text control, call true_index_to_pos() on the return value.
370 371 372 373 374 375 376 377 |
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 370 def translate(docid, point) target = @reverse_table.keys.find do | frag | frag.docid == docid && frag.contains?(point) end return nil if target.nil? return @reverse_table[target] - target.length + ( point - target.offset ) end |