Class: Interphase::Container
- Defined in:
- lib/interphase/widgets/basic_widgets.rb
Overview
A widget which may contain other widgets.
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
Attributes inherited from Widget
Instance Method Summary collapse
-
#add(child, should_add = true, &block) ⇒ Object
Add a widget as a child of this one.
-
#method_missing(requested, *args, &block) ⇒ Object
Allows child named widgets to be looked up like an attribute.
- #respond_to_missing? ⇒ Boolean
-
#show_all ⇒ Object
Show this widget and all of its children.
Methods inherited from Widget
#destroy, #initialize, #on, #show, #size
Constructor Details
This class inherits a constructor from Interphase::Widget
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(requested, *args, &block) ⇒ Object
Allows child named widgets to be looked up like an attribute. TODO IMPLEMENT RESPONDS_TO
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/interphase/widgets/basic_widgets.rb', line 96 def method_missing(requested, *args, &block) (children || []).each do |child| # An exception simply means that wasn't the child we were looking for begin return child.send(requested) rescue StandardError next end end super end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
68 69 70 |
# File 'lib/interphase/widgets/basic_widgets.rb', line 68 def children @children end |
Instance Method Details
#add(child, should_add = true, &block) ⇒ Object
Add a widget as a child of this one. Accepts a block which is executed on the child.
child-
The new child widget.
should_add-
(Optional) Whether to actually add the element, or just to register it as added by adding it to
children. You probably shouldn’t change this.
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/interphase/widgets/basic_widgets.rb', line 76 def add(child, should_add = true, &block) child.instance_eval(&block) if block_given? raise 'Widget already has a parent' unless child.parent.nil? gtk_instance.add(child.gtk_instance) if should_add child.parent = self # Ensure a children array exists, and add the new child to it @children ||= [] children << child end |
#respond_to_missing? ⇒ Boolean
109 110 111 |
# File 'lib/interphase/widgets/basic_widgets.rb', line 109 def respond_to_missing?(*) true end |
#show_all ⇒ Object
Show this widget and all of its children.
90 91 92 |
# File 'lib/interphase/widgets/basic_widgets.rb', line 90 def show_all gtk_instance.show_all end |