diff --git a/vstgui/lib/controls/clistcontrol.cpp b/vstgui/lib/controls/clistcontrol.cpp index b129495f2..5b1abeea3 100644 --- a/vstgui/lib/controls/clistcontrol.cpp +++ b/vstgui/lib/controls/clistcontrol.cpp @@ -187,7 +187,9 @@ void CListControl::drawRect (CDrawContext* context, const CRect& updateRect) rowSize.setHeight (impl->rowDescriptions[row].height); if (updateRect.rectOverlap (rowSize)) { - int32_t flags = selectedRow == row ? IListControlDrawer::Row::Selected : 0; + IListControlDrawer::Row::Flags flags; + if (selectedRow == row) + flags = IListControlDrawer::Row::Selected; if (impl->rowDescriptions[row].flags & CListControlRowDesc::Selectable) flags |= IListControlDrawer::Row::Selectable; if (impl->hoveredRow && *impl->hoveredRow == row + getMinRowIndex ()) diff --git a/vstgui/lib/controls/clistcontrol.h b/vstgui/lib/controls/clistcontrol.h index d4e6d773e..319025550 100644 --- a/vstgui/lib/controls/clistcontrol.h +++ b/vstgui/lib/controls/clistcontrol.h @@ -5,6 +5,7 @@ #pragma once #include "../optional.h" +#include "../enumbitset.h" #include "ccontrol.h" //------------------------------------------------------------------------ @@ -84,20 +85,22 @@ class CListControl final : public CControl //------------------------------------------------------------------------ struct CListControlRowDesc { - enum Flags + enum Flag : uint32_t { /** Indicates that the row is selectable */ Selectable = 1 << 0, /** Indicates that the row should be redrawn when the mouse hovers it */ Hoverable = 1 << 1, }; + using Flags = EnumBitset; + /** The height of the row */ CCoord height {0}; /** The flags of the row, see the Flags enum above */ - int32_t flags {Selectable}; + Flags flags {Selectable}; CListControlRowDesc () = default; - CListControlRowDesc (CCoord h, int32_t f) : height (h), flags (f) {} + CListControlRowDesc (CCoord h, Flags f) : height (h), flags (f) {} }; //------------------------------------------------------------------------ @@ -115,13 +118,14 @@ class IListControlDrawer : virtual public IReference struct Row { - enum + enum Flag : uint32_t { Selectable = 1 << 0, Selected = 1 << 1, Hovered = 1 << 2, LastRow = 1 << 3, }; + using Flags = EnumBitset; operator int32_t () const { return getIndex (); } int32_t getIndex () const { return index; } @@ -131,11 +135,11 @@ class IListControlDrawer : virtual public IReference bool isHovered () const { return (flags & Hovered) != 0; } bool isLastRow () const { return (flags & LastRow) != 0; } - Row (int32_t index, int32_t flags) : index (index), flags (flags) {} + Row (int32_t index, Flags flags) : index (index), flags (flags) {} private: int32_t index; - int32_t flags; + Flags flags; }; virtual void drawBackground (CDrawContext* context, CRect size) = 0; @@ -168,23 +172,25 @@ class StaticListControlConfigurator : public IListControlConfigurator, public NonAtomicReferenceCounted { public: + using Flags = CListControlRowDesc::Flags; + StaticListControlConfigurator (CCoord inRowHeight, - int32_t inFlags = CListControlRowDesc::Selectable | - CListControlRowDesc::Hoverable) + Flags inFlags = {CListControlRowDesc::Selectable, + CListControlRowDesc::Hoverable}) : rowHeight (inRowHeight), flags (inFlags) { } void setRowHeight (CCoord height) { rowHeight = height; } - void setFlags (int32_t f) { flags = f; } + void setFlags (Flags f) { flags = f; } CCoord getRowHeight () const { return rowHeight; } - int32_t getFlags () const { return flags; } + Flags getFlags () const { return flags; } CListControlRowDesc getRowDesc (int32_t row) const override { return {rowHeight, flags}; } private: CCoord rowHeight; - int32_t flags; + Flags flags; }; //------------------------------------------------------------------------ diff --git a/vstgui/standalone/examples/standalone/source/testappdelegate.cpp b/vstgui/standalone/examples/standalone/source/testappdelegate.cpp index ca7cafefa..c55faf287 100644 --- a/vstgui/standalone/examples/standalone/source/testappdelegate.cpp +++ b/vstgui/standalone/examples/standalone/source/testappdelegate.cpp @@ -151,7 +151,7 @@ class WeekdaysListConfigurator : public StaticListControlConfigurator CListControlRowDesc getRowDesc (int32_t row) const override { if (row == 0) - return {getRowHeight () * 2., 0}; + return {getRowHeight () * 2., {}}; return {getRowHeight (), getFlags ()}; } }; diff --git a/vstgui/tests/unittest/lib/controls/clistcontrol_test.cpp b/vstgui/tests/unittest/lib/controls/clistcontrol_test.cpp index 5d23e1136..73c74f3fe 100644 --- a/vstgui/tests/unittest/lib/controls/clistcontrol_test.cpp +++ b/vstgui/tests/unittest/lib/controls/clistcontrol_test.cpp @@ -11,9 +11,10 @@ namespace VSTGUI { //------------------------------------------------------------------------ -static SharedPointer createTestListControl ( - CCoord rowHeight, int32_t numRows = 10, - int32_t rowFlags = CListControlRowDesc::Selectable | CListControlRowDesc::Hoverable) +static SharedPointer + createTestListControl (CCoord rowHeight, int32_t numRows = 10, + CListControlRowDesc::Flags rowFlags = CListControlRowDesc::Flags { + CListControlRowDesc::Selectable | CListControlRowDesc::Hoverable}) { auto listControl = makeOwned (CRect (0, 0, 100, 100)); auto config = makeOwned (rowHeight, rowFlags); @@ -121,7 +122,7 @@ TEST_CASE (CListControlTest, KeyDownOnUnselectableRows) { constexpr auto rowHeight = 20; constexpr auto numRows = 20; - auto listControl = createTestListControl (rowHeight, numRows, 0); + auto listControl = createTestListControl (rowHeight, numRows, {}); listControl->setValue (2.f); EXPECT (listControl->getValue () == 2.f); @@ -135,7 +136,7 @@ TEST_CASE (CListControlTest, KeyWithModifier) { constexpr auto rowHeight = 20; constexpr auto numRows = 20; - auto listControl = createTestListControl (rowHeight, numRows, 0); + auto listControl = createTestListControl (rowHeight, numRows, {}); listControl->setValue (1.f); diff --git a/vstgui/uidescription/viewcreator/stringlistcontrolcreator.cpp b/vstgui/uidescription/viewcreator/stringlistcontrolcreator.cpp index 5bf025dc2..f0df54fd4 100644 --- a/vstgui/uidescription/viewcreator/stringlistcontrolcreator.cpp +++ b/vstgui/uidescription/viewcreator/stringlistcontrolcreator.cpp @@ -147,9 +147,12 @@ bool StringListControlCreator::apply (CView* view, const UIAttributes& attribute configurator->setRowHeight (d); bool b; if (attributes.getBooleanAttribute (kAttrStyleHover, b)) - configurator->setFlags (CListControlRowDesc::Selectable | - (b ? CListControlRowDesc::Hoverable : 0)); - + { + CListControlRowDesc::Flags f (CListControlRowDesc::Selectable); + if (b) + f |= CListControlRowDesc::Hoverable; + configurator->setFlags (f); + } control->invalid (); control->recalculateLayout ();