Browse Source

Absolutely positioned table cells

Michael Ragazzon 2 years ago
parent
commit
c6ff12ff3e

+ 2 - 4
Source/Core/Element.cpp

@@ -420,10 +420,8 @@ Vector2f Element::GetAbsoluteOffset(Box::Area area)
 				absolute_offset -= offset_parent->scroll_offset;
 
 			// Finally, there may be relatively positioned elements between ourself and our containing block, add their relative offsets as well.
-			// TODO: Uhm, this doesn't really make sense for absolutely positioned boxes. But then again, if we have a
-			// relative parent, then that should be our containing block. So I guess its fine?
-			for (Element* relative_parent = parent; relative_parent && relative_parent != offset_parent; relative_parent = relative_parent->parent)
-				absolute_offset += relative_parent->relative_offset_position;
+			for (Element* ancestor = parent; ancestor && ancestor != offset_parent; ancestor = ancestor->parent)
+				absolute_offset += ancestor->relative_offset_position;
 		}
 	}
 

+ 21 - 12
Source/Core/Layout/TableFormattingDetails.cpp

@@ -286,18 +286,27 @@ void TableGrid::PushRow(Element* element_row, ElementList cell_elements, TableWr
 			break;
 		}
 
-		// Add the new cell to our list.
-		open_cells.emplace_back();
-		Cell& cell = open_cells.back();
-
-		cell.element_cell = element_cell;
-		cell.row_begin = row_index;
-		cell.row_last = row_index + row_span - 1;
-		cell.column_begin = column;
-		cell.column_last = column_last;
-
-		if (element_cell->GetPosition() == Style::Position::Relative)
-			table_wrapper.AddRelativeElement(element_cell);
+		const Style::Position cell_position = element_cell->GetPosition();
+		if (cell_position == Style::Position::Absolute || cell_position == Style::Position::Fixed)
+		{
+			ContainerBox* containing_box = LayoutDetails::GetContainingBlock(&table_wrapper, cell_position).container;
+			containing_box->AddAbsoluteElement(element_cell, {}, table_wrapper.GetElement());
+		}
+		else
+		{
+			// Add the new cell to our list.
+			open_cells.emplace_back();
+			Cell& cell = open_cells.back();
+
+			cell.element_cell = element_cell;
+			cell.row_begin = row_index;
+			cell.row_last = row_index + row_span - 1;
+			cell.column_begin = column;
+			cell.column_last = column_last;
+
+			if (cell_position == Style::Position::Relative)
+				table_wrapper.AddRelativeElement(element_cell);
+		}
 
 		column += col_span;
 	}

+ 4 - 4
Source/Core/Layout/TableFormattingDetails.h

@@ -26,8 +26,8 @@
  *
  */
 
-#ifndef RMLUI_CORE_LAYOUT_TABLEDETAILS_H
-#define RMLUI_CORE_LAYOUT_TABLEDETAILS_H
+#ifndef RMLUI_CORE_LAYOUT_TABLEFORMATTINGDETAILS_H
+#define RMLUI_CORE_LAYOUT_TABLEFORMATTINGDETAILS_H
 
 #include "../../../Include/RmlUi/Core/StyleTypes.h"
 #include "../../../Include/RmlUi/Core/Types.h"
@@ -39,8 +39,8 @@ class TableWrapper;
 struct ComputedAxisSize;
 
 /*
-TableGrid builds the structure of the table, that is a list of rows, columns, and cells, taking
-spanning attributes into account to position cells.
+    TableGrid builds the structure of the table, that is a list of rows, columns, and cells, taking
+    spanning attributes into account to position cells.
 */
 class TableGrid {
 public: