Sha256: 4b5871fc2c0d4d662bef3f443fbed3e4b0e2bc3e3f816893d95bc730eea0ec2d

Contents?: true

Size: 1.1 KB

Versions: 25

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module DrawioDsl
  # The layout engine is responsible for laying out the elements on the page.
  #
  # The layout engine can automatically place elements on the page.
  #
  # It will keep track of layout boundaries, current position and flow direction.
  # Elements will be placed on the page in the order they are added.
  # Row/column flow objects will hold information about horizontal and vertical element padding
  class LayoutEngine
    attr_reader :page

    attr_reader :current_page
    attr_reader :current_layout

    def initialize(page)
      @page = page
    end

    def call
      page.position_x = page.margin_left
      page.position_y = page.margin_top

      page.nodes.all.each do |node|
        traverse_node(node)
      end
    end

    def traverse_node(node)
      process_node(node)
      node.nodes.all.each do |child|
        traverse_node(child)
      end
    end

    def process_node(node)
      case node.classification
      when :layout_rule
        @current_layout = node
      when :shape
        current_layout&.position_shape(node)
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
drawio_dsl-0.11.7 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.11.6 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.11.5 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.11.4 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.11.3 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.11.2 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.11.1 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.11.0 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.10.1 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.10.0 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.9.0 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.8.11 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.8.10 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.8.9 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.8.8 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.8.7 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.8.6 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.8.5 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.8.4 lib/drawio_dsl/layout_engine.rb
drawio_dsl-0.8.3 lib/drawio_dsl/layout_engine.rb