Class: HexaPDF::Layout::TableBox::Cell
- Defined in:
- lib/hexapdf/layout/table_box.rb
Overview
Represents a single cell of the table.
A cell is a container box that fits and draws its children with a BoxFitter. Its dimensions (width and height) are not determined by its children but by the table layout algorithm. Furthermore, its style can be used for drawing e.g. a cell border.
Cell borders work similar to the separated borders model of CSS, i.e. each cell has its own borders that do not overlap.
Constant Summary
Constants included from Utils
Instance Attribute Summary collapse
-
#children ⇒ Object
The boxes to layout inside this cell.
-
#col_span ⇒ Object
readonly
The number of columns this cell spans.
-
#column ⇒ Object
readonly
The 0-based column number of the cell.
-
#left ⇒ Object
The x-coordinate of the cell’s top-left corner.
-
#preferred_height ⇒ Object
readonly
The preferred height of the cell, determined during #fit.
-
#preferred_width ⇒ Object
readonly
The preferred width of the cell, determined during #fit.
-
#row ⇒ Object
readonly
The 0-based row number of the cell.
-
#row_span ⇒ Object
readonly
The number of rows this cell spans.
-
#top ⇒ Object
The y-coordinate of the cell’s top-left corner.
Attributes inherited from Box
#fit_result, #height, #properties, #style, #width
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Returns
true
if the cell has no content. -
#initialize(row:, column:, children: nil, row_span: nil, col_span: nil, **kwargs) ⇒ Cell
constructor
Creates a new Cell instance.
-
#inspect ⇒ Object
:nodoc:.
-
#update_height(height) ⇒ Object
Updates the height of the box to the given value.
Methods inherited from Box
#content_height, #content_width, create, #draw, #fit, #split, #split_box?, #supports_position_flow?
Constructor Details
#initialize(row:, column:, children: nil, row_span: nil, col_span: nil, **kwargs) ⇒ Cell
Creates a new Cell instance.
194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/hexapdf/layout/table_box.rb', line 194 def initialize(row:, column:, children: nil, row_span: nil, col_span: nil, **kwargs) super(**kwargs, width: 0, height: 0) @children = children @row = row @column = column @row_span = row_span || 1 @col_span = col_span || 1 style.border.width.set(1) unless style.border? style.border.draw_on_bounds = true style.padding.set(5) unless style.padding? end |
Instance Attribute Details
#children ⇒ Object
The boxes to layout inside this cell.
This may either be nil
(if the cell has no content), a single Box instance or an array of Box instances.
191 192 193 |
# File 'lib/hexapdf/layout/table_box.rb', line 191 def children @children end |
#col_span ⇒ Object (readonly)
The number of columns this cell spans.
185 186 187 |
# File 'lib/hexapdf/layout/table_box.rb', line 185 def col_span @col_span end |
#column ⇒ Object (readonly)
The 0-based column number of the cell.
179 180 181 |
# File 'lib/hexapdf/layout/table_box.rb', line 179 def column @column end |
#left ⇒ Object
The x-coordinate of the cell’s top-left corner.
The coordinate is relative to the table’s content rectangle, with positive x-axis going to the right and positive y-axis going to the bottom.
This value is set by the parent Cells object during fitting and may therefore only be relied on afterwards.
158 159 160 |
# File 'lib/hexapdf/layout/table_box.rb', line 158 def left @left end |
#preferred_height ⇒ Object (readonly)
The preferred height of the cell, determined during #fit.
173 174 175 |
# File 'lib/hexapdf/layout/table_box.rb', line 173 def preferred_height @preferred_height end |
#preferred_width ⇒ Object (readonly)
The preferred width of the cell, determined during #fit.
170 171 172 |
# File 'lib/hexapdf/layout/table_box.rb', line 170 def preferred_width @preferred_width end |
#row ⇒ Object (readonly)
The 0-based row number of the cell.
176 177 178 |
# File 'lib/hexapdf/layout/table_box.rb', line 176 def row @row end |
#row_span ⇒ Object (readonly)
The number of rows this cell spans.
182 183 184 |
# File 'lib/hexapdf/layout/table_box.rb', line 182 def row_span @row_span end |
#top ⇒ Object
The y-coordinate of the cell’s top-left corner.
The coordinate is relative to the table’s content rectangle, with positive x-axis going to the right and positive y-axis going to the bottom.
This value is set by the parent Cells object during fitting and may therefore only be relied on afterwards.
167 168 169 |
# File 'lib/hexapdf/layout/table_box.rb', line 167 def top @top end |
Instance Method Details
#empty? ⇒ Boolean
Returns true
if the cell has no content.
207 208 209 |
# File 'lib/hexapdf/layout/table_box.rb', line 207 def empty? super && (!@fit_results || @fit_results.empty?) end |
#inspect ⇒ Object
:nodoc:
222 223 224 |
# File 'lib/hexapdf/layout/table_box.rb', line 222 def inspect "<Cell (#{row},#{column}) #{row_span}x#{col_span} #{Array(children).map(&:class)}>" end |
#update_height(height) ⇒ Object
Updates the height of the box to the given value.
The height
has to be greater than or equal to the fitted height.
214 215 216 217 218 219 |
# File 'lib/hexapdf/layout/table_box.rb', line 214 def update_height(height) if height < @height raise HexaPDF::Error, "Given height needs to be at least as big as fitted height" end @height = height end |