Sha256: a3913b6f67981c2b521c11aff127ca6d8541b5f48c84108621a396ea37832824

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 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 :diagram

    attr_reader :current_page
    attr_reader :current_layout
    attr_reader :page_margin_top
    attr_reader :page_margin_left
    attr_reader :x
    attr_reader :y

    def initialize(diagram)
      @diagram = diagram
      @x = 0
      @y = 0
    end

    def call
      diagram.pages.each do |page|
        focus_on_page(page)

        apply_layout_to_page(page)
      end
    end

    private

    def focus_on_page(page)
      @current_page   = page
      page.position_x = page.margin_left
      page.position_y = page.margin_top
    end

    def apply_layout_to_page(page)
      page.nodes.each do |node|
        case node.classification
        when :layout_rule
          @current_layout = node
        when :shape
          current_layout.position_shape(node)
        end
        node.debug(format: :row)
      end
    end

    def define_layout_rule(layout_rule)
      layout_rule.debug
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
drawio_dsl-0.2.0 lib/drawio_dsl/layout_engine.rb