Class: MittensUi::Switch
Instance Attribute Summary
Attributes inherited from Core
Instance Method Summary collapse
- #activate ⇒ Object (also: #on)
-
#initialize(options = {}) ⇒ Switch
constructor
A new instance of Switch.
- #render ⇒ Object
- #status ⇒ Object
Methods inherited from Core
#hidden?, #hide, #remove, #show
Methods included from Helpers
#icon_map, #list_system_icons, #set_margin_from_opts_for
Constructor Details
#initialize(options = {}) ⇒ Switch
Returns a new instance of Switch.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mittens_ui/switch.rb', line 5 def initialize( = {}) @switch = Gtk::Switch.new @switch.set_active(false) # We need a Grid within our global $vertical_box layout # in order to make the Widget look good (meaning not overly streched). @grid = Gtk::Grid.new @grid.set_column_spacing(1) @grid.set_row_spacing(1) @grid.attach(@switch, 0, 0, 1, 1) super(@switch, ) end |
Instance Method Details
#activate ⇒ Object Also known as: on
19 20 21 22 23 24 |
# File 'lib/mittens_ui/switch.rb', line 19 def activate @switch.signal_connect('notify::active') do || .active? ? .set_active(true) : .set_active(false) yield end end |
#render ⇒ Object
27 28 29 30 |
# File 'lib/mittens_ui/switch.rb', line 27 def render $vertical_box.pack_start(@grid) return self end |
#status ⇒ Object
32 33 34 |
# File 'lib/mittens_ui/switch.rb', line 32 def status @switch.active? ? :on : :off end |