Skip to content

Commit

Permalink
Added ability to hide preset browser search bar (#444)
Browse files Browse the repository at this point in the history
Co-authored-by: Christoph Hart <[email protected]>
  • Loading branch information
davidhealey and christoph-hart authored Oct 20, 2024
1 parent 8721d51 commit 9661c07
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions hi_core/hi_components/floating_layout/FrontendPanelTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ var PresetBrowserPanel::toDynamicObject() const
storePropertyInObject(obj, SpecialPanelIds::ShowAddButton, options.showAddButton);
storePropertyInObject(obj, SpecialPanelIds::ShowRenameButton, options.showRenameButton);
storePropertyInObject(obj, SpecialPanelIds::ShowDeleteButton, options.showDeleteButton);
storePropertyInObject(obj, SpecialPanelIds::ShowSearchBar, options.showSearchBar);
storePropertyInObject(obj, SpecialPanelIds::ShowFavoriteIcon, options.showFavoriteIcons);
storePropertyInObject(obj, SpecialPanelIds::FullPathFavorites, options.fullPathFavorites);
storePropertyInObject(obj, SpecialPanelIds::ButtonsInsideBorder, options.buttonsInsideBorder);
Expand All @@ -980,6 +981,7 @@ void PresetBrowserPanel::fromDynamicObject(const var& object)
options.showAddButton = getPropertyWithDefault(object, SpecialPanelIds::ShowAddButton);
options.showRenameButton = getPropertyWithDefault(object, SpecialPanelIds::ShowRenameButton);
options.showDeleteButton = getPropertyWithDefault(object, SpecialPanelIds::ShowDeleteButton);
options.showSearchBar = getPropertyWithDefault(object, SpecialPanelIds::ShowSearchBar);
options.fullPathFavorites = getPropertyWithDefault(object, SpecialPanelIds::FullPathFavorites);
options.buttonsInsideBorder = getPropertyWithDefault(object, SpecialPanelIds::ButtonsInsideBorder);
options.editButtonOffset = getPropertyWithDefault(object, SpecialPanelIds::EditButtonOffset);
Expand Down Expand Up @@ -1068,6 +1070,7 @@ juce::Identifier PresetBrowserPanel::getDefaultablePropertyId(int index) const
RETURN_DEFAULT_PROPERTY_ID(index, SpecialPanelIds::ShowAddButton, "ShowAddButton");
RETURN_DEFAULT_PROPERTY_ID(index, SpecialPanelIds::ShowRenameButton, "ShowRenameButton");
RETURN_DEFAULT_PROPERTY_ID(index, SpecialPanelIds::ShowDeleteButton, "ShowDeleteButton");
RETURN_DEFAULT_PROPERTY_ID(index, SpecialPanelIds::ShowSearchBar, "ShowSearchBar");
RETURN_DEFAULT_PROPERTY_ID(index, SpecialPanelIds::ButtonsInsideBorder, "ButtonsInsideBorder");
RETURN_DEFAULT_PROPERTY_ID(index, SpecialPanelIds::EditButtonOffset, "EditButtonOffset");
RETURN_DEFAULT_PROPERTY_ID(index, SpecialPanelIds::ListAreaOffset, "ListAreaOffset");
Expand Down Expand Up @@ -1103,6 +1106,7 @@ var PresetBrowserPanel::getDefaultProperty(int index) const
RETURN_DEFAULT_PROPERTY(index, SpecialPanelIds::ShowRenameButton, true);
RETURN_DEFAULT_PROPERTY(index, SpecialPanelIds::FullPathFavorites, false);
RETURN_DEFAULT_PROPERTY(index, SpecialPanelIds::ShowDeleteButton, true);
RETURN_DEFAULT_PROPERTY(index, SpecialPanelIds::ShowSearchBar, true);
RETURN_DEFAULT_PROPERTY(index, SpecialPanelIds::ButtonsInsideBorder, false);
RETURN_DEFAULT_PROPERTY(index, SpecialPanelIds::EditButtonOffset, 10);
RETURN_DEFAULT_PROPERTY(index, SpecialPanelIds::NumColumns, 3);
Expand Down
1 change: 1 addition & 0 deletions hi_core/hi_components/floating_layout/FrontendPanelTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ class PresetBrowserPanel : public FloatingTileContent,
ShowAddButton,
ShowRenameButton,
ShowDeleteButton,
ShowSearchBar,
ButtonsInsideBorder,
ColumnRowPadding,
SearchBarBounds,
Expand Down
20 changes: 16 additions & 4 deletions hi_core/hi_components/plugin_components/PresetBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,9 @@ void PresetBrowser::resized()
int y = 0;

const bool showCloseButton = closeButton->isVisible();
const bool showSearchBar = searchBar->isVisible();

if (searchBarBounds.size() == 4)
if (showSearchBar && searchBarBounds.size() == 4)
searchBar->setBounds((int)searchBarBounds[0], (int)searchBarBounds[1], (int)searchBarBounds[2], (int)searchBarBounds[3]);

if (showCloseButton)
Expand All @@ -827,7 +828,7 @@ void PresetBrowser::resized()
saveButton->setBounds(ar.removeFromRight(100));
manageButton->setBounds(ar.removeFromLeft(100));

if (searchBarBounds.size() != 4)
if (showSearchBar && searchBarBounds.size() != 4)
searchBar->setBounds(ar);

y += 40;
Expand Down Expand Up @@ -874,13 +875,13 @@ void PresetBrowser::resized()

ar.removeFromLeft(10);

if (searchBarBounds.size() != 4)
if (showSearchBar && searchBarBounds.size() != 4)
searchBar->setBounds(ar);

somethingInTopRow |= saveButton->isVisible();
somethingInTopRow |= manageButton->isVisible();
somethingInTopRow |= showFavoritesButton;
somethingInTopRow |= searchBar->getHeight() > 0;
somethingInTopRow |= showSearchBar && searchBar->getHeight() > 0;

if(somethingInTopRow)
y += 40;
Expand Down Expand Up @@ -1073,10 +1074,20 @@ void PresetBrowser::setShowFavorites(bool shouldShowFavorites)
showFavoritesButton = shouldShowFavorites;
}

