fix absolut position when padding in place

This commit is contained in:
Lukas Wöhrl
2020-06-11 17:45:45 +02:00
parent ede65bbce4
commit 1e1e5cb477
3 changed files with 56 additions and 19 deletions

View File

@@ -88,3 +88,7 @@
<div style="width:20px; height:20px; position: absolute; align-self: flex-end;"></div>
</div>
<div id="absolute_layout_percentage_from_padded_parent" style="flex-direction:column; width:750px; height:1000px; padding-top: 100px; border-top: 100px;">
<div style="width:750px; height:50%; position: absolute;"></div>
</div>

View File

@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*/
// @Generated by gentest/gentest.rb from
// @Generated by gentest/gentest.rb from
// gentest/fixtures/YGAbsolutePositionTest.html
#include <gtest/gtest.h>
@@ -184,9 +184,7 @@ TEST(YogaTest, absolute_layout_width_height_start_top_end_bottom) {
YGConfigFree(config);
}
TEST(
YogaTest,
do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent) {
TEST(YogaTest, do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
@@ -578,9 +576,7 @@ TEST(YogaTest, absolute_layout_align_items_center_on_child_only) {
YGConfigFree(config);
}
TEST(
YogaTest,
absolute_layout_align_items_and_justify_content_center_and_top_position) {
TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_top_position) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
@@ -625,9 +621,7 @@ TEST(
YGConfigFree(config);
}
TEST(
YogaTest,
absolute_layout_align_items_and_justify_content_center_and_bottom_position) {
TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_bottom_position) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
@@ -672,9 +666,7 @@ TEST(
YGConfigFree(config);
}
TEST(
YogaTest,
absolute_layout_align_items_and_justify_content_center_and_left_position) {
TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_left_position) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
@@ -719,9 +711,7 @@ TEST(
YGConfigFree(config);
}
TEST(
YogaTest,
absolute_layout_align_items_and_justify_content_center_and_right_position) {
TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_right_position) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
@@ -1039,3 +1029,46 @@ TEST(YogaTest, absolute_layout_in_wrap_reverse_row_container_flex_end) {
YGConfigFree(config);
}
TEST(YogaTest, absolute_layout_percentage_from_padded_parent) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetPadding(root, YGEdgeTop, 100);
YGNodeStyleSetBorder(root, YGEdgeTop, 100);
YGNodeStyleSetWidth(root, 750);
YGNodeStyleSetHeight(root, 1000);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute);
YGNodeStyleSetWidth(root_child0, 750);
YGNodeStyleSetHeightPercent(root_child0, 50);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(750, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(1000, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(750, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root_child0));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(750, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(1000, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(750, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root_child0));
YGNodeFreeRecursive(root);
YGConfigFree(config);
}

View File

@@ -2656,7 +2656,7 @@ static void YGJustifyMainAxis(
} else if (performLayout) {
child->setLayoutPosition(
childLayout.position[pos[mainAxis]] +
node->getLeadingBorder(mainAxis) + leadingMainDim,
node->getLeadingPadding(mainAxis, ownerWidth).unwrap() + leadingMainDim,
pos[mainAxis]);
}
}
@@ -3563,9 +3563,9 @@ static void YGNodelayoutImpl(
YGNodeAbsoluteLayoutChild(
node,
child,
availableInnerWidth,
availableWidth,
isMainAxisRow ? measureModeMainDim : measureModeCrossDim,
availableInnerHeight,
availableHeight,
direction,
config,
layoutMarkerData,