Skip to content

Commit

Permalink
C++ style enums 7/N: MeasureMode (facebook#1389)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#39452

Pull Request resolved: facebook#1389

This converts usages of YGMeasureMode to MeasureMode

Reviewed By: rozele

Differential Revision: D49271165

fbshipit-source-id: a6ab7509a3f74bc6e1c42c0ce3376e1e7447f4dd
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 15, 2023
1 parent c4d0b6a commit 22bee6e
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 180 deletions.
2 changes: 1 addition & 1 deletion tests/YGNodeCallbackTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TEST(Node, measure_with_measure_fn) {
});

ASSERT_EQ(
n.measure(23, YGMeasureModeExactly, 24, YGMeasureModeAtMost),
n.measure(23, MeasureMode::Exactly, 24, MeasureMode::AtMost),
(YGSize{23, 12}));
}

Expand Down
8 changes: 4 additions & 4 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,13 +905,13 @@ bool YGNodeCanUseCachedMeasurement(
float marginColumn,
YGConfigRef config) {
return yoga::canUseCachedMeasurement(
widthMode,
scopedEnum(widthMode),
availableWidth,
heightMode,
scopedEnum(heightMode),
availableHeight,
lastWidthMode,
scopedEnum(lastWidthMode),
lastAvailableWidth,
lastHeightMode,
scopedEnum(lastHeightMode),
lastAvailableHeight,
lastComputedWidth,
lastComputedHeight,
Expand Down
30 changes: 14 additions & 16 deletions yoga/algorithm/Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,50 @@
* LICENSE file in the root directory of this source tree.
*/

#include <yoga/Yoga.h>

#include <yoga/algorithm/Cache.h>
#include <yoga/algorithm/PixelGrid.h>
#include <yoga/numeric/Comparison.h>

namespace facebook::yoga {

static inline bool sizeIsExactAndMatchesOldMeasuredSize(
YGMeasureMode sizeMode,
MeasureMode sizeMode,
float size,
float lastComputedSize) {
return sizeMode == YGMeasureModeExactly &&
return sizeMode == MeasureMode::Exactly &&
yoga::inexactEquals(size, lastComputedSize);
}

static inline bool oldSizeIsUnspecifiedAndStillFits(
YGMeasureMode sizeMode,
MeasureMode sizeMode,
float size,
YGMeasureMode lastSizeMode,
MeasureMode lastSizeMode,
float lastComputedSize) {
return sizeMode == YGMeasureModeAtMost &&
lastSizeMode == YGMeasureModeUndefined &&
return sizeMode == MeasureMode::AtMost &&
lastSizeMode == MeasureMode::Undefined &&
(size >= lastComputedSize || yoga::inexactEquals(size, lastComputedSize));
}

static inline bool newMeasureSizeIsStricterAndStillValid(
YGMeasureMode sizeMode,
MeasureMode sizeMode,
float size,
YGMeasureMode lastSizeMode,
MeasureMode lastSizeMode,
float lastSize,
float lastComputedSize) {
return lastSizeMode == YGMeasureModeAtMost &&
sizeMode == YGMeasureModeAtMost && !std::isnan(lastSize) &&
return lastSizeMode == MeasureMode::AtMost &&
sizeMode == MeasureMode::AtMost && !std::isnan(lastSize) &&
!std::isnan(size) && !std::isnan(lastComputedSize) && lastSize > size &&
(lastComputedSize <= size || yoga::inexactEquals(size, lastComputedSize));
}

bool canUseCachedMeasurement(
const YGMeasureMode widthMode,
const MeasureMode widthMode,
const float availableWidth,
const YGMeasureMode heightMode,
const MeasureMode heightMode,
const float availableHeight,
const YGMeasureMode lastWidthMode,
const MeasureMode lastWidthMode,
const float lastAvailableWidth,
const YGMeasureMode lastHeightMode,
const MeasureMode lastHeightMode,
const float lastAvailableHeight,
const float lastComputedWidth,
const float lastComputedHeight,
Expand Down
10 changes: 5 additions & 5 deletions yoga/algorithm/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

#pragma once

#include <yoga/Yoga.h>
#include <yoga/config/Config.h>
#include <yoga/enums/MeasureMode.h>

namespace facebook::yoga {

bool canUseCachedMeasurement(
YGMeasureMode widthMode,
MeasureMode widthMode,
float availableWidth,
YGMeasureMode heightMode,
MeasureMode heightMode,
float availableHeight,
YGMeasureMode lastWidthMode,
MeasureMode lastWidthMode,
float lastAvailableWidth,
YGMeasureMode lastHeightMode,
MeasureMode lastHeightMode,
float lastAvailableHeight,
float lastComputedWidth,
float lastComputedHeight,
Expand Down
Loading

0 comments on commit 22bee6e

Please sign in to comment.