Skip to content

Commit

Permalink
- revamped API Browser
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-hart committed Sep 10, 2024
1 parent c40a014 commit aa3ccf5
Show file tree
Hide file tree
Showing 4 changed files with 287 additions and 47 deletions.
51 changes: 43 additions & 8 deletions hi_backend/backend/debug_components/ApiBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,23 +284,40 @@ className(className_)

auto extendedHelp = ExtendedApiDocumentation::getMarkdownText(className, name);

if(extendedHelp.isEmpty())
{
AttributedString help;

const String name = methodTree_.getProperty(Identifier("name")).toString();
const String arguments = methodTree_.getProperty(Identifier("arguments")).toString();
const String description = methodTree_.getProperty(Identifier("description")).toString().trim();
const String returnType = methodTree_.getProperty("returnType", "void");

extendedHelp << "`" << className_ << "." << name << arguments << "` \n";

if(!returnType.isEmpty())
extendedHelp << "**Return Type**: `" << returnType << "` \n";

extendedHelp << "> " << description << " \n";
extendedHelp << "**[F1]** - open in docs **[Enter, Double-Click]** - paste in editor";
}

if (extendedHelp.isNotEmpty())
{
parser = new MarkdownRenderer(extendedHelp);
parser->setTextColour(Colours::white);
parser->setDefaultTextSize(15.0f);
parser->parse();

auto bd = MarkdownLayout::StyleData::createBrightStyle();
bd.fontSize = 14.0f;
parser->setStyleData(bd);
}

setWantsKeyboardFocus(true);

help = ValueTreeApiHelpers::createAttributedStringFromApi(methodTree, className, true, Colours::white);
}




void ApiCollection::MethodItem::mouseDoubleClick(const MouseEvent&)
void ApiCollection::MethodItem::mouseDoubleClick(const MouseEvent& e)
{
insertIntoCodeEditor();
}
Expand All @@ -313,6 +330,18 @@ bool ApiCollection::MethodItem::keyPressed(const KeyPress& key)
return true;
}

if(key.isKeyCode(KeyPress::upKey))
{
findParentComponentOfClass<SearchableListComponent>()->selectNext(false, this);
return true;
}
if(key.isKeyCode(KeyPress::downKey))
{
findParentComponentOfClass<SearchableListComponent>()->selectNext(true, this);

return true;
}

return false;
}

Expand Down Expand Up @@ -362,6 +391,8 @@ ApiCollection::ClassCollection::ClassCollection(const ValueTree &api) :
classApi(api),
name(api.getType().toString())
{
setWantsKeyboardFocus(true);

for (int i = 0; i < api.getNumChildren(); i++)
{
items.add(new MethodItem(api.getChild(i), name));
Expand All @@ -375,8 +406,12 @@ name(api.getType().toString())
void ApiCollection::ClassCollection::paint(Graphics &g)
{
g.setColour(Colours::white.withAlpha(0.9f));
g.setFont(GLOBAL_MONOSPACE_FONT());
g.drawText(name, 10, 0, getWidth() - 10, COLLECTION_HEIGHT, Justification::centredLeft, true);

auto f = GLOBAL_MONOSPACE_FONT();


g.setFont(GLOBAL_MONOSPACE_FONT().withHeight(f.getHeight() * 1.2f));
g.drawText(name, 14, 0, getWidth() - 10, COLLECTION_HEIGHT, Justification::centredLeft, true);
}

ExtendedApiDocumentation::MethodDocumentation::MethodDocumentation(Identifier& className_, const Identifier& id) :
Expand Down
14 changes: 9 additions & 5 deletions hi_backend/backend/debug_components/ApiBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class ApiCollection : public SearchableListComponent
{
public:

const int extendedWidth = 600;
const int extendedWidth = 500;

MethodItem(const ValueTree &methodTree_, const String &className_);

Expand All @@ -219,8 +219,9 @@ class ApiCollection : public SearchableListComponent
return Item::getPopupWidth();
}

void focusGained(FocusChangeType) override
void focusGained(FocusChangeType ft) override
{
Item::focusGained(ft);
repaint();
}

Expand All @@ -231,8 +232,9 @@ class ApiCollection : public SearchableListComponent
return { File(), s };
}

void focusLost(FocusChangeType ) override
void focusLost(FocusChangeType ft) override
{
Item::focusLost(ft);
repaint();
}

Expand All @@ -248,10 +250,12 @@ class ApiCollection : public SearchableListComponent
auto bounds = Rectangle<float>(10.0f, 10.0f, 280.0f, (float)getPopupHeight() - 20);
help.draw(g, bounds);
}

}

