Class: Ea::Svg::EaEmitter::Element::CompartmentGeometry

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/svg/ea_emitter/element/compartment_geometry.rb

Overview

Y-coordinate calculator for the compartments of an element box: header text, header divider, attribute rows, operation rows, enum literals, tagged-value rows.

Owns its own coordinate math; the rest of Elements only reads header_first_y, divider_y, attr_first_y, etc. Construction takes the bounds, font size, line counts, and per-region offsets from the theme.

Extracted from Elements.rb to keep each concern in one place (MECE). Element rendering reads these values; coordinate math changes don't ripple into rendering.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bounds:, size:, header_lines_count:, attr_lines_count:, op_lines_count:, tagged_values_count:, header_top_padding: 9, header_line_offset: 6, divider_offset: 8, attr_line_offset: 4, attr_first_offset: 7) ⇒ CompartmentGeometry

Returns a new instance of CompartmentGeometry.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 27

def initialize(bounds:, size:, header_lines_count:,
                attr_lines_count:, op_lines_count:,
                tagged_values_count:,
                header_top_padding: 9,
                header_line_offset: 6,
                divider_offset: 8,
                attr_line_offset: 4,
                attr_first_offset: 7)
  @bounds = bounds
  @size = size
  @header_lines_count = header_lines_count
  @attr_lines_count = attr_lines_count
  @op_lines_count = op_lines_count
  @tagged_values_count = tagged_values_count
  @header_top_padding = header_top_padding
  @header_line_offset = header_line_offset
  @divider_offset = divider_offset
  @attr_line_offset = attr_line_offset
  @attr_first_offset = attr_first_offset
end

Instance Attribute Details

#attr_first_offsetObject (readonly)

Returns the value of attribute attr_first_offset.



20
21
22
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 20

def attr_first_offset
  @attr_first_offset
end

#attr_line_offsetObject (readonly)

Returns the value of attribute attr_line_offset.



20
21
22
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 20

def attr_line_offset
  @attr_line_offset
end

#attr_lines_countObject (readonly)

Returns the value of attribute attr_lines_count.



20
21
22
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 20

def attr_lines_count
  @attr_lines_count
end

#boundsObject (readonly)

Returns the value of attribute bounds.



20
21
22
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 20

def bounds
  @bounds
end

#divider_offsetObject (readonly)

Returns the value of attribute divider_offset.



20
21
22
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 20

def divider_offset
  @divider_offset
end

#header_line_offsetObject (readonly)

Returns the value of attribute header_line_offset.



20
21
22
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 20

def header_line_offset
  @header_line_offset
end

#header_lines_countObject (readonly)

Returns the value of attribute header_lines_count.



20
21
22
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 20

def header_lines_count
  @header_lines_count
end

#header_top_paddingObject (readonly)

Returns the value of attribute header_top_padding.



20
21
22
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 20

def header_top_padding
  @header_top_padding
end

#op_lines_countObject (readonly)

Returns the value of attribute op_lines_count.



20
21
22
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 20

def op_lines_count
  @op_lines_count
end

#sizeObject (readonly)

Returns the value of attribute size.



20
21
22
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 20

def size
  @size
end

#tagged_values_countObject (readonly)

Returns the value of attribute tagged_values_count.



20
21
22
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 20

def tagged_values_count
  @tagged_values_count
end

Instance Method Details

#attr_bottom_yObject



69
70
71
72
73
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 69

def attr_bottom_y
  return attr_first_y unless attr_lines_count&.positive?

  attr_first_y + (attr_lines_count - 1) * (size + (attr_line_offset || 4))
end

#attr_first_yObject



63
64
65
66
67
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 63

def attr_first_y
  return bounds.y + size + (header_top_padding || 9) + 12 unless divider_y

  divider_y + size + (attr_first_offset || 7)
end

#divider_yObject

Y of the divider line between header and the rest. Returns nil when there's no header content to separate from empty below-header content.



55
56
57
58
59
60
61
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 55

def divider_y
  return nil if header_lines_count.zero?

  header_first_y +
    ([header_lines_count, 1].max - 1) * (size + (header_line_offset || 6)) +
    (divider_offset || 8)
end

#enum_divider_yObject



91
92
93
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 91

def enum_divider_y
  op_bottom_y + size + 5
end

#enum_literal_first_yObject



95
96
97
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 95

def enum_literal_first_y
  enum_divider_y + size + 5
end

#header_first_yObject



48
49
50
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 48

def header_first_y
  bounds.y + size + (header_top_padding || 9)
end

#op_bottom_yObject



85
86
87
88
89
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 85

def op_bottom_y
  return op_divider_y unless op_lines_count&.positive?

  op_first_y + (op_lines_count - 1) * (size + 4)
end

#op_divider_yObject



75
76
77
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 75

def op_divider_y
  attr_bottom_y + size + 5
end

#op_first_yObject



79
80
81
82
83
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 79

def op_first_y
  return nil unless op_lines_count&.positive?

  op_divider_y + size + 5
end

#tagged_value_first_yObject

Tagged values appear after attributes (or after ops if present). EA does not emit a separate divider — the italic "tags" header marks the compartment.



102
103
104
105
106
107
108
# File 'lib/ea/svg/ea_emitter/element/compartment_geometry.rb', line 102

def tagged_value_first_y
  return nil unless tagged_values_count&.positive?

  base = attr_bottom_y
  base = op_bottom_y if op_lines_count&.positive?
  base + size + 5
end