Class: CyberarmEngine::Element::CheckBox

Inherits:
Flow show all
Defined in:
lib/cyberarm_engine/ui/elements/check_box.rb

Constant Summary

Constants included from Theme

Theme::THEME

Instance Attribute Summary

Attributes inherited from Container

#children, #fill_color, #gui_state, #scroll_x, #scroll_y, #stroke_color

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 Flow

#layout

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 inherited from Container

#add, #build, #clear, #fits_on_line?, #hit_element?, #layout, #max_width, #move_to_next_line, #position_on_current_line, #position_on_next_line, #recalculate, #render, #tallest_neighbor, #update

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, #recalculate, #render, #reposition, #root, #set_background, #set_border_color, #set_border_thickness, #set_margin, #set_padding, #show, #stylize, #toggle, #update, #update_background, #visible?, #width

Methods included from CyberarmEngine::Event

#event, #publish, #subscribe, #unsubscribe

Methods included from Theme

#deep_merge, #default, #theme_defaults

Constructor Details

#initialize(text, options, block = nil) ⇒ CheckBox

Returns a new instance of CheckBox.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/cyberarm_engine/ui/elements/check_box.rb', line 4

def initialize(text, options, block = nil)
  super({}, block = nil)
  options[:toggled] = options[:checked]

  @toggle_button = ToggleButton.new(options)
  @label         = Label.new(text, options)

  define_label_singletons

  add(@toggle_button)
  add(@label)
end

Instance Method Details

#define_label_singletonsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cyberarm_engine/ui/elements/check_box.rb', line 30

def define_label_singletons
  @label.define_singleton_method(:_toggle_button) do |button|
    @_toggle_button = button
  end

  @label._toggle_button(@toggle_button)

  @label.define_singleton_method(:holding_left_mouse_button) do |sender, x, y|
    @_toggle_button.left_mouse_button(sender, x, y)
  end

  @label.define_singleton_method(:released_left_mouse_button) do |sender, x, y|
    @_toggle_button.released_left_mouse_button(sender, x, y)
  end

  @label.define_singleton_method(:clicked_left_mouse_button) do |sender, x, y|
    @_toggle_button.clicked_left_mouse_button(sender, x, y)
  end

  @label.define_singleton_method(:enter) do |sender|
    @_toggle_button.enter(sender)
  end

  @label.define_singleton_method(:leave) do |sender|
    @_toggle_button.leave(sender)
  end
end

#text=(text) ⇒ Object



17
18
19
20
# File 'lib/cyberarm_engine/ui/elements/check_box.rb', line 17

def text=(text)
  @label.text = text
  recalculate
end

#valueObject



22
23
24
# File 'lib/cyberarm_engine/ui/elements/check_box.rb', line 22

def value
  @toggle_button.value
end

#value=(bool) ⇒ Object



26
27
28
# File 'lib/cyberarm_engine/ui/elements/check_box.rb', line 26

def value=(bool)
  @toggle_button.vlaue = bool
end