class Fidgit::ToggleButton
A button that toggles its value from false<->true when clicked.
Attributes
value[R]
Public Class Methods
new(text, options = {}, &block)
click to toggle source
@param (see Button#initialize)
@option (see Button#initialize)
Calls superclass method
Fidgit::Button::new
# File lib/fidgit/elements/toggle_button.rb, line 14 def initialize(text, options = {}, &block) options = { value: false }.merge! options @value = options[:value] super(text, options) @text_on = (options[:text_on] || text).dup @icon_on = options[:icon_on] || icon @tip_on = (options[:tip_on] || tip).dup @border_color_on = (options[:border_color_on] || options[:border_color] || default(:toggled, :border_color)).dup @text_off = (options[:text_off] || text).dup @icon_off = options[:icon_off] || icon @tip_off = (options[:tip_off] || tip).dup @border_color_off = (options[:border_color_off] || options[:border_color] || default(:border_color)).dup update_status subscribe :clicked_left_mouse_button do |sender, x, y| @value = (not @value) update_status publish :changed, @value end end
Public Instance Methods
value=(value)
click to toggle source
# File lib/fidgit/elements/toggle_button.rb, line 9 def value=(value); @value = value; update_status; end
Protected Instance Methods
post_init_block(&block)
click to toggle source
The block for a toggle-button is connected to :changed event.
# File lib/fidgit/elements/toggle_button.rb, line 44 def post_init_block(&block) subscribe :changed, &block end
update_status()
click to toggle source
# File lib/fidgit/elements/toggle_button.rb, line 49 def update_status if @value self.text = @text_on.dup @icon = @icon_on ? @icon_on.dup : nil @tip = @tip_on.dup @border_color = @border_color_on.dup else self.text = @text_off.dup @icon = @icon_off ? @icon_off.dup : nil @tip = @tip_off.dup @border_color = @border_color_off.dup end recalc nil end