Class: Sirens::TextView
- Inherits:
-
WidgetView
- Object
- AbstractView
- WidgetView
- Sirens::TextView
- Defined in:
- lib/views/text_view.rb
Class Method Summary collapse
-
.view_accepted_styles ⇒ Object
Answer the styles accepted by this view.
Instance Method Summary collapse
- #background_color=(value) ⇒ Object
- #foreground_color=(value, state: :normal) ⇒ Object
-
#initialize_handles ⇒ Object
Initializing.
-
#selected_text ⇒ Object
Returns the selected text of nil if no text is selected.
- #set_text(text) ⇒ Object
- #state_colors_from(value) ⇒ Object
-
#subscribe_to_ui_events ⇒ Object
Hooking GUI signals.
- #text ⇒ Object
-
#text_view ⇒ Object
Accessing.
- #wrap_mode ⇒ Object
-
#wrap_mode=(value) ⇒ Object
Styles.
Methods inherited from WidgetView
#add_view, #apply_prop, #apply_props, #initialize, #main_handle
Methods inherited from AbstractView
accepted_styles, #accepted_styles, #add_view, #attribute_at, #height, #height=, #initialize, #main_handle, #populate_popup_menu_block=, #remove_view, #set_attribute, #show, #show_popup_menu, #width, #width=
Constructor Details
This class inherits a constructor from Sirens::WidgetView
Class Method Details
.view_accepted_styles ⇒ Object
Answer the styles accepted by this view.
9 10 11 |
# File 'lib/views/text_view.rb', line 9 def view_accepted_styles() super() + [:wrap_mode].freeze end |
Instance Method Details
#background_color=(value) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/views/text_view.rb', line 47 def background_color=(value) state_colors_from(value).each_pair do |state, value| next if value.nil? text_view.override_background_color( state, Gdk::RGBA.parse(value) ) end end |
#foreground_color=(value, state: :normal) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/views/text_view.rb', line 55 def foreground_color=(value, state: :normal) state_colors_from(value).each_pair do |state, value| next if value.nil? text_view.override_color( state, Gdk::RGBA.parse(value) ) end end |
#initialize_handles ⇒ Object
Initializing
16 17 18 19 20 21 22 23 |
# File 'lib/views/text_view.rb', line 16 def initialize_handles() @text_view = Gtk::TextView.new @main_handle = Gtk::ScrolledWindow.new @main_handle.set_policy(:automatic, :always) @main_handle.add(@text_view) end |
#selected_text ⇒ Object
Returns the selected text of nil if no text is selected.
104 105 106 107 108 109 110 |
# File 'lib/views/text_view.rb', line 104 def selected_text() selection_bounds = text_view.buffer.selection_bounds return if selection_bounds.nil? text_view.buffer.get_text(selection_bounds[0], selection_bounds[1], false) end |
#set_text(text) ⇒ Object
93 94 95 96 97 |
# File 'lib/views/text_view.rb', line 93 def set_text(text) text = '' if text.nil? text_view.buffer.text = text end |
#state_colors_from(value) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/views/text_view.rb', line 63 def state_colors_from(value) colors = Hash[ normal: nil, active: nil, prelight: nil, selected: nil, insensitive: nil, ] if value.kind_of?(Hash) value.each_pair do |state, value| colors[state] = value end else colors[:normal] = value end colors end |
#subscribe_to_ui_events ⇒ Object
Hooking GUI signals
27 28 29 30 31 32 33 34 35 |
# File 'lib/views/text_view.rb', line 27 def subscribe_to_ui_events() text_view.signal_connect('populate-popup') do |text_view, | = MenuView.new(menu_handle: ) @populate_popup_menu_block.call(menu: ) .show_all end end |
#text ⇒ Object
89 90 91 |
# File 'lib/views/text_view.rb', line 89 def text() text_view.buffer.text end |
#text_view ⇒ Object
Accessing
85 86 87 |
# File 'lib/views/text_view.rb', line 85 def text_view() @text_view end |
#wrap_mode ⇒ Object
43 44 45 |
# File 'lib/views/text_view.rb', line 43 def wrap_mode() text_view.wrap_mode end |
#wrap_mode=(value) ⇒ Object
Styles
39 40 41 |
# File 'lib/views/text_view.rb', line 39 def wrap_mode=(value) text_view.wrap_mode = value end |