Class: CyberarmEngine::Element::ToggleButton
- Inherits:
-
Button
- Object
- CyberarmEngine::Element
- Label
- Button
- CyberarmEngine::Element::ToggleButton
- Defined in:
- lib/cyberarm_engine/ui/elements/toggle_button.rb
Constant Summary
Constants included from Theme
Instance Attribute Summary collapse
-
#toggled ⇒ Object
Returns the value of attribute toggled.
Attributes inherited from CyberarmEngine::Element
#background_canvas, #border_canvas, #enabled, #event_handler, #options, #parent, #style, #x, #y, #z
Instance Method Summary collapse
- #clicked_left_mouse_button(sender, x, y) ⇒ Object
-
#initialize(options, block = nil) ⇒ ToggleButton
constructor
A new instance of ToggleButton.
- #recalculate ⇒ Object
- #toggle ⇒ Object
- #value ⇒ Object
Methods inherited from Button
#blur, #draw_text, #enter, #leave, #left_mouse_button, #released_left_mouse_button, #render
Methods inherited from Label
Methods inherited from CyberarmEngine::Element
#background=, #button_down, #button_up, #content_height, #content_width, #default_events, #draw, #enabled?, #height, #hide, #hit?, #inner_height, #inner_width, #is_root?, #noncontent_height, #noncontent_width, #outer_height, #outer_width, #render, #reposition, #root, #set_background, #set_border_color, #set_border_thickness, #set_margin, #set_padding, #show, #stylize, #update, #update_background, #value=, #visible?, #width
Methods included from Common
#current_state, #darken, #draw_rect, #fill, #get_asset, #get_image, #get_sample, #get_song, #lighten, #opacity, #pop_state, #previous_state, #push_state, #show_cursor, #show_cursor=, #window
Methods included from CyberarmEngine::Event
#event, #publish, #subscribe, #unsubscribe
Methods included from Theme
#deep_merge, #default, #theme_defaults
Constructor Details
#initialize(options, block = nil) ⇒ ToggleButton
Returns a new instance of ToggleButton.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/cyberarm_engine/ui/elements/toggle_button.rb', line 6 def initialize(, block = nil) super([:checkmark], , block) @toggled = [:toggled] || false if @toggled @text.text = @options[:checkmark] else @text.text = "" end return self end |
Instance Attribute Details
#toggled ⇒ Object
Returns the value of attribute toggled.
4 5 6 |
# File 'lib/cyberarm_engine/ui/elements/toggle_button.rb', line 4 def toggled @toggled end |
Instance Method Details
#clicked_left_mouse_button(sender, x, y) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/cyberarm_engine/ui/elements/toggle_button.rb', line 23 def (sender, x, y) toggle @block.call(self) if @block return :handled end |
#recalculate ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/cyberarm_engine/ui/elements/toggle_button.rb', line 41 def recalculate super _width = dimensional_size(@style.width, :width) _height= dimensional_size(@style.height,:height) @width = _width ? _width : @text.textobject.text_width(@options[:checkmark]) @height = _height ? _height : @text.height update_background end |
#toggle ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/cyberarm_engine/ui/elements/toggle_button.rb', line 31 def toggle if @toggled @toggled = false @text.text = "" else @toggled = true @text.text = @options[:checkmark] end end |
#value ⇒ Object
51 52 53 |
# File 'lib/cyberarm_engine/ui/elements/toggle_button.rb', line 51 def value @toggled end |