Module: Wx::KeywordConstructor::ClassMethods

Defined in:
lib/wx/keyword_ctors.rb

Constant Summary collapse

STANDARD_DEFAULTS =

Common Wx constructor argument keywords, with their default values.

{
  :id        => -1,
  :size      => Wx::DEFAULT_SIZE,
  :pos       => Wx::DEFAULT_POSITION,
  :style     => 0,
  :title     => '',
  :validator => Wx::DEFAULT_VALIDATOR,
  :choices   => [] # for Choice, ComboBox etc
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#param_specObject



110
111
112
# File 'lib/wx/keyword_ctors.rb', line 110

def param_spec
  @param_spec ||= []
end

Instance Method Details

#args_as_hash(*mixed_args) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/wx/keyword_ctors.rb', line 135

def args_as_hash(*mixed_args)
  kwa = mixed_args.last.kind_of?(Hash) ? mixed_args.pop : {}
  param_spec.zip(mixed_args) do | param, arg |
    kwa[param.name] = arg if arg
  end
  kwa 
end

#args_as_list(*mixed_args) ⇒ Object



131
132
133
# File 'lib/wx/keyword_ctors.rb', line 131

def args_as_list(*mixed_args)
  Wx::args_as_list(param_spec, *mixed_args)
end

#describe_constructorObject



143
144
145
146
147
# File 'lib/wx/keyword_ctors.rb', line 143

def describe_constructor()
  param_spec.inject("") do | desc, param |
    desc << ":#{param.name} => (#{param.default.class.name})\n"
  end
end

#wx_ctor_params(*params) ⇒ Object

Adds a list of named parameters params to the parameter specification for this Wx class’s constructor. Each parameter should be specified as a either a common known symbol, such as :size or :pos: or :style: (corresponding to the common constructor arguments in WxWidgets API), or a single-key with the key the name of the argument, and the value a default value.

Parameters should be specified in the order they occur in the Wx API constructor



123
124
125
126
127
128
129
# File 'lib/wx/keyword_ctors.rb', line 123

def wx_ctor_params(*params)
  self.param_spec += params.map do | param |
    param.kind_of?(Hash) ? 
      Parameter[ param.keys.first, param.values.first ] : 
      Parameter[ param, STANDARD_DEFAULTS[param] ]
  end
end