Class: Cura::Component::Pack

Inherits:
Group show all
Includes:
Attributes::HasOrientation
Defined in:
lib/cura/component/pack.rb

Overview

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?

Direct Known Subclasses

Listbox

Instance Attribute Summary collapse

Attributes included from Attributes::HasOrientation

#orientation

Attributes included from Attributes::HasAncestry

#parent

Attributes included from Attributes::HasOffsets

#offsets

Attributes included from Attributes::HasEvents

#event_handler

Instance Method Summary collapse

Methods included from Attributes::HasOrientation

#horizontal?, #vertical?

Methods included from Attributes::HasAttributes

included, #update_attributes

Methods inherited from Group

#height, #update, #width

Methods included from Attributes::HasChildren

#add_children, #children, #children?, #delete_child, #delete_children, #each

Methods inherited from Base

#application, #background, #contains_coordinates?, #cursor, #focus, #focused?, #foreground, inherited, #inspect, #pencil, type, #update

Methods included from Attributes::HasVisibility

#visible=, #visible?

Methods included from Attributes::HasRelativeCoordinates

#absolute_x, #absolute_y

Methods included from Attributes::HasCoordinates

#x, #x=, #y, #y=

Methods included from Attributes::HasAncestry

#ancestors, #parent?

Methods included from Attributes::HasOffsets

#border, #border=, #margin, #margin=, #padding, #padding=

Methods included from Attributes::HasColors

#background, #background=, #foreground, #foreground=

Methods included from Attributes::HasFocusability

#focusable=, #focusable?

Methods included from Attributes::HasEvents

included, #on_event

Methods included from Attributes::HasDimensions

#height, #resize, #width

Constructor Details

#initialize(attributes = {}) ⇒ Pack

Returns a new instance of Pack.



14
15
16
17
18
19
# File 'lib/cura/component/pack.rb', line 14

def initialize(attributes={})
  @fill = false
  @spacing = 0

  super
end

Instance Attribute Details

#spacingInteger

Get the spacing between children.

Returns:

  • (Integer)


99
100
101
# File 'lib/cura/component/pack.rb', line 99

def spacing
  @spacing
end

Instance Method Details

#add_child(component_or_type, attributes = {}) ⇒ Component

Add a child to this group.

Parameters:

  • component_or_type (#to_sym, Component)

    A Symbol representing the child component type or a Base instance. When a Symbol is given, a new child component will be initialized of that type. See Base.type.

  • attributes (#to_h) (defaults to: {})

    When component_or_type is a Symbol, then these attributes will be used to initialize the child component. When component_or_type is a Base, then these attributes will be used to update the child component.

  • options (Hash)

    a customizable set of options

Returns:



53
54
55
56
57
58
59
60
# 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

#delete_child_at(index) ⇒ Component

Remove a child from this object’s children at the given index.

Parameters:

  • index (#to_i)

Returns:



66
67
68
69
70
71
72
# File 'lib/cura/component/pack.rb', line 66

def delete_child_at(index)
  child = super

  pack_children

  child
end

#drawPack

Draw this pack.

Returns:



115
116
117
118
119
# File 'lib/cura/component/pack.rb', line 115

def draw
  pack_children

  super
end

#fill=(value) ⇒ Boolean

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.

Parameters:

  • value (Object)

Returns:

  • (Boolean)


92
93
94
# File 'lib/cura/component/pack.rb', line 92

def fill=(value)
  @fill = !!value
end

#fill?Boolean

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.

Returns:

  • (Boolean)


79
80
81
# File 'lib/cura/component/pack.rb', line 79

def fill?
  @fill
end

#height=(value) ⇒ Object

Set the height dimension of this pack.



31
32
33
34
35
36
37
# File 'lib/cura/component/pack.rb', line 31

def height=(value)
  result = super

  pack_children

  result
end

#width=(value) ⇒ Object

Set the width dimension of this pack.



22
23
24
25
26
27
28
# File 'lib/cura/component/pack.rb', line 22

def width=(value)
  result = super

  pack_children

  result
end