Class: CyberarmEngine::Element::ToggleButton

Inherits:
Button show all
Defined in:
lib/cyberarm_engine/ui/elements/toggle_button.rb

Constant Summary

Constants included from Theme

Theme::THEME

Instance Attribute Summary collapse

Attributes inherited from CyberarmEngine::Element

#background_canvas, #border_canvas, #enabled, #event_handler, #options, #parent, #style, #x, #y, #z

Instance Method Summary collapse

Methods inherited from Button

#blur, #draw_text, #enter, #leave, #left_mouse_button, #released_left_mouse_button, #render

Methods inherited from Label

#render, #value=

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(options, block = nil)
  super(options[:checkmark], options, block)
  @toggled = options[:toggled] || false
  if @toggled
    @text.text = @options[:checkmark]
  else
    @text.text = ""
  end

  return self
end

Instance Attribute Details

#toggledObject

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 clicked_left_mouse_button(sender, x, y)
  toggle

  @block.call(self) if @block

  return :handled
end

#recalculateObject



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

#toggleObject



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

#valueObject



51
52
53
# File 'lib/cyberarm_engine/ui/elements/toggle_button.rb', line 51

def value
  @toggled
end