Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch search UI updates #7954

Merged
merged 7 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 53 additions & 33 deletions src/surge-xt/gui/widgets/PatchSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ struct PatchDBTypeAheadProvider : public TypeAheadDataProvider,
{
SurgeStorage *storage{nullptr};
PatchSelector *selector{nullptr};

PatchDBTypeAheadProvider(PatchSelector *s) : selector(s) {}

std::vector<PatchStorage::PatchDB::patchRecord> lastSearchResult;
std::vector<int> searchFor(const std::string &s) override
{
std::cout << "search for " << s << "\n";
lastSearchResult = storage->patchDB->queryFromQueryString(s);
std::vector<int> res(lastSearchResult.size());
std::iota(res.begin(), res.end(), 0);
Expand All @@ -76,8 +78,8 @@ struct PatchDBTypeAheadProvider : public TypeAheadDataProvider,
return "<<ERROR>>";
}

int getRowHeight() override { return 23; }
int getDisplayedRows() override { return 12; }
int getRowHeight() override { return 28; }
int getDisplayedRows() override { return 11; }

juce::Colour rowBg{juce::Colours::white}, hlRowBg{juce::Colours::lightblue},
rowText{juce::Colours::black}, hlRowText{juce::Colours::red},
Expand All @@ -87,56 +89,51 @@ struct PatchDBTypeAheadProvider : public TypeAheadDataProvider,
void paintDataItem(int searchIndex, juce::Graphics &g, int width, int height,
bool rowIsSelected) override
{
bool isMouseOver = selector->typeAhead->isRowMouseOver(searchIndex);

g.fillAll(rowBg);
if (rowIsSelected)
{
auto r = juce::Rectangle<int>(0, 0, width, height).reduced(2, 2);
auto r = juce::Rectangle<int>(0, 0, width, height - 0.5);
g.setColour(hlRowBg);
g.fillRect(r);
}
else if (isMouseOver)
{
auto r = juce::Rectangle<int>(0, 0, width, height - 0.5);
g.setColour(hlRowBg.withAlpha(0.3f));
g.fillRect(r);
}

g.setFont(skin->fontManager->getLatoAtSize(12));
auto marginVertical = 3;

g.setFont(skin->fontManager->getLatoAtSize(11));
if (searchIndex >= 0 && searchIndex < lastSearchResult.size())
{
auto pr = lastSearchResult[searchIndex];
auto r = juce::Rectangle<int>(4, 0, width - 8, height - 1);
auto r = juce::Rectangle<int>(4, marginVertical - 2, width - 8, height);
if (rowIsSelected)
g.setColour(hlRowText);
else
g.setColour(rowText);
g.drawText(pr.name, r, juce::Justification::centredTop);
g.drawText(pr.name, r, juce::Justification::topLeft);

if (rowIsSelected)
g.setColour(hlRowSubText);
g.setColour(hlRowSubText.withAlpha(0.8f));
else
g.setColour(rowSubText);
g.setColour(rowSubText.withAlpha(0.8f));
g.setFont(skin->fontManager->getLatoAtSize(8));
g.drawText(pr.cat, r, juce::Justification::bottomLeft);
g.drawText(pr.author, r, juce::Justification::bottomRight);
}
g.setColour(divider);
g.drawLine(4, height - 1, width - 4, height - 1, 1);
}

void paintOverChildren(juce::Graphics &g, const juce::Rectangle<int> &bounds) override
{
auto q = bounds.reduced(2, 2);
auto res = lastSearchResult.size();
std::string txt;

if (res <= 0)
{
txt = "No results";
auto rLower = juce::Rectangle<int>(4, 0, width - 8, height - marginVertical);
r.translate(0, -marginVertical * 2);
g.drawText(pr.cat, rLower, juce::Justification::bottomLeft);
g.drawText(pr.author, rLower, juce::Justification::bottomRight);
}
else
{
txt = fmt::format("{:d} result{:s}", res, (res > 1 ? "s" : ""));
}

g.setColour(rowText.withAlpha(0.666f));
g.setFont(skin->fontManager->getLatoAtSize(7, juce::Font::bold));
g.drawText(txt, q, juce::Justification::topLeft);
g.setColour(divider.withAlpha(0.8f));
g.drawLine(0, height - 0.5, width, height - 0.5, 0.5);
}

void paintOverChildren(juce::Graphics &g, const juce::Rectangle<int> &bounds) override {}
};

struct PatchSelector::TB : juce::Component
Expand Down Expand Up @@ -294,7 +291,7 @@ void PatchSelector::paint(juce::Graphics &g)
cat = cat.translated(0, getHeight() * 0.5);
auth = auth.withTrimmedRight(3)
.withWidth(150)
.translated(getWidth() - 150 - 3, 0)
.translated(getWidth() - 180 - 3, 0)
.withTop(cat.getY())
.withHeight(cat.getHeight());
}
Expand Down Expand Up @@ -392,6 +389,29 @@ void PatchSelector::paint(juce::Graphics &g)
g.drawText((useCatAndBy ? "By: " : "") + author, auth,
skin->getVersion() >= 2 ? juce::Justification::centredRight
: juce::Justification::centredLeft);