void mouseEnter(const MouseEvent&) override { repaint(); }
void mouseEnter(const MouseEvent&) override
{
repaint();
}
void mouseExit(const MouseEvent&) override { repaint(); }
void mouseDoubleClick(const MouseEvent&) override;

Expand Down
57 changes: 35 additions & 22 deletions hi_backend/backend/debug_components/ProcessorCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ SearchableListComponent::SearchableListComponent(BackendRootWindow* window):
{
addAndMakeVisible(fuzzySearchBox = new TextEditor());
fuzzySearchBox->addListener(this);



textClearButton = new SearchBoxClearComponent(*fuzzySearchBox);

setWantsKeyboardFocus(true);

GlobalHiseLookAndFeel::setTextEditorColours(*fuzzySearchBox);

internalContainer = new InternalContainer();
Expand Down Expand Up @@ -71,7 +74,7 @@ void SearchableListComponent::resized()
}

b.removeFromLeft(b.getHeight());

fuzzySearchBox->setBounds(b.reduced(1));
viewport->setBounds(0, 26, getWidth(), getHeight() - 26);

Expand Down Expand Up @@ -294,34 +297,39 @@ void SearchableListComponent::InternalContainer::resized()

void SearchableListComponent::Item::mouseDown(const MouseEvent& event)
{
if (event.mods.isRightButtonDown())
if (!usePopupMenu)
{
if (!usePopupMenu)
if(auto cp = findParentComponentOfClass<SearchableListComponent>()->currentPopup.get())
{
if (getPopupHeight() != 0)
if(cp->parent == this)
{
auto parent = TopLevelWindowWithOptionalOpenGL::findRoot(this);
clicksToClose++;

CallOutBox::launchAsynchronously(std::unique_ptr<PopupComponent>(new PopupComponent(this)), parent->getLocalArea(this, getLocalBounds()), parent);
if(clicksToClose > 1)
{
findParentComponentOfClass<SearchableListComponent>()->showPopup(nullptr);
}
}
}
else
{
PopupMenu m;
return;
}

if (event.mods.isRightButtonDown())
{
PopupMenu m;

m.setLookAndFeel(&laf);
m.setLookAndFeel(&laf);

fillPopupMenu(m);
fillPopupMenu(m);

PopupMenu::Options options;
Point<int> mousePos(Desktop::getInstance().getMousePosition());
PopupMenu::Options options;

Point<int> mousePos(Desktop::getInstance().getMousePosition());

Point<int> pos2 = mousePos;
pos2.addXY(200, 500);
Point<int> pos2 = mousePos;
pos2.addXY(200, 500);

m.showMenuAsync(options.withTargetScreenArea(Rectangle<int>(mousePos, mousePos)), new PopupCallback(this));
}
m.showMenuAsync(options.withTargetScreenArea(Rectangle<int>(mousePos, mousePos)), new PopupCallback(this));
}
else
{
Expand Down Expand Up @@ -356,12 +364,17 @@ void SearchableListComponent::Item::matchAgainstSearch(const String &stringToMat
SearchableListComponent::Item::PopupComponent::PopupComponent(Item *p) :
parent(p)
{
setSize(p->getPopupWidth(), p->getPopupHeight());
setWantsKeyboardFocus(true);
parent->findParentComponentOfClass<SearchableListComponent>()->viewport->getVerticalScrollBar().addListener(this);
setWantsKeyboardFocus(false);
}

void SearchableListComponent::Item::PopupComponent::paint(Graphics& g)
{
auto cornerSize = 3.0f;

g.setColour(JUCE_LIVE_CONSTANT_OFF(Colour(0xffe0e0e0)));
g.fillRoundedRectangle(getLocalBounds().toFloat(), cornerSize);

if (parent.getComponent() != nullptr) parent->paintPopupBox(g);
}

Expand Down
Loading

0 comments on commit aa3ccf5

Please sign in to comment.