Class: MittensUi::Textbox
Overview
A single-line or multiline text input widget. In single-line mode (default), wraps Gtk::Entry. In multiline mode, wraps Gtk::TextView inside a Gtk::ScrolledWindow.
Instance Attribute Summary
Attributes inherited from Core
Instance Method Summary collapse
-
#clear ⇒ void
Clears all text from the widget.
-
#enable_text_completion(data) ⇒ void
Enables autocomplete suggestions for single-line mode.
-
#initialize(options = {}) ⇒ Textbox
constructor
Creates a new Textbox widget.
-
#text ⇒ String
Returns the current text content of the widget.
- #text=(value) ⇒ Object
Methods inherited from Core
#hidden?, #hide, #keyboard_shortcut, #remove, #remove_keyboard_shortcut, #render, #shortcuts, #show
Methods included from Helpers
#icon_map, #list_system_icons, #set_margin_from_opts_for
Constructor Details
#initialize(options = {}) ⇒ Textbox
Creates a new Textbox widget.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mittens_ui/textbox.rb', line 45 def initialize( = {}) @multiline = .fetch(:multiline, false) if @multiline init_multiline() else init_single_line() end super(@gtk_widget, ) end |
Instance Method Details
#clear ⇒ void
This method returns an undefined value.
Clears all text from the widget. Works in both single-line and multiline mode.
88 89 90 91 92 93 94 |
# File 'lib/mittens_ui/textbox.rb', line 88 def clear if @multiline @text_buffer.text = '' else @textbox.text = '' end end |
#enable_text_completion(data) ⇒ void
This method returns an undefined value.
Enables autocomplete suggestions for single-line mode. Has no effect in multiline mode.
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/mittens_ui/textbox.rb', line 104 def enable_text_completion(data) return if @multiline completion = Gtk::EntryCompletion.new model = Gtk::ListStore.new(String) data.each do |value| iter = model.append iter[0] = value end completion.model = model completion.text_column = 0 @textbox.completion = completion end |
#text ⇒ String
Returns the current text content of the widget. Works in both single-line and multiline mode.
64 65 66 67 68 69 70 |
# File 'lib/mittens_ui/textbox.rb', line 64 def text if @multiline @text_buffer.text else @textbox.text end end |
#text=(value) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/mittens_ui/textbox.rb', line 73 def text=(value) if @multiline @text_buffer.text = value.to_s else @textbox.text = value.to_s end end |