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
length
characters long fromstart
, returns an Array of Vectors describing it. -
#translate(docid, point) ⇒ Object
Returns the notional offset of the point
point
within the documentdocid
, or nil if that point is not displayed.
Constructor Details
#initialize(*args) ⇒ TextTable
Returns a new instance of TextTable.
318 319 320 321 |
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 318 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
325 326 327 328 |
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 325 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
332 333 334 335 |
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 332 def []=(key, value) super(key, value) @reverse_table[ value.to_code() ] = key unless value.nil? end |
#fetch(key) ⇒ Object
337 338 339 340 341 342 343 344 345 346 |
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 337 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
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 350 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.
378 379 380 381 382 383 384 385 |
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 378 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 |