void PresetBrowser::setShowSearchBar(bool shouldBeShown)
{
if (shouldBeShown != searchBar->isVisible())
{
searchBar->setVisible(shouldBeShown);
resized();
}
}

void PresetBrowser::setShowFullPathFavorites(bool shouldShowFullPathFavorites)
{
fullPathFavorites = shouldShowFullPathFavorites;
}

void PresetBrowser::setHighlightColourAndFont(Colour c, Colour bgColour, Font f)
{
auto& lf = getPresetBrowserLookAndFeel();
Expand Down Expand Up @@ -1297,6 +1308,7 @@ void PresetBrowser::setOptions(const Options& newOptions)
setShowEditButtons(1, newOptions.showAddButton);
setShowEditButtons(2, newOptions.showRenameButton);
setShowEditButtons(3, newOptions.showDeleteButton);
setShowSearchBar(newOptions.showSearchBar);
setButtonsInsideBorder(newOptions.buttonsInsideBorder);
setEditButtonOffset(newOptions.editButtonOffset);
setListAreaOffset(newOptions.listAreaOffset);
Expand Down
2 changes: 2 additions & 0 deletions hi_core/hi_components/plugin_components/PresetBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class PresetBrowser : public Component,
bool showAddButton = true;
bool showRenameButton = true;
bool showDeleteButton = true;
bool showSearchBar = true;
bool buttonsInsideBorder = false;
int editButtonOffset = 10;
Array<var> listAreaOffset;
Expand Down Expand Up @@ -258,6 +259,7 @@ class PresetBrowser : public Component,
void setShowButton(int buttonId, bool newValue);
void setShowNotesLabel(bool shouldBeShown);
void setShowEditButtons(int buttonId, bool showEditButtons);
void setShowSearchBar(bool shouldBeShown);
void setButtonsInsideBorder(bool inside);
void setEditButtonOffset(int offset);
void setListAreaOffset(Array<var> offset);
Expand Down

0 comments on commit 9661c07

Please sign in to comment.