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:



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

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:



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

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.



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

def draw
  super
  
  draw_children
end

#heightInteger

Get the height of this group.

Returns:

  • (Integer)


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

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.



60
61
62
63
64
# File 'lib/cura/component/group.rb', line 60

def update
  super
  
  update_children
end

#widthInteger

Get the width of this group.

Returns:

  • (Integer)


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

def width
  return @width unless @width == :auto
  return 0 if children.empty?
  
  children.collect { |child| child.x + child.width + child.offsets.width }.max
end