-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from zintus/pixel-grid-rounding
Rounding behaviour
- Loading branch information
Showing
4 changed files
with
84 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <gtest/gtest.h> | ||
#include <yoga/Yoga.h> | ||
|
||
// This test scrutinize next behaviours: | ||
// - pixel grid snapping in 1e4..0 coordinate range | ||
// - ability to layout nodes with smallest possible dimensions (one pixel separators) | ||
// - providing text node layout with bounds strictly larger than sized | ||
|
||
TEST(YogaTest, pixel_grid_rounding_table) { | ||
const float kPointScale = 3; | ||
|
||
const YGConfigRef config = YGConfigNew(); | ||
YGConfigSetPointScaleFactor(config, kPointScale); | ||
|
||
const float kSeparatorHeight = 1 / kPointScale; | ||
const float kCellContentHeight = 44.5; | ||
const int kCellsCount = 100; | ||
|
||
const YGNodeRef root = YGNodeNewWithConfig(config); | ||
|
||
int subnodesCount = 0; | ||
|
||
for (int i = 0; i < kCellsCount; i++) { | ||
const YGNodeRef separator = YGNodeNewWithConfig(config); | ||
YGNodeStyleSetHeight(separator, kSeparatorHeight); | ||
YGNodeInsertChild(root, separator, subnodesCount++); | ||
|
||
const YGNodeRef cell = YGNodeNewWithConfig(config); | ||
YGNodeSetNodeType(cell, YGNodeTypeText); | ||
YGNodeStyleSetHeight(cell, kCellContentHeight); | ||
YGNodeInsertChild(root, cell, subnodesCount++); | ||
} | ||
|
||
const YGNodeRef separator = YGNodeNewWithConfig(config); | ||
YGNodeStyleSetHeight(separator, kSeparatorHeight); | ||
YGNodeInsertChild(root, separator, subnodesCount++); | ||
|
||
YGNodeCalculateLayout(root, 375, YGUndefined, YGDirectionLTR); | ||
|
||
EXPECT_LE(kCellsCount * (kSeparatorHeight + kCellContentHeight) + kSeparatorHeight, YGNodeLayoutGetHeight(root)); | ||
EXPECT_FLOAT_EQ(375, YGNodeLayoutGetWidth(root)); | ||
|
||
for (int i = 0; i < YGNodeGetChildCount(root); i++) { | ||
const YGNodeRef child = YGNodeGetChild(root, i); | ||
const float childHeight = YGNodeLayoutGetHeight(child); | ||
|
||
if (YGNodeGetNodeType(child) == YGNodeTypeText) { | ||
EXPECT_GT(childHeight, kCellContentHeight); | ||
} else { | ||
EXPECT_GT(childHeight, 0); | ||
} | ||
} | ||
|
||
YGNodeFreeRecursive(root); | ||
|
||
YGConfigFree(config); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters