diff options
author | Alec Mouri <alecmouri@google.com> | 2022-04-16 00:29:05 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2022-04-16 00:29:05 +0000 |
commit | 87d026acfc992c36b0f64a0061ba55add45f87df (patch) | |
tree | fa6bb7596b37b32c5fd3c18059d948039a472a6c /libs | |
parent | 617bcfefc4178814233c2d84e11dd240f51e6455 (diff) | |
parent | 168f6ccfce328a1224297ba5b7af2779fcee0d9a (diff) | |
download | native-87d026acfc992c36b0f64a0061ba55add45f87df.tar.gz |
Merge "Set better defaults for layer stack and oriented display space" into tm-dev
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ui/include/ui/Size.h | 12 | ||||
-rw-r--r-- | libs/ui/tests/Size_test.cpp | 32 |
2 files changed, 44 insertions, 0 deletions
diff --git a/libs/ui/include/ui/Size.h b/libs/ui/include/ui/Size.h index ecc192dcae..bdcbd569fc 100644 --- a/libs/ui/include/ui/Size.h +++ b/libs/ui/include/ui/Size.h @@ -23,6 +23,8 @@ #include <type_traits> #include <utility> +#include <ui/Rotation.h> + namespace android::ui { // A simple value type representing a two-dimensional size. @@ -61,6 +63,16 @@ struct Size { set(Size(w, h)); } + // Applies a rotation onto the size + void rotate(Rotation rotation) { + if (rotation == ROTATION_90 || rotation == ROTATION_270) { + transpose(); + } + } + + // Swaps the width and height, emulating a 90 degree rotation. + void transpose() { std::swap(width, height); } + // Sets the value to kInvalidSize void makeInvalid(); diff --git a/libs/ui/tests/Size_test.cpp b/libs/ui/tests/Size_test.cpp index acef47fb97..0a236e60e4 100644 --- a/libs/ui/tests/Size_test.cpp +++ b/libs/ui/tests/Size_test.cpp @@ -61,6 +61,38 @@ TEST(SizeTest, BasicLessThanComparison) { EXPECT_FALSE(Size(1, 1) < Size(1, 1)); } +TEST(SizeTest, Transpose) { + Size s(123, 456); + s.transpose(); + EXPECT_EQ(s, Size(456, 123)); +} + +TEST(SizeTest, Rotate) { + { + Size s(123, 456); + s.rotate(Rotation::Rotation0); + EXPECT_EQ(s, Size(123, 456)); + } + + { + Size s(123, 456); + s.rotate(Rotation::Rotation90); + EXPECT_EQ(s, Size(456, 123)); + } + + { + Size s(123, 456); + s.rotate(Rotation::Rotation180); + EXPECT_EQ(s, Size(123, 456)); + } + + { + Size s(123, 456); + s.rotate(Rotation::Rotation270); + EXPECT_EQ(s, Size(456, 123)); + } +} + TEST(SizeTest, ValidAndEmpty) { { Size s; |