Class: Engine::Components::UI::Flex

Inherits:
Engine::Component show all
Defined in:
lib/engine/components/ui/flex.rb

Instance Attribute Summary collapse

Attributes inherited from Engine::Component

#game_object

Instance Method Summary collapse

Methods inherited from Engine::Component

#_erase!, #destroy, #destroy!, #destroyed?, destroyed_components, erase_destroyed_components, method_added, #renderer?, #set_game_object, #ui_renderer?, #update

Methods included from Serializable

allowed_class?, get_class, included, register_class, #uuid

Instance Attribute Details

#directionObject (readonly)

Returns the value of attribute direction.



12
13
14
# File 'lib/engine/components/ui/flex.rb', line 12

def direction
  @direction
end

#gapObject (readonly)

Returns the value of attribute gap.



12
13
14
# File 'lib/engine/components/ui/flex.rb', line 12

def gap
  @gap
end

#justifyObject (readonly)

Returns the value of attribute justify.



12
13
14
# File 'lib/engine/components/ui/flex.rb', line 12

def justify
  @justify
end

Instance Method Details

#awakeObject



14
15
16
17
18
# File 'lib/engine/components/ui/flex.rb', line 14

def awake
  @direction ||= :row
  @gap ||= 0
  @justify ||= :stretch
end

#rect_for_child(child_ui_rect) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/engine/components/ui/flex.rb', line 25

def rect_for_child(child_ui_rect)
  children = child_ui_rects
  index = children.index(child_ui_rect)
  return nil unless index

  parent_rect = @ui_rect.computed_rect
  layout.rect_for_child(child_ui_rect, index, children, parent_rect)
end

#startObject



20
21
22
23
# File 'lib/engine/components/ui/flex.rb', line 20

def start
  @ui_rect = game_object.component(UI::Rect)
  raise "UI::Flex requires a UI::Rect component on the same GameObject" unless @ui_rect
end