Class: Glimmer::SWT::GSWT
- Inherits:
-
Object
- Object
- Glimmer::SWT::GSWT
- Defined in:
- lib/glimmer/swt/g_swt.rb
Constant Summary collapse
- ERROR_INVALID_STYLE =
" is an invalid SWT style! Please choose a style from org.eclipse.swt.SWT class constants."
- EXTRA_STYLES =
{ NO_RESIZE: GSWT[:shell_trim] & (~GSWT[:resize]) & (~GSWT[:max]) }
Class Method Summary collapse
-
.[](*symbols) ⇒ Object
Gets SWT constants as if calling SWT::CONSTANT where constant is passed in as a lower case symbol.
-
.constant(symbol) ⇒ Object
Returns SWT style integer value for passed in symbol or allows passed in object to pass through (e.g. Integer).
- .constantify_args(args) ⇒ Object
-
.deconstruct(integer) ⇒ Object
Deconstructs a style integer into symbols Useful for debugging.
- .has_constant?(symbol) ⇒ Boolean
Class Method Details
.[](*symbols) ⇒ Object
Gets SWT constants as if calling SWT::CONSTANT where constant is passed in as a lower case symbol
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/glimmer/swt/g_swt.rb', line 10 def [](*symbols) symbols.compact.reduce(0) do |output, symbol| constant_value = constant(symbol) if constant_value.is_a?(Integer) output | constant(symbol) else raise symbol.to_s + ERROR_INVALID_STYLE end end end |
.constant(symbol) ⇒ Object
Returns SWT style integer value for passed in symbol or allows passed in object to pass through (e.g. Integer). This makes is convenient to use symbols or actual SWT style integers in Glimmer Does not raise error for invalid values. Just lets them pass as is. (look into [] operator if you want an error raised on invalid values)
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/glimmer/swt/g_swt.rb', line 26 def constant(symbol) return symbol unless symbol.is_a?(Symbol) || symbol.is_a?(String) symbol_string = symbol.to_s swt_constant_symbol = symbol_string.downcase == symbol_string ? symbol_string.upcase.to_sym : symbol_string.to_sym SWT.const_get(swt_constant_symbol) rescue begin alternative_swt_constant_symbol = SWT.constants.find {|c| c.to_s.upcase == swt_constant_symbol.to_s.upcase} SWT.const_get(alternative_swt_constant_symbol) rescue EXTRA_STYLES[swt_constant_symbol] || symbol end end |
.constantify_args(args) ⇒ Object
45 46 47 |
# File 'lib/glimmer/swt/g_swt.rb', line 45 def constantify_args(args) args.map {|arg| constant(arg)} end |
.deconstruct(integer) ⇒ Object
Deconstructs a style integer into symbols Useful for debugging
51 52 53 54 55 56 57 |
# File 'lib/glimmer/swt/g_swt.rb', line 51 def deconstruct(integer) SWT.constants.reduce([]) do |found, c| constant_value = SWT.const_get(c) rescue -1 is_found = constant_value.is_a?(Integer) && (constant_value & style) == constant_value is_found ? found += [c] : found end end |
.has_constant?(symbol) ⇒ Boolean
40 41 42 43 |
# File 'lib/glimmer/swt/g_swt.rb', line 40 def has_constant?(symbol) return false unless symbol.is_a?(Symbol) || symbol.is_a?(String) constant(symbol).is_a?(Integer) end |