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
trueif the cell has no content. -
#initialize(row:, column:, children: nil, min_height: 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, min_height: nil, row_span: nil, col_span: nil, **kwargs) ⇒ Cell
Creates a new Cell instance.
214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/hexapdf/layout/table_box.rb', line 214 def initialize(row:, column:, children: nil, min_height: 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 @min_height = min_height 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.
211 212 213 |
# File 'lib/hexapdf/layout/table_box.rb', line 211 def children @children end |
#col_span ⇒ Object (readonly)
The number of columns this cell spans.
205 206 207 |
# File 'lib/hexapdf/layout/table_box.rb', line 205 def col_span @col_span end |
#column ⇒ Object (readonly)
The 0-based column number of the cell.
199 200 201 |
# File 'lib/hexapdf/layout/table_box.rb', line 199 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.
178 179 180 |
# File 'lib/hexapdf/layout/table_box.rb', line 178 def left @left end |
#preferred_height ⇒ Object (readonly)
The preferred height of the cell, determined during #fit.
193 194 195 |
# File 'lib/hexapdf/layout/table_box.rb', line 193 def preferred_height @preferred_height end |
#preferred_width ⇒ Object (readonly)
The preferred width of the cell, determined during #fit.
190 191 192 |
# File 'lib/hexapdf/layout/table_box.rb', line 190 def preferred_width @preferred_width end |
#row ⇒ Object (readonly)
The 0-based row number of the cell.
196 197 198 |
# File 'lib/hexapdf/layout/table_box.rb', line 196 def row @row end |
#row_span ⇒ Object (readonly)
The number of rows this cell spans.
202 203 204 |
# File 'lib/hexapdf/layout/table_box.rb', line 202 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.
187 188 189 |
# File 'lib/hexapdf/layout/table_box.rb', line 187 def top @top end |
Instance Method Details
#empty? ⇒ Boolean
Returns true if the cell has no content.
228 229 230 |
# File 'lib/hexapdf/layout/table_box.rb', line 228 def empty? super && (!@fit_results || @fit_results.empty?) end |
#inspect ⇒ Object
:nodoc:
243 244 245 |
# File 'lib/hexapdf/layout/table_box.rb', line 243 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.
235 236 237 238 239 240 |
# File 'lib/hexapdf/layout/table_box.rb', line 235 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 |