class Cura::Component::Pack
A component with children which moves and optionally resizes them. TODO: Expand attribute - See: www.pygtk.org/pygtk2tutorial/sec-DetailsOfBoxes.html TODO: I think the only time it needs to pack_children
is right before drawing? Would that get messy?
Attributes
Get the spacing between children.
@return [Integer]
Public Class Methods
Cura::Attributes::HasOrientation::new
# File lib/cura/component/pack.rb, line 14 def initialize(attributes={}) @fill = false @spacing = 0 super end
Public Instance Methods
Add a child to this group.
@param [#to_sym, Component] component_or_type
A Symbol representing the child component type or a {Component::Base} instance. When a Symbol is given, a new child component will be initialized of that type. See {Component::Base.type}.
@param [#to_h] attributes
When component_or_type is a Symbol, then these attributes will be used to initialize the child component. When component_or_type is a {Component::Base}, then these attributes will be used to update the child component.
@option options [#to_i] :expand
The new child is to be given extra space. The extra space will be divided evenly between all children that use this option.
@option options [#to_i] :fill
The space given to child by the expand option is actually allocated to child, rather than just padding it. This parameter has no effect if expand is set to false.
@return [Component]
Cura::Component::Group#add_child
# File lib/cura/component/pack.rb, line 53 def add_child(component_or_type, attributes={}) # TODO: :expand and :fill attributes? child = super pack_children child end
Remove a child from this object's children at the given index.
@param [#to_i] index @return [Component]
Cura::Component::Group#delete_child_at
# File lib/cura/component/pack.rb, line 66 def delete_child_at(index) child = super pack_children child end
Draw this pack.
@return [Pack]
Cura::Component::Group#draw
# File lib/cura/component/pack.rb, line 115 def draw pack_children # TODO: Should be in #update? super end
Set whether children will be filled. Must be truthy or falsey.
If set to a truthy value, children will be resized to fit the space available to it. For example, if orientation is set to :horizontal, then all of the children's width attributes will be set to this instance's width.
@param [Object] value @return [Boolean]
# File lib/cura/component/pack.rb, line 92 def fill=(value) @fill = !!value end
Get whether children will be filled. If this pack's orientation is set to :vertical, then the children's width will be set to this pack's width. If this pack's orientation is set to :horizontal, then the children's height will be set to this pack's width.
@return [Boolean]
# File lib/cura/component/pack.rb, line 79 def fill? @fill end
Set the height dimension of this pack.
# File lib/cura/component/pack.rb, line 31 def height=(value) result = super pack_children result end
Set the spacing between children.
@param [#to_i] value @return [Integer]
# File lib/cura/component/pack.rb, line 105 def spacing=(value) value = value.to_i value = 0 if value < 0 @spacing = value end
Set the width dimension of this pack.
# File lib/cura/component/pack.rb, line 22 def width=(value) result = super pack_children result end
Protected Instance Methods
Position and resize this pack's children based on it's attributes.
# File lib/cura/component/pack.rb, line 124 def pack_children child_x = 0 child_y = 0 children.each do |child| if horizontal? child.x = child_x child_x += child.width + child.offsets.width + spacing child.height = height if fill? elsif vertical? child.y = child_y if vertical? child_y += child.height + child.offsets.height + spacing child.width = width if fill? end end end