Skip to content

Commit

Permalink
Merge pull request #317 from steinbergmedia/bugfix/coptionmenu-get-ra…
Browse files Browse the repository at this point in the history
…nge-and-max

fix COptionMenu().getMax()
  • Loading branch information
scheffle authored Jan 5, 2024
2 parents dc31b4a + b8c32f8 commit 24f7973
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions vstgui/lib/controls/coptionmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,14 @@ void COptionMenu::setValue (float val)
setDirty ();
}

//------------------------------------------------------------------------
float COptionMenu::getMax () const
{
if (menuItems->empty ())
return 0.f;
return static_cast<float> (menuItems->size () - 1);
}

//------------------------------------------------------------------------
void COptionMenu::takeFocus ()
{
Expand Down
2 changes: 1 addition & 1 deletion vstgui/lib/controls/coptionmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class COptionMenu : public CParamDisplay
void setMin (float val) override {}
float getMin () const override { return 0; }
void setMax (float val) override {}
float getMax () const override { return (float)(menuItems->size () - 1); }
float getMax () const override;

void draw (CDrawContext* pContext) override;
CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override;
Expand Down
6 changes: 6 additions & 0 deletions vstgui/tests/unittest/lib/controls/coptionmenu_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ TEST_CASE (CCommandMenuItemTest, DescConstructor3)
EXPECT_EQ (item.getCommandName (), "CommandNme");
}

TEST_CASE (COptionMenuTest, GetMaxWhenEmpty)
{
COptionMenu menu;
EXPECT_EQ (menu.getMax (), 0.f);
}

} // VSTGUI

0 comments on commit 24f7973

Please sign in to comment.