Skip to content

Commit

Permalink
Fix text cropping for directory path component
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Jan 25, 2025
1 parent e28f4e8 commit f9403be
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions Source/Components/PropertiesPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -1104,33 +1104,38 @@ class PropertiesPanel : public Component {
};

struct DirectoryPathComponent final : public PropertiesPanelProperty {
Label label;
String label;
SmallIconButton browseButton = SmallIconButton(Icons::Folder);
Value property;

DirectoryPathComponent(String const& propertyName, Value& value)
: PropertiesPanelProperty(propertyName)
, property(value)
{
label.setEditable(true, false);
label.getTextValue().referTo(property);
label.addMouseListener(this, true);
label.setFont(Font(14));
label.attachToComponent(&browseButton, true);

addAndMakeVisible(label);
setPath(value.toString());
addAndMakeVisible(browseButton);

browseButton.onClick = [this] {
Dialogs::showOpenDialog([this](URL const& url) {
auto const result = url.getLocalFile();
if (result.exists()) {
label.setText(result.getFullPathName(), sendNotification);
setPath(result.getFullPathName());
}
},
false, true, "", "", getTopLevelComponent());
false, true, "", "", getTopLevelComponent());
};
}

void setPath(String path)
{
property = path;
if(path.length() > 46)
{
path = "..." + path.substring(path.length() - 46, path.length()).fromFirstOccurrenceOf("/", true, false);
}
label = path;
repaint();
}

PropertiesPanelProperty* createCopy() override
{
Expand All @@ -1140,16 +1145,15 @@ class PropertiesPanel : public Component {
void paint(Graphics& g) override
{
PropertiesPanelProperty::paint(g);

g.setColour(findColour(PlugDataColour::panelBackgroundColourId));
g.fillRect(getLocalBounds().removeFromRight(getHeight()));

g.setColour(findColour(PlugDataColour::panelTextColourId).withAlpha(0.8f));
g.setFont(Fonts::getDefaultFont().withHeight(14));
g.drawText(label, 90, 2, getWidth() - 120, getHeight() - 4, Justification::centredLeft);
}

void resized() override
{
auto labelBounds = getLocalBounds().removeFromRight(getWidth() / 2);
label.setBounds(labelBounds);
browseButton.setBounds(labelBounds.removeFromRight(getHeight()));
browseButton.setBounds(getLocalBounds().removeFromRight(getHeight()));
}
};

Expand Down

0 comments on commit f9403be

Please sign in to comment.