Skip to content

Commit 7f3fc7e

Browse files
committed
Add plugin description callout in Plugin Installer
1 parent 39519c6 commit 7f3fc7e

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

Source/UI/PluginInstaller.cpp

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,42 @@ class PluginVersionCell : public Component
809809
std::function<void (const String&)> onVersionChanged;
810810
};
811811

812+
class PluginDescriptionCalloutComponent : public Component
813+
{
814+
public:
815+
PluginDescriptionCalloutComponent (String descriptionToShow, Font descriptionFont)
816+
: font (std::move (descriptionFont))
817+
{
818+
descriptionText.append (std::move (descriptionToShow),
819+
font,
820+
findColour (ThemeColours::defaultText));
821+
descriptionText.setJustification (Justification::topLeft);
822+
descriptionText.setWordWrap (AttributedString::WordWrap::byWord);
823+
descriptionLayout.createLayout (descriptionText, static_cast<float> (contentWidth - padding * 2));
824+
setSize (contentWidth, getPreferredHeight());
825+
}
826+
827+
void paint (Graphics& g) override
828+
{
829+
g.setColour (findColour (ThemeColours::widgetBackground));
830+
g.fillRoundedRectangle (getLocalBounds().toFloat().reduced (1.0f), 5.0f);
831+
descriptionLayout.draw (g, getLocalBounds().reduced (padding).toFloat());
832+
}
833+
834+
private:
835+
int getPreferredHeight() const
836+
{
837+
return jlimit (40, 500, roundToInt (descriptionLayout.getHeight()) + padding * 2);
838+
}
839+
840+
static constexpr int contentWidth = 360;
841+
static constexpr int padding = 12;
842+
843+
AttributedString descriptionText;
844+
TextLayout descriptionLayout;
845+
Font font;
846+
};
847+
812848
class PluginIconButtonCell : public Component
813849
{
814850
public:
@@ -1117,6 +1153,23 @@ void PluginListBoxComponent::paintCell (Graphics& g,
11171153
g.drawText (text.isNotEmpty() ? text : String ("-"), textBounds, Justification::centredLeft, true);
11181154
}
11191155

1156+
void PluginListBoxComponent::cellClicked (int rowNumber, int columnId, const MouseEvent&)
1157+
{
1158+
if (columnId != descriptionColumn)
1159+
return;
1160+
1161+
const auto* pluginInfo = getPluginForVisibleRow (rowNumber);
1162+
1163+
if (pluginInfo == nullptr || pluginInfo->description.trim().isEmpty() || pluginTable == nullptr)
1164+
return;
1165+
1166+
auto anchorBounds = pluginTable->getCellPosition (descriptionColumn, rowNumber, true);
1167+
auto content = std::make_unique<PluginDescriptionCalloutComponent> (pluginInfo->description.trim(),
1168+
Font (FontOptions ("Inter", "Regular", 15.0f)));
1169+
auto& callOut = CallOutBox::launchAsynchronously (std::move (content), anchorBounds, this);
1170+
callOut.setDismissalMouseClicksAreAlwaysConsumed (true);
1171+
}
1172+
11201173
Component* PluginListBoxComponent::refreshComponentForCell (int rowNumber,
11211174
int columnId,
11221175
bool /*isRowSelected*/,
@@ -1207,7 +1260,7 @@ String PluginListBoxComponent::getCellTooltip (int rowNumber, int columnId)
12071260
return pluginInfo->developers;
12081261

12091262
case descriptionColumn:
1210-
return pluginInfo->description;
1263+
return pluginInfo->description.isNotEmpty() ? "Click to view full description" : String();
12111264

12121265
case dependenciesColumn:
12131266
return getDependenciesText (*pluginInfo);

Source/UI/PluginInstaller.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ class PluginListBoxComponent : public Component,
179179

180180
void paintCell (Graphics& g, int rowNumber, int columnId, int width, int height, bool rowIsSelected) override;
181181

182+
void cellClicked (int rowNumber, int columnId, const MouseEvent& event) override;
183+
182184
Component* refreshComponentForCell (int rowNumber,
183185
int columnId,
184186
bool isRowSelected,

0 commit comments

Comments
 (0)