Class: Glimmer::LibUI::ControlProxy::MenuItemProxy::RadioMenuItemProxy

Inherits:
Glimmer::LibUI::ControlProxy::MenuItemProxy show all
Defined in:
lib/glimmer/libui/control_proxy/menu_item_proxy/radio_menu_item_proxy.rb

Overview

Proxy for LibUI radio menu item object

Follows the Proxy Design Pattern

Constant Summary

Constants inherited from Glimmer::LibUI::ControlProxy

BOOLEAN_PROPERTIES, KEYWORD_ALIASES, STRING_PROPERTIES, TransformProxy

Instance Attribute Summary

Attributes inherited from Glimmer::LibUI::ControlProxy

#args, #block, #content_added, #custom_control, #keyword, #libui, #options, #parent_custom_control, #parent_proxy, #slot

Instance Method Summary collapse

Methods inherited from Glimmer::LibUI::ControlProxy::MenuItemProxy

#libui_api_keyword

Methods inherited from Glimmer::LibUI::ControlProxy

#append_properties, #append_property, #bind_content, #can_handle_listener?, constant_symbol, #content, control_proxies, control_proxy_class, create, #custom_listener_name_aliases, #custom_listener_names, #default_destroy, #deregister_all_custom_listeners, #deregister_custom_listeners, descendant_keyword_constant_map, #destroy, #destroy_child, #enabled, exists?, #handle_custom_listener, #has_custom_listener?, image_proxies, keyword, #libui_api_keyword, #listeners, #listeners_for, main_window_proxy, map_descendant_keyword_constants_for, menu_proxies, #method_missing, new_control, #notify_custom_listeners, #post_add_content, #post_initialize_child, reset_descendant_keyword_constant_map, #respond_to?, #respond_to_libui?, #send_to_libui, #visible, #window_proxy

Methods included from DataBindable

#data_bind, #data_bind_read, #data_binding_model_attribute_observer_registrations

Methods included from Parent

#children, #post_initialize_child

Constructor Details

#initialize(keyword, parent, args, &block) ⇒ RadioMenuItemProxy

Returns a new instance of RadioMenuItemProxy.



32
33
34
35
# File 'lib/glimmer/libui/control_proxy/menu_item_proxy/radio_menu_item_proxy.rb', line 32

def initialize(keyword, parent, args, &block)
  @last_checked = nil
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::LibUI::ControlProxy

Instance Method Details

#checked(value = nil) ⇒ Object Also known as: checked?, set_checked, checked=



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/glimmer/libui/control_proxy/menu_item_proxy/radio_menu_item_proxy.rb', line 37

def checked(value = nil)
  if value.nil?
    super()
  else
    super
    if Glimmer::LibUI.integer_to_boolean(value, allow_nil: false) != Glimmer::LibUI.integer_to_boolean(@last_checked, allow_nil: false)
      if Glimmer::LibUI.integer_to_boolean(value)
        (@parent_proxy.children - [self]).select {|c| c.is_a?(RadioMenuItemProxy)}.each do |menu_item|
          menu_item.checked = false
        end
      end
      @last_checked = checked
    end
  end
end

#data_bind_write(property, model_binding) ⇒ Object



68
69
70
# File 'lib/glimmer/libui/control_proxy/menu_item_proxy/radio_menu_item_proxy.rb', line 68

def data_bind_write(property, model_binding)
  handle_listener('on_clicked') { model_binding.call(checked) } if property == 'checked'
end

#handle_listener(listener_name, &listener) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/glimmer/libui/control_proxy/menu_item_proxy/radio_menu_item_proxy.rb', line 56

def handle_listener(listener_name, &listener)
  if listener_name.to_s == 'on_clicked'
    radio_listener = Proc.new do
      self.checked = true
      listener.call(self)
    end
    super(listener_name, &radio_listener)
  else
    super
  end
end