Module: QDA::GUI::HighlightingTextCtrl::TextColourHighlighter

Included in:
QDA::GUI::HighlightingTextCtrl
Defined in:
lib/weft/wxgui/controls/textcontrols.rb

Overview

Provide support for highlighting regions within the text control by changing the text foreground colour - background colour doesn’t work on MS Windows WxWidgets.

Constant Summary collapse

HIGHLIGHTED_STYLE =

background colour doesn’t seem to work in MSW

Wx::TextAttr.new(Wx::BLUE)
NORMAL_STYLE =
Wx::TextAttr.new(Wx::BLACK)

Instance Method Summary collapse

Instance Method Details

#clearObject



142
143
144
145
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 142

def clear()
  super()
  @highlights = []
end

#highlight(from, to) ⇒ Object

highlight the characters from from to to. These are characters within the underlying text - this method will automatically translate those to real characters displayed within the text control.



127
128
129
130
131
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 127

def highlight(from, to)
  true_from, true_to = true_index_to_pos(from), true_index_to_pos(to)
  set_style( true_from, true_to, HIGHLIGHTED_STYLE )
  @highlights.push( [from, to] )
end

#initialize(*args) ⇒ Object



118
119
120
121
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 118

def initialize(*args)
  super
  @highlights = []
end

#unhighlightObject

remove all highlights



134
135
136
137
138
139
140
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 134

def unhighlight()
  while extent = @highlights.shift()
    from, to = *extent
    true_from, true_to = true_index_to_pos(from), true_index_to_pos(to)
    set_style( true_from, true_to, NORMAL_STYLE )
  end      
end