From c20bcc1f08ea8546e54bd874ef3ada6bbc842899 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 12 Nov 2022 10:27:19 -0800 Subject: [PATCH] UI: Avoid enum/float comparisons. --- Common/UI/View.cpp | 6 +++--- Common/UI/View.h | 10 ++++------ Common/UI/ViewGroup.cpp | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 72d3443ab0..4ca46140a2 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -19,9 +19,9 @@ namespace UI { -const float ITEM_HEIGHT = 64.f; -const float MIN_TEXT_SCALE = 0.8f; -const float MAX_ITEM_SIZE = 65535.0f; +static constexpr Size ITEM_HEIGHT = 64.f; +static constexpr float MIN_TEXT_SCALE = 0.8f; +static constexpr float MAX_ITEM_SIZE = 65535.0f; void MeasureBySpec(Size sz, float contentWidth, MeasureSpec spec, float *measured) { *measured = sz; diff --git a/Common/UI/View.h b/Common/UI/View.h index 0a78433073..6e29c6bdef 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -128,10 +128,10 @@ enum FocusDirection { FOCUS_NEXT_PAGE, }; -enum { - WRAP_CONTENT = -1, - FILL_PARENT = -2, -}; +typedef float Size; // can also be WRAP_CONTENT or FILL_PARENT. + +static constexpr Size WRAP_CONTENT = -1.0f; +static constexpr Size FILL_PARENT = -2.0f; // Gravity enum Gravity { @@ -174,8 +174,6 @@ enum class BorderStyle { ITEM_DOWN_BG, }; -typedef float Size; // can also be WRAP_CONTENT or FILL_PARENT. - enum Orientation { ORIENT_HORIZONTAL, ORIENT_VERTICAL, diff --git a/Common/UI/ViewGroup.cpp b/Common/UI/ViewGroup.cpp index f4fb73ffa3..f90f0eb1a6 100644 --- a/Common/UI/ViewGroup.cpp +++ b/Common/UI/ViewGroup.cpp @@ -22,7 +22,7 @@ namespace UI { -const float ITEM_HEIGHT = 64.f; +static constexpr Size ITEM_HEIGHT = 64.f; void ApplyGravity(const Bounds outer, const Margins &margins, float w, float h, int gravity, Bounds &inner) { inner.w = w;