Class: MittensUi::Switch

Inherits:
Core
  • Object
show all
Defined in:
lib/mittens_ui/switch.rb

Instance Attribute Summary

Attributes inherited from Core

#core_widget

Instance Method Summary collapse

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(options = {})
  @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, options)
end

Instance Method Details

#activateObject 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 |switch_widget|
    switch_widget.active? ? switch_widget.set_active(true) : switch_widget.set_active(false)
    yield
  end
end

#renderObject



27
28
29
30
# File 'lib/mittens_ui/switch.rb', line 27

def render
  $vertical_box.pack_start(@grid)
  return self
end

#statusObject



32
33
34
# File 'lib/mittens_ui/switch.rb', line 32

def status
  @switch.active? ? :on : :off
end