Class: Arrolio::Table::AutoLayout
- Inherits:
-
Object
- Object
- Arrolio::Table::AutoLayout
- Defined in:
- lib/arrolio/table/auto_layout.rb
Overview
Computes column widths for a Content::Table based on natural content widths. Each column gets at least its natural width (longest unbreakable token + padding). Remaining space is distributed proportionally to the column's natural width, so wider columns get more extra space.
If the total natural width exceeds the available width, columns are scaled down proportionally (each gets a share proportional to its natural width, but never below a minimum).
Constant Summary collapse
- MIN_COLUMN_WIDTH =
points — prevents columns from collapsing
20.0- CELL_PADDING =
points — left + right padding per cell
8.0
Instance Attribute Summary collapse
-
#available_width ⇒ Object
readonly
Returns the value of attribute available_width.
-
#measurer ⇒ Object
readonly
Returns the value of attribute measurer.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
-
#compute ⇒ Object
Returns an Array of Float widths (one per column), summing to
available_width. -
#initialize(table, available_width:, measurer: nil) ⇒ AutoLayout
constructor
A new instance of AutoLayout.
Constructor Details
#initialize(table, available_width:, measurer: nil) ⇒ AutoLayout
Returns a new instance of AutoLayout.
20 21 22 23 24 |
# File 'lib/arrolio/table/auto_layout.rb', line 20 def initialize(table, available_width:, measurer: nil) @table = table @available_width = available_width.to_f @measurer = measurer || default_measurer end |
Instance Attribute Details
#available_width ⇒ Object (readonly)
Returns the value of attribute available_width.
18 19 20 |
# File 'lib/arrolio/table/auto_layout.rb', line 18 def available_width @available_width end |
#measurer ⇒ Object (readonly)
Returns the value of attribute measurer.
18 19 20 |
# File 'lib/arrolio/table/auto_layout.rb', line 18 def measurer @measurer end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
18 19 20 |
# File 'lib/arrolio/table/auto_layout.rb', line 18 def table @table end |
Instance Method Details
#compute ⇒ Object
Returns an Array of Float widths (one per column), summing
to available_width.
28 29 30 31 32 33 |
# File 'lib/arrolio/table/auto_layout.rb', line 28 def compute return Array.new(column_count, @available_width / column_count) if column_count.zero? natural = natural_widths distribute(natural) end |