Class: Cura::Component::Group

Inherits:
Base
  • Object
show all
Includes:
Attributes::HasChildren
Defined in:
lib/cura/component/group.rb

Overview

A component with children. When children are added, their parent will be set to this group.

Direct Known Subclasses

Pack, Scrollbar

Instance Attribute Summary

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::HasChildren

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

Methods inherited from Base

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

Methods included from Attributes::HasRelativeCoordinates

#absolute_x, #absolute_y, #initialize

Methods included from Attributes::HasCoordinates

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

Methods included from Attributes::HasAttributes

included, #initialize, #update_attributes

Methods included from Attributes::HasAncestry

#ancestors, #initialize, #parent?

Methods included from Attributes::HasOffsets

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

Methods included from Attributes::HasColors

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

Methods included from Attributes::HasFocusability

#focusable=, #focusable?, #initialize

Methods included from Attributes::HasEvents

included, #initialize, #on_event

Methods included from Attributes::HasDimensions

#height=, #initialize, #resize, #width=

Methods included from Attributes::HasInitialize

#initialize

Instance Method Details

#add_child(component) ⇒ Component

Add a child to this group and set it’s parent to this Group.

Parameters:

Returns:



37
38
39
40
41
42
43
# File 'lib/cura/component/group.rb', line 37

def add_child(component)
  component = super

  component.parent = self

  component
end

#delete_child_at(index) ⇒ Component

Remove a child from this object’s children at the given index and set it’s parent to nil.

Parameters:

  • index (Integer)

Returns:



49
50
51
52
53
54
55
# File 'lib/cura/component/group.rb', line 49

def delete_child_at(index)
  component = super

  component.parent = nil

  component
end

#drawObject

Draw all children relative to this location. TODO: If the dimensions of this group of this group are less than the computed dimensions, the drawing will be clipped.



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

def draw
  super

  draw_children
end

#heightInteger

Get the height of this group.

Returns:

  • (Integer)


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

def height
  return @height unless @height == :auto
  return 0 if children.empty?

  children.collect { |child| child.y + child.height + child.offsets.height }.max
end

#updateObject

Update all children.



58
59
60
61
62
# File 'lib/cura/component/group.rb', line 58

def update
  super

  update_children
end

#widthInteger

Get the width of this group.

Returns:

  • (Integer)


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

def width
  return @width unless @width == :auto
  return 0 if children.empty?

  children.collect { |child| child.x + child.width + child.offsets.width }.max
end