Files
react-native/ReactCommon/flexlayout/flexlayout/Dimension.h
T
J.T. Yim 4eec47344e Add flexlayout dirSync to react-native-github
Summary:
Changelog:
[Internal] Include FlexLayout C++ source to ReactCommons

Reviewed By: d16r, NickGerleman

Differential Revision: D38716145

fbshipit-source-id: 0ca2ab040e72168f2f1b479609b6cda2787eba66
2022-08-17 09:55:15 -07:00

68 lines
1.6 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <cmath>
#include "FlexLayoutEnums.h"
#include "FlexLayoutMacros.h"
#include "Type.h"
#ifdef DEBUG
#include <iosfwd>
#endif
namespace facebook {
namespace flexlayout {
#ifdef DEBUG
auto operator<<(std::ostream& os, const AlignContent& x) -> std::ostream&;
auto operator<<(std::ostream& os, const AlignItems& x) -> std::ostream&;
auto operator<<(std::ostream& os, const AlignSelf& x) -> std::ostream&;
auto operator<<(std::ostream& os, const Edge& x) -> std::ostream&;
auto operator<<(std::ostream& os, const PositionType& x) -> std::ostream&;
auto operator<<(std::ostream& os, const Display& x) -> std::ostream&;
#endif
namespace utils {
class Dimension {
public:
Dimension() {
value = NAN;
unit = Unit::Undefined;
}
explicit Dimension(const Float value, const Unit unit)
: value(value), unit(unit) {}
[[nodiscard]] auto resolve(const Float ownerSize) const -> Float {
switch (unit) {
case Unit::Point:
return value;
case Unit::Percent:
return value * ownerSize * 0.01f;
case Unit::Auto:
case Unit::Undefined:
return NAN;
}
}
FLEX_LAYOUT_EXPORT auto operator==(const Dimension& rhs) const -> bool;
auto operator!=(const Dimension& rhs) const -> bool;
Float value;
Unit unit;
};
#ifdef DEBUG
auto operator<<(std::ostream& os, const Dimension& x) -> std::ostream&;
#endif
} // namespace utils
} // namespace flexlayout
} // namespace facebook