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.
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/hexapdf/layout/table_box.rb', line 187 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.
184 185 186 |
# File 'lib/hexapdf/layout/table_box.rb', line 184 def children @children end |
#col_span ⇒ Object (readonly)
The number of columns this cell spans.
178 179 180 |
# File 'lib/hexapdf/layout/table_box.rb', line 178 def col_span @col_span end |
#column ⇒ Object (readonly)
The 0-based column number of the cell.
172 173 174 |
# File 'lib/hexapdf/layout/table_box.rb', line 172 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.
151 152 153 |
# File 'lib/hexapdf/layout/table_box.rb', line 151 def left @left end |
#preferred_height ⇒ Object (readonly)
The preferred height of the cell, determined during #fit.
166 167 168 |
# File 'lib/hexapdf/layout/table_box.rb', line 166 def preferred_height @preferred_height end |
#preferred_width ⇒ Object (readonly)
The preferred width of the cell, determined during #fit.
163 164 165 |
# File 'lib/hexapdf/layout/table_box.rb', line 163 def preferred_width @preferred_width end |
#row ⇒ Object (readonly)
The 0-based row number of the cell.
169 170 171 |
# File 'lib/hexapdf/layout/table_box.rb', line 169 def row @row end |
#row_span ⇒ Object (readonly)
The number of rows this cell spans.
175 176 177 |
# File 'lib/hexapdf/layout/table_box.rb', line 175 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.
160 161 162 |
# File 'lib/hexapdf/layout/table_box.rb', line 160 def top @top end |
Instance Method Details
#empty? ⇒ Boolean
Returns true
if the cell has no content.
200 201 202 |
# File 'lib/hexapdf/layout/table_box.rb', line 200 def empty? super && (!@fit_results || @fit_results.empty?) end |
#inspect ⇒ Object
:nodoc:
215 216 217 |
# File 'lib/hexapdf/layout/table_box.rb', line 215 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.
207 208 209 210 211 212 |
# File 'lib/hexapdf/layout/table_box.rb', line 207 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 |