Class: Glimmer::Wx::SizerProxy
- Inherits:
-
Object
- Object
- Glimmer::Wx::SizerProxy
show all
- 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
Class Method Summary
collapse
Instance Method Summary
collapse
#data_bind, #data_bind_read, #data_bind_write, #data_binding_model_attribute_observer_registrations
Constructor Details
#initialize(keyword, parent, args, &block) ⇒ SizerProxy
96
97
98
99
100
101
102
103
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 96
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
123
124
125
126
127
128
129
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 123
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
wx returns the contained LibUI object
93
94
95
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 93
def args
@args
end
|
#block ⇒ Object
wx returns the contained LibUI object
93
94
95
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 93
def block
@block
end
|
#content_added ⇒ Object
Also known as:
content_added?
wx returns the contained LibUI object
93
94
95
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 93
def content_added
@content_added
end
|
#keyword ⇒ Object
wx returns the contained LibUI object
93
94
95
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 93
def keyword
@keyword
end
|
#parent_proxy ⇒ Object
wx returns the contained LibUI object
93
94
95
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 93
def parent_proxy
@parent_proxy
end
|
#wx ⇒ Object
wx returns the contained LibUI object
93
94
95
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 93
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
68
69
70
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 68
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
64
65
66
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 64
def keyword(constant_symbol)
constant_symbol.to_s.underscore.sub(/_proxy$/, '')
end
|
.map_descendant_keyword_constants_for(klass, accumulator: {}) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 77
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
72
73
74
75
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 72
def reset_descendant_keyword_constant_map
@descendant_keyword_constant_map = nil
descendant_keyword_constant_map
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
135
136
137
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 135
def add(control_proxy, *args, &block)
@wx.add(control_proxy.wx, *args)
end
|
#content(&block) ⇒ Object
131
132
133
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 131
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)
106
107
108
109
110
111
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 106
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
114
115
116
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 114
def post_initialize_child(child)
end
|
#respond_to?(method_name, *args, &block) ⇒ Boolean
118
119
120
121
|
# File 'lib/glimmer/wx/sizer_proxy.rb', line 118
def respond_to?(method_name, *args, &block)
@wx.respond_to?(method_name, true) ||
super(method_name, true)
end
|