Module: Iup::AttributeBuilders

Included in:
CommonAttributes, DragDropAttributes, InternalDragDropAttributes, ScrollBarAttributes, Timer, Widget
Defined in:
lib/wrapped/attribute-builders.rb

Overview

methods to help construct attribute methods

Instance Method Summary collapse

Instance Method Details

#define_attribute(name) ⇒ Object

Given the name of an attribute, this method creates a new method which accepts an optional value. Providing the value will set the named attribute for this object, or else its current value will be returned.



11
12
13
14
15
16
17
18
19
20
# File 'lib/wrapped/attribute-builders.rb', line 11

def define_attribute name
  attribute = name.to_s.upcase
  define_method name do |val=nil|
    if val.nil?
      IupLib.IupGetAttribute(@handle, attribute).first
    else
      IupLib.IupSetAttribute @handle, attribute, val.to_s
    end
  end
end

#define_id_attribute(name) ⇒ Object

Given the name of an attribute, this method creates a new method requiring an id number as a parameter and an optional value. Providing the value will set the named attribute for this object using the id number, e.g. “ITEM1”, or else the current value will be returned. This supports attributes such as “ITEM1” “ITEM2” by making the id number a parameter.



46
47
48
49
50
51
52
53
54
55
# File 'lib/wrapped/attribute-builders.rb', line 46

def define_id_attribute name
  define_method name do |id, val=nil|
    attribute = "#{name}#{id}".upcase
    if val.nil?
      IupLib.IupGetAttribute(@handle, attribute).first
    else
      IupLib.IupSetAttribute @handle, attribute, val.to_s
    end
  end
end

#define_id_readonly(name) ⇒ Object

Given the name of an attribute, this method creates a new method requiring an id number as a parameter. The current value of the attribute name + id will be returned. This supports attributes such as “ITEM1” “ITEM2” by making the id number a parameter.



61
62
63
64
65
# File 'lib/wrapped/attribute-builders.rb', line 61

def define_id_readonly name
  define_method name do |id|
    IupLib.IupGetAttribute(@handle, "#{name}#{id}".upcase).first
  end
end

#define_id_writeonly(name) ⇒ Object

Given the name of an attribute, this method creates a new method requiring an id number as a parameter and a value. Providing the value will set the named attribute for this object using the id number, e.g. “ITEM1”. This supports attributes such as “ITEM1” “ITEM2” by making the id number a parameter.



72
73
74
75
76
# File 'lib/wrapped/attribute-builders.rb', line 72

def define_id_writeonly name
  define_method name do |id, val|
    IupLib.IupSetAttribute @handle, "#{name}#{id}".upcase, val.to_s
  end
end

#define_property_attribute(name) ⇒ Object

Given the name of an attribute, this method creates a new method taking a property name and an optional value. If given the value, the new method will set the attribute’s property to the value. Otherwise, the current value of the attribute’s property will be returned. This supports attributes such as “ITEM=val”, providing a parameter for the property name.



83
84
85
86
87
88
89
90
91
92
# File 'lib/wrapped/attribute-builders.rb', line 83

def define_property_attribute name
  attribute = name.to_s.upcase
  define_method name do |property, val=nil|
    if val.nil?
      IupLib.IupGetAttribute(@handle, attribute, property.upcase).first
    else
      IupLib.IupSetAttribute @handle, attribute, "#{property}=#{val}".upcase
    end
  end
end

#define_property_writeonly(name) ⇒ Object

Given the name of an attribute, this method creates a new method taking a property name and a value. The new method will set the attribute’s property to the value. This supports attributes such as “ITEM=val”, providing a parameter for the property name.



98
99
100
101
102
103
# File 'lib/wrapped/attribute-builders.rb', line 98

def define_property_writeonly name
  attribute = name.to_s.upcase
  define_method name do |property, val|
    IupLib.IupSetAttribute @handle, attribute, "#{property}=#{val}".upcase
  end
end

#define_readonly(name) ⇒ Object

Given the name of an attribute, this method creates a new method which returns its current value.



24
25
26
27
28
29
# File 'lib/wrapped/attribute-builders.rb', line 24

def define_readonly name
  attribute = name.to_s.upcase
  define_method name do
    IupLib.IupGetAttribute(@handle, attribute).first
  end
end

#define_writeonly(name) ⇒ Object

Given the name of an attribute, this method creates a new method which accepts a value and sets the named attribute for this object.



34
35
36
37
38
39
# File 'lib/wrapped/attribute-builders.rb', line 34

def define_writeonly name
  attribute = name.to_s.upcase
  define_method name do |val|
    IupLib.IupSetAttribute @handle, attribute, val
  end
end