Class: Glimmer::Wx::SizerProxy
- Inherits:
-
Object
- Object
- Glimmer::Wx::SizerProxy
- Includes:
- DataBindable
- Defined in:
- lib/glimmer/wx/sizer_proxy.rb
Overview
Proxy for Wx sizer objects
Follows the Proxy Design Pattern
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
wx returns the contained LibUI object.
-
#block ⇒ Object
readonly
wx returns the contained LibUI object.
-
#content_added ⇒ Object
(also: #content_added?)
readonly
wx returns the contained LibUI object.
-
#keyword ⇒ Object
readonly
wx returns the contained LibUI object.
-
#parent_proxy ⇒ Object
readonly
wx returns the contained LibUI object.
-
#wx ⇒ Object
readonly
wx returns the contained LibUI object.
Class Method Summary collapse
- .constant_symbol(keyword) ⇒ Object
- .create(keyword, parent, args, &block) ⇒ Object
- .descendant_keyword_constant_map ⇒ Object
- .exists?(keyword) ⇒ Boolean
- .keyword(constant_symbol) ⇒ Object
- .map_descendant_keyword_constants_for(klass, accumulator: {}) ⇒ Object
- .new_sizer(keyword, parent, args) ⇒ Object
- .reset_descendant_keyword_constant_map ⇒ Object
- .sizer_addable_method(keyword) ⇒ Object
- .sizer_proxy_class(keyword) ⇒ Object
- .wx_constant_symbol(keyword) ⇒ Object
Instance Method Summary collapse
- #add(control_proxy, *args, &block) ⇒ Object
-
#add_sizer_addable(keyword, *args) ⇒ Object
Adds a sizer addable (visual things other than controls) Example: for keyword ‘growable_col`, sizer addable method is `add_growable_col`.
-
#can_add_sizer_addable?(keyword) ⇒ Boolean
Checks if it can add a sizer addable (visual things other than controls) Example: for keyword ‘growable_col`, sizer addable method is `add_growable_col`.
- #content(&block) ⇒ Object
-
#initialize(keyword, parent, args, &block) ⇒ SizerProxy
constructor
A new instance of SizerProxy.
- #method_missing(method_name, *args, &block) ⇒ Object
-
#post_add_content ⇒ Object
Subclasses may override to perform post add_content work (normally must call super).
-
#post_initialize_child(child) ⇒ Object
Subclasses may override to perform post initialization work on an added child.
- #respond_to?(method_name, *args, &block) ⇒ Boolean
Methods included from DataBindable
#data_bind, #data_bind_read, #data_bind_write, #data_binding_model_attribute_observer_registrations
Constructor Details
#initialize(keyword, parent, args, &block) ⇒ SizerProxy
Returns a new instance of SizerProxy.
100 101 102 103 104 105 106 107 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 100 def initialize(keyword, parent, args, &block) @keyword = keyword @parent_proxy = parent @args = args @block = block build_sizer post_add_content if @block.nil? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 127 def method_missing(method_name, *args, &block) if @wx.respond_to?(method_name, true) @wx.send(method_name, *args, &block) else super end end |
Instance Attribute Details
#args ⇒ Object (readonly)
wx returns the contained LibUI object
97 98 99 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 97 def args @args end |
#block ⇒ Object (readonly)
wx returns the contained LibUI object
97 98 99 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 97 def block @block end |
#content_added ⇒ Object (readonly) Also known as: content_added?
wx returns the contained LibUI object
97 98 99 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 97 def content_added @content_added end |
#keyword ⇒ Object (readonly)
wx returns the contained LibUI object
97 98 99 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 97 def keyword @keyword end |
#parent_proxy ⇒ Object (readonly)
wx returns the contained LibUI object
97 98 99 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 97 def parent_proxy @parent_proxy end |
#wx ⇒ Object (readonly)
wx returns the contained LibUI object
97 98 99 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 97 def wx @wx end |
Class Method Details
.constant_symbol(keyword) ⇒ Object
60 61 62 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 60 def constant_symbol(keyword) "#{keyword.to_s.camelcase(:upper)}Proxy".to_sym end |
.create(keyword, parent, args, &block) ⇒ Object
40 41 42 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 40 def create(keyword, parent, args, &block) sizer_proxy_class(keyword).new(keyword, parent, args, &block) end |
.descendant_keyword_constant_map ⇒ Object
72 73 74 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 72 def descendant_keyword_constant_map @descendant_keyword_constant_map ||= map_descendant_keyword_constants_for(self) end |
.exists?(keyword) ⇒ Boolean
32 33 34 35 36 37 38 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 32 def exists?(keyword) keyword.end_with?('_sizer') and ( ::Wx.constants.include?(wx_constant_symbol(keyword)) or descendant_keyword_constant_map.keys.include?(keyword) ) end |
.keyword(constant_symbol) ⇒ Object
68 69 70 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 68 def keyword(constant_symbol) constant_symbol.to_s.underscore.sub(/_proxy$/, '') end |
.map_descendant_keyword_constants_for(klass, accumulator: {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 81 def map_descendant_keyword_constants_for(klass, accumulator: {}) klass.constants.map do |constant_symbol| [constant_symbol, klass.const_get(constant_symbol)] end.select do |constant_symbol, constant| constant.is_a?(Module) && !accumulator.values.include?(constant) end.each do |constant_symbol, constant| accumulator[keyword(constant_symbol)] = constant map_descendant_keyword_constants_for(constant, accumulator: accumulator) end accumulator end |
.new_sizer(keyword, parent, args) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 48 def new_sizer(keyword, parent, args) args = args.clone || [] if args.last.is_a?(Hash) args[-1] = args[-1].clone end ::Wx.const_get(wx_constant_symbol(keyword)).new(*args) end |
.reset_descendant_keyword_constant_map ⇒ Object
76 77 78 79 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 76 def reset_descendant_keyword_constant_map @descendant_keyword_constant_map = nil descendant_keyword_constant_map end |
.sizer_addable_method(keyword) ⇒ Object
64 65 66 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 64 def sizer_addable_method(keyword) "add_#{keyword}" end |
.sizer_proxy_class(keyword) ⇒ Object
44 45 46 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 44 def sizer_proxy_class(keyword) descendant_keyword_constant_map[keyword] || SizerProxy end |
.wx_constant_symbol(keyword) ⇒ Object
56 57 58 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 56 def wx_constant_symbol(keyword) keyword.to_s.camelcase(:upper).to_sym end |
Instance Method Details
#add(control_proxy, *args, &block) ⇒ Object
139 140 141 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 139 def add(control_proxy, *args, &block) @wx.add(control_proxy.wx, *args) end |
#add_sizer_addable(keyword, *args) ⇒ Object
Adds a sizer addable (visual things other than controls) Example: for keyword ‘growable_col`, sizer addable method is `add_growable_col`
151 152 153 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 151 def add_sizer_addable(keyword, *args) @wx.send(SizerProxy.sizer_addable_method(keyword), *args) end |
#can_add_sizer_addable?(keyword) ⇒ Boolean
Checks if it can add a sizer addable (visual things other than controls) Example: for keyword ‘growable_col`, sizer addable method is `add_growable_col`
145 146 147 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 145 def can_add_sizer_addable?(keyword) @wx.respond_to?(SizerProxy.sizer_addable_method(keyword)) end |
#content(&block) ⇒ Object
135 136 137 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 135 def content(&block) Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::SizerExpression.new, @keyword, {post_add_content: @content_added}, &block) end |
#post_add_content ⇒ Object
Subclasses may override to perform post add_content work (normally must call super)
110 111 112 113 114 115 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 110 def post_add_content unless @content_added @parent_proxy&.post_initialize_child(self) @content_added = true end end |
#post_initialize_child(child) ⇒ Object
Subclasses may override to perform post initialization work on an added child
118 119 120 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 118 def post_initialize_child(child) # No Op by default end |
#respond_to?(method_name, *args, &block) ⇒ Boolean
122 123 124 125 |
# File 'lib/glimmer/wx/sizer_proxy.rb', line 122 def respond_to?(method_name, *args, &block) @wx.respond_to?(method_name, true) || super(method_name, true) end |