mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibWeb: Move FFC layout algorithm step 14 to a separate function
This commit is contained in:
parent
e590e17b8a
commit
6d433c99f4
2 changed files with 33 additions and 26 deletions
|
@ -127,32 +127,7 @@ void FlexFormattingContext::run(Box& flex_container, LayoutMode)
|
||||||
// FIXME: This
|
// FIXME: This
|
||||||
|
|
||||||
// 14. Align all flex items along the cross-axis
|
// 14. Align all flex items along the cross-axis
|
||||||
// FIXME: Get the alignment via "align-self" of the item (which accesses "align-items" of the parent if unset)
|
align_all_flex_items_along_the_cross_axis(flex_container, flex_lines);
|
||||||
// FIXME: Take better care of margins
|
|
||||||
float line_cross_offset = 0;
|
|
||||||
for (auto& flex_line : flex_lines) {
|
|
||||||
for (auto* flex_item : flex_line.items) {
|
|
||||||
switch (flex_container.computed_values().align_items()) {
|
|
||||||
case CSS::AlignItems::Baseline:
|
|
||||||
// FIXME: Implement this
|
|
||||||
// Fallthrough
|
|
||||||
case CSS::AlignItems::FlexStart:
|
|
||||||
case CSS::AlignItems::Stretch:
|
|
||||||
flex_item->cross_offset = line_cross_offset + flex_item->margins.cross_before;
|
|
||||||
break;
|
|
||||||
case CSS::AlignItems::FlexEnd:
|
|
||||||
flex_item->cross_offset = line_cross_offset + flex_line.cross_size - flex_item->cross_size;
|
|
||||||
break;
|
|
||||||
case CSS::AlignItems::Center:
|
|
||||||
flex_item->cross_offset = line_cross_offset + (flex_line.cross_size / 2.0f) - (flex_item->cross_size / 2.0f);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
line_cross_offset += flex_line.cross_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 15. Determine the flex container’s used cross size:
|
// 15. Determine the flex container’s used cross size:
|
||||||
if (has_definite_cross_size(flex_container)) {
|
if (has_definite_cross_size(flex_container)) {
|
||||||
|
@ -950,4 +925,34 @@ void FlexFormattingContext::distribute_any_remaining_free_space(Box const& flex_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FlexFormattingContext::align_all_flex_items_along_the_cross_axis(Box const& flex_container, Vector<FlexLine>& flex_lines)
|
||||||
|
{
|
||||||
|
// FIXME: Get the alignment via "align-self" of the item (which accesses "align-items" of the parent if unset)
|
||||||
|
// FIXME: Take better care of margins
|
||||||
|
float line_cross_offset = 0;
|
||||||
|
for (auto& flex_line : flex_lines) {
|
||||||
|
for (auto* flex_item : flex_line.items) {
|
||||||
|
switch (flex_container.computed_values().align_items()) {
|
||||||
|
case CSS::AlignItems::Baseline:
|
||||||
|
// FIXME: Implement this
|
||||||
|
// Fallthrough
|
||||||
|
case CSS::AlignItems::FlexStart:
|
||||||
|
case CSS::AlignItems::Stretch:
|
||||||
|
flex_item->cross_offset = line_cross_offset + flex_item->margins.cross_before;
|
||||||
|
break;
|
||||||
|
case CSS::AlignItems::FlexEnd:
|
||||||
|
flex_item->cross_offset = line_cross_offset + flex_line.cross_size - flex_item->cross_size;
|
||||||
|
break;
|
||||||
|
case CSS::AlignItems::Center:
|
||||||
|
flex_item->cross_offset = line_cross_offset + (flex_line.cross_size / 2.0f) - (flex_item->cross_size / 2.0f);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
line_cross_offset += flex_line.cross_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,8 @@ private:
|
||||||
|
|
||||||
void distribute_any_remaining_free_space(Box const& flex_container, Vector<FlexLine>&, float main_available_size);
|
void distribute_any_remaining_free_space(Box const& flex_container, Vector<FlexLine>&, float main_available_size);
|
||||||
|
|
||||||
|
void align_all_flex_items_along_the_cross_axis(Box const& flex_container, Vector<FlexLine>&);
|
||||||
|
|
||||||
bool is_row_layout() const { return m_flex_direction == CSS::FlexDirection::Row || m_flex_direction == CSS::FlexDirection::RowReverse; }
|
bool is_row_layout() const { return m_flex_direction == CSS::FlexDirection::Row || m_flex_direction == CSS::FlexDirection::RowReverse; }
|
||||||
|
|
||||||
CSS::FlexDirection m_flex_direction {};
|
CSS::FlexDirection m_flex_direction {};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue