From cea62a839947e55c3e1ab715b4b62ad53630840f Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 29 Jan 2025 17:47:50 +0000 Subject: [PATCH] Codechange: Use EnumBitSet for AspectFlags. --- src/widget.cpp | 4 ++-- src/widget_type.h | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/widget.cpp b/src/widget.cpp index 9dfe2b9e9d..6e083da6b0 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -932,8 +932,8 @@ void NWidgetBase::ApplyAspectRatio() uint x = this->smallest_x; uint y = this->smallest_y; - if (HasFlag(this->aspect_flags, AspectFlags::ResizeX)) x = std::max(this->smallest_x, static_cast(this->smallest_y * std::abs(this->aspect_ratio))); - if (HasFlag(this->aspect_flags, AspectFlags::ResizeY)) y = std::max(this->smallest_y, static_cast(this->smallest_x / std::abs(this->aspect_ratio))); + if (this->aspect_flags.Test(AspectFlag::ResizeX)) x = std::max(this->smallest_x, static_cast(this->smallest_y * std::abs(this->aspect_ratio))); + if (this->aspect_flags.Test(AspectFlag::ResizeY)) y = std::max(this->smallest_y, static_cast(this->smallest_x / std::abs(this->aspect_ratio))); this->smallest_x = x; this->smallest_y = y; diff --git a/src/widget_type.h b/src/widget_type.h index f7e50eb860..974d872003 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -113,12 +113,11 @@ enum SizingType : uint8_t { ST_RESIZE, ///< Resize the nested widget tree. }; -enum class AspectFlags : uint8_t { - ResizeX = 1U << 0, - ResizeY = 1U << 1, - ResizeXY = ResizeX | ResizeY, +enum class AspectFlag : uint8_t { + ResizeX, + ResizeY, }; -DECLARE_ENUM_AS_BIT_SET(AspectFlags) +using AspectFlags = EnumBitSet; /* Forward declarations. */ class NWidgetCore; @@ -235,7 +234,7 @@ public: uint current_x; ///< Current horizontal size (after resizing). uint current_y; ///< Current vertical size (after resizing). float aspect_ratio = 0; ///< Desired aspect ratio of widget. - AspectFlags aspect_flags = AspectFlags::ResizeX; ///< Which dimensions can be resized. + AspectFlags aspect_flags = AspectFlag::ResizeX; ///< Which dimensions can be resized. int pos_x; ///< Horizontal position of top-left corner of the widget in the window. int pos_y; ///< Vertical position of top-left corner of the widget in the window. @@ -302,8 +301,8 @@ public: void SetMinimalTextLines(uint8_t min_lines, uint8_t spacing, FontSize size); void SetFill(uint fill_x, uint fill_y); void SetResize(uint resize_x, uint resize_y); - void SetAspect(float ratio, AspectFlags flags = AspectFlags::ResizeX); - void SetAspect(int x_ratio, int y_ratio, AspectFlags flags = AspectFlags::ResizeX); + void SetAspect(float ratio, AspectFlags flags = AspectFlag::ResizeX); + void SetAspect(int x_ratio, int y_ratio, AspectFlags flags = AspectFlag::ResizeX); bool UpdateMultilineWidgetSize(const std::string &str, int max_lines); bool UpdateSize(uint min_x, uint min_y); @@ -1360,7 +1359,7 @@ constexpr NWidgetPart SetScrollbar(WidgetID index) * @param flags Dimensions which should be resized. * @ingroup NestedWidgetParts */ -constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags = AspectFlags::ResizeX) +constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags = AspectFlag::ResizeX) { return NWidgetPart{WPT_ASPECT, NWidgetPartAspect{ratio, flags}}; }