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

Methods included from Attributes::HasVisibility

#initialize, #visible=, #visible?

Methods included from Attributes::HasAttributes

included, #initialize, #update_attributes

Methods included from Attributes::HasRelativeCoordinates

#absolute_x, #absolute_y, #initialize

Methods included from Attributes::HasCoordinates

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

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_or_type, attributes = {}) ⇒ Component

Add a child to this group and set it’s parent 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.

Returns:



54
55
56
57
58
59
60
# File 'lib/cura/component/group.rb', line 54

def add_child(component_or_type, attributes={})
  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:



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

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.



83
84
85
86
87
# File 'lib/cura/component/group.rb', line 83

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.



75
76
77
78
79
# File 'lib/cura/component/group.rb', line 75

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