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



150
151
152
153
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 150

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.



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

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



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

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

#unhighlightObject

remove all highlights



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

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