Class: Fidgit::ToggleButton
Overview
A button that toggles its value from false<->true when clicked.
Constant Summary
Constants inherited from Label
Constants inherited from Composite
Constants inherited from Element
Element::DEFAULT_SCHEMA_FILE, Element::VALID_ALIGN_H, Element::VALID_ALIGN_V
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Attributes inherited from Label
#background_color, #border_color, #icon_position
Attributes inherited from Packer
Attributes inherited from Element
#align_h, #align_v, #background_color, #border_thickness, #font, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #tip, #z
Instance Method Summary collapse
-
#initialize(text, options = {}, &block) ⇒ ToggleButton
constructor
A new instance of ToggleButton.
Methods inherited from Button
#activate, #clicked_left_mouse_button, #enabled=, #enter, #leave, #parent=, #text=
Methods inherited from Label
Methods inherited from Container
#add, #button, #clear, #color_picker, #color_well, #combo_box, #file_browser, #grid, #group, #hit_element, #horizontal, #image_frame, #insert, #label, #list, #radio_button, #remove, #scroll_area, #scroll_window, #slider, #text_area, #to_s, #toggle_button, #update, #vertical, #write_tree, #x=, #y=
Methods inherited from Element
#default, #drag?, #draw, #draw_frame, #draw_rect, #enabled=, #enabled?, #height, #height=, #hit?, #max_height, #max_width, #min_height, #min_width, new, original_new, #outer_height, #outer_width, #recalc, schema, #to_s, #update, #width, #width=, #with, #x, #x=, #y, #y=
Methods included from Event
#events, included, new_event_handlers, #publish, #subscribe, #unsubscribe
Constructor Details
#initialize(text, options = {}, &block) ⇒ ToggleButton
Returns a new instance of ToggleButton.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fidgit/elements/toggle_button.rb', line 14 def initialize(text, = {}, &block) = { value: false }.merge! @value = [:value] super(text, ) @text_on = ([:text_on] || text).dup @icon_on = [:icon_on] || icon @tip_on = ([:tip_on] || tip).dup @border_color_on = ([:border_color_on] || [:border_color] || default(:toggled, :border_color)).dup @text_off = ([:text_off] || text).dup @icon_off = [:icon_off] || icon @tip_off = ([:tip_off] || tip).dup @border_color_off = ([:border_color_off] || [: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 |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
8 9 10 |
# File 'lib/fidgit/elements/toggle_button.rb', line 8 def value @value end |