class MittensUi::Switch

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method MittensUi::Core::new
# 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

Public Instance Methods

activate() { || ... } click to toggle source
# 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
Also aliased as: on
on()
Alias for: activate
render() click to toggle source
# File lib/mittens_ui/switch.rb, line 27
def render
  $vertical_box.pack_start(@grid)
  return self
end
status() click to toggle source
# File lib/mittens_ui/switch.rb, line 32
def status
  @switch.active? ? :on : :off
end