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, #inspect, #pencil, #update

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.



16
17
18
19
20
21
22
# File 'lib/cura/component/pack.rb', line 16

def initialize(attributes={})
  @fill = false
  @spacing = 0
  
  # @child_modifiers
  super
end

Instance Attribute Details

#spacingInteger

Get the spacing between children.

Returns:

  • (Integer)


97
98
99
# File 'lib/cura/component/pack.rb', line 97

def spacing
  @spacing
end

Instance Method Details

#add_child(component) ⇒ Component

Add a child to this group.

Parameters:

  • component (Component)
  • options (#to_hash, #to_h)

Returns:



52
53
54
55
56
57
58
# File 'lib/cura/component/pack.rb', line 52

def add_child(component)
  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:



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

def delete_child_at(index)
  child = super

  pack_children

  child
end

#drawPack

Draw this pack.

Returns:



113
114
115
116
117
# File 'lib/cura/component/pack.rb', line 113

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)


90
91
92
# File 'lib/cura/component/pack.rb', line 90

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)


77
78
79
# File 'lib/cura/component/pack.rb', line 77

def fill?
  @fill
end

#height=(value) ⇒ Object

Set the height dimension of this pack.



34
35
36
37
38
39
40
# File 'lib/cura/component/pack.rb', line 34

def height=(value)
  result = super

  pack_children

  result
end

#width=(value) ⇒ Object

Set the width dimension of this pack.



25
26
27
28
29
30
31
# File 'lib/cura/component/pack.rb', line 25

def width=(value)
  result = super

  pack_children

  result
end