// search result text
}
if (typeAhead->lbox->isVisible())
{
auto res = patchDbProvider->lastSearchResult.size();
std::string txt;

if (res <= 0)
{
txt = "No results";
}
else
{
txt = fmt::format("{:d} result{:s}", res, (res > 1 ? "s" : ""));
}

auto tc = skin->getColor(Colors::PatchBrowser::Text);
g.setColour(tc);
g.setFont(skin->fontManager->displayFont);

auto rect = juce::Rectangle(20, -12, 70, 40);
g.drawText(txt, rect, juce::Justification::centredLeft);
}
}

Expand All @@ -412,7 +432,7 @@ void PatchSelector::resized()
.translated(2, 1);
searchButton->setBounds(searchRect);

auto tad = getLocalBounds().reduced(fsize + 4, 0).translated(0, -2);
auto tad = getLocalBounds().reduced(fsize, 0).translated(0, -2);

typeAhead->setBounds(tad);
}
Expand Down
26 changes: 25 additions & 1 deletion src/surge-xt/gui/widgets/TypeAheadTextEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ struct TypeAheadListBoxModel : public juce::ListBoxModel
TypeAheadDataProvider *provider;
std::vector<int> search;
TypeAhead *ta{nullptr};
int rowIsMouseOver = 0;

TypeAheadListBoxModel(TypeAhead *t, TypeAheadDataProvider *p) : ta(t), provider(p) {}

void setSearch(const std::string &t) { search = provider->searchFor(t); }
int getNumRows() override { return search.size(); }

int isRowMouseOver(int row) { return rowIsMouseOver == row; };

void paintListBoxItem(int rowNumber, juce::Graphics &g, int width, int height,
bool rowIsSelected) override
{
Expand Down Expand Up @@ -109,6 +113,8 @@ struct TypeAheadListBoxModel : public juce::ListBoxModel
{
int row{0};
bool isSelected{false};
bool isMouseOver{false};

TypeAheadListBoxModel *model{nullptr};
TARow(TypeAheadListBoxModel *m) : model(m) { setWantsKeyboardFocus(true); }

Expand Down Expand Up @@ -153,6 +159,20 @@ struct TypeAheadListBoxModel : public juce::ListBoxModel

void mouseDown(const juce::MouseEvent &e) override { model->returnKeyPressed(row); }

void mouseEnter(const juce::MouseEvent &event) override
{
isMouseOver = true;
model->rowIsMouseOver = row;
repaint();
}

void mouseExit(const juce::MouseEvent &event) override
{
model->rowIsMouseOver = -1;
isMouseOver = false;
repaint();
}

void mouseDoubleClick(const juce::MouseEvent &e) override { model->escapeKeyPressed(); }

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TARow);
Expand Down Expand Up @@ -204,6 +224,7 @@ struct TypeAheadListBox : public juce::ListBox

void paintOverChildren(juce::Graphics &graphics) override
{

juce::ListBox::paintOverChildren(graphics);

if (auto m = dynamic_cast<TypeAheadListBoxModel *>(getListBoxModel()))
Expand Down Expand Up @@ -254,6 +275,8 @@ TypeAhead::TypeAhead(const std::string &l, TypeAheadDataProvider *p)

TypeAhead::~TypeAhead() = default;

bool TypeAhead::isRowMouseOver(int row) { return lboxmodel->rowIsMouseOver == row; }

void TypeAhead::dismissWithValue(int providerIdx, const std::string &s,
const juce::ModifierKeys &mod)
{
Expand Down Expand Up @@ -364,6 +387,7 @@ void TypeAhead::searchAndShowLBox()

void TypeAhead::showLbox()
{

auto p = getParentComponent();

while (p && !dynamic_cast<Surge::Widgets::MainFrame *>(p))
Expand All @@ -375,7 +399,7 @@ void TypeAhead::showLbox()
getLocalBounds()
.translated(0, getHeight())
.withHeight(
lboxmodel->provider->getRowHeight() * lboxmodel->provider->getDisplayedRows() + 4);
lboxmodel->provider->getRowHeight() * lboxmodel->provider->getDisplayedRows() + 2);

if (p)
{
Expand Down
1 change: 1 addition & 0 deletions src/surge-xt/gui/widgets/TypeAheadTextEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct TypeAhead : public juce::TextEditor, juce::TextEditor::Listener
std::unique_ptr<juce::ListBox> lbox;
std::unique_ptr<TypeAheadListBoxModel> lboxmodel;

bool isRowMouseOver(int row);
void searchAndShowLBox();
void showLbox();
void parentHierarchyChanged() override;
Expand Down
Loading