-
-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
216 additions
and
2 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
common/cpp/react/renderer/components/rnscreens/FrameCorrectionModes.h
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,51 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace rnscreens { | ||
|
||
/** | ||
* Flags describing types of corrections to apply to Screen frame | ||
* after layout process. | ||
*/ | ||
class FrameCorrectionModes final { | ||
public: | ||
enum Mode : std::uint8_t { | ||
/** | ||
* No correction should be applied to layout metrics of Screen | ||
*/ | ||
None = 0, | ||
|
||
/** | ||
* Screen's frame height should be corrected | ||
*/ | ||
FrameHeightCorrection = 1 << 0, | ||
|
||
/** | ||
* Screen's frame origin should be corrected | ||
*/ | ||
FrameOriginCorrection = 1 << 1, | ||
}; | ||
|
||
inline void set(Mode mode) { | ||
modes_ = Mode(modes_ | mode); | ||
} | ||
|
||
inline void unset(Mode mode) { | ||
modes_ = Mode(modes_ & ~mode); | ||
} | ||
|
||
// Check whether current set of flags contains all flags set in argument. | ||
inline bool check(Mode mode) const { | ||
return Mode(modes_ & mode) == mode; | ||
} | ||
|
||
inline Mode getAll() const { | ||
return modes_; | ||
} | ||
|
||
private: | ||
Mode modes_{Mode::None}; | ||
}; | ||
|
||
} // namespace rnscreens |
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
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
36 changes: 36 additions & 0 deletions
36
common/cpp/react/renderer/components/rnscreens/utils/RectUtil.h
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,36 @@ | ||
#pragma once | ||
|
||
#include <react/renderer/graphics/Float.h> | ||
#include <react/renderer/graphics/Size.h> | ||
#include <cmath> | ||
#include <concepts> | ||
|
||
namespace rnscreens { | ||
|
||
namespace react = facebook::react; | ||
|
||
template <typename T> | ||
requires std::is_floating_point_v<T> | ||
inline constexpr bool equalWithRespectToEps(const T a, const T b, const T eps) { | ||
return std::abs(a - b) <= eps; | ||
} | ||
|
||
/** | ||
* Compares given two frame sizes with respect to the epsilon. | ||
* | ||
* @param first first frame size | ||
* @param second second frame size | ||
* @param eps comparison precision, defaults to 0.01, which should ensure that | ||
* precision of comparison is under 1px | ||
* @return whether the frame dimensions are the same with respect to given | ||
* epsilon | ||
*/ | ||
inline constexpr bool checkFrameSizesEqualWithEps( | ||
const react::Size &first, | ||
const react::Size &second, | ||
const react::Float eps = 0.01) { | ||
return equalWithRespectToEps(first.width, second.width, eps) && | ||
equalWithRespectToEps(first.height, second.height, eps); | ||
} | ||
|
||
} // namespace rnscreens |