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, #tip, #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

Methods inherited from CyberarmEngine::Element

#background=, #button_down, #button_up, #content_height, #content_width, #default_events, #draggable?, #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, #to_s, #toggle, #update, #update_background, #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)
  @value = options[:checked] || false
  if @value
    @text.text = @options[:checkmark]
  else
    @text.text = ""
  end

  return self
end

Instance Attribute Details

#toggledObject (readonly)

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



18
19
20
21
22
23
24
# File 'lib/cyberarm_engine/ui/elements/toggle_button.rb', line 18

def clicked_left_mouse_button(sender, x, y)
  self.value = !@value

  @block.call(self) if @block

  return :handled
end

#recalculateObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cyberarm_engine/ui/elements/toggle_button.rb', line 26

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

#valueObject



38
39
40
# File 'lib/cyberarm_engine/ui/elements/toggle_button.rb', line 38

def value
  @value
end

#value=(boolean) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cyberarm_engine/ui/elements/toggle_button.rb', line 42

def value=(boolean)
  @value = boolean

  if boolean
    @text.text = @options[:checkmark]
  else
    @text.text = ""
  end

  recalculate

  publish(:changed, @value)
end