Skip to content

Commit

Permalink
Text improvements (#117)
Browse files Browse the repository at this point in the history
* fix menubutton left and right margins

* MenuButton now has a variable to remove arrow and center text

* add some code to later add tooltip arrows
  • Loading branch information
luismrguimaraes authored Aug 28, 2024
1 parent ce4125c commit 73f8c0d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
4 changes: 4 additions & 0 deletions include/sst/jucegui/components/MenuButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ struct MenuButton : public CallbackButtonComponent<MenuButton>,

void paint(juce::Graphics &g) override;

bool centerTextAndExcludeArrow{false};

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MenuButton)
};

Expand All @@ -80,6 +82,8 @@ struct MenuButtonDiscreteEditor : public DiscreteParamEditor,

void paint(juce::Graphics &g) override;

bool centerTextAndExcludeArrow{false};

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MenuButtonDiscreteEditor);
};
} // namespace sst::jucegui::components
Expand Down
3 changes: 2 additions & 1 deletion include/sst/jucegui/components/ToolTip.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ struct ToolTip : juce::Component, sst::jucegui::style::StyleConsumer
{
std::optional<GlyphPainter::GlyphType> rowLeadingGlyph{std::nullopt};
std::string leftAlignText{}, centerAlignText{}, rightAlignText{};
bool leftIsMonospace{false}, centerIsMonospace{false}, rightIsMonospace{false};
bool leftIsMonospace{false}, centerIsMonospace{false}, rightIsMonospace{false},
drawLRArrow{false}, drawRLArrow{false};

explicit Row(const std::string s) : leftAlignText(s) {}
Row() {}
Expand Down
30 changes: 18 additions & 12 deletions src/sst/jucegui/components/MenuButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,31 @@ void MenuButtonPainter<T>::paintMenuButton(juce::Graphics &g, const std::string

g.setFont(getFont(Styles::labelfont));
g.setColour(tx);
g.drawText(label, b.withTrimmedLeft(2), juce::Justification::centredLeft);
if (that->centerTextAndExcludeArrow)
g.drawText(label, b, juce::Justification::centred);
else
g.drawText(label, b.withTrimmedLeft(5), juce::Justification::centredLeft);

g.setColour(ar);
auto q = b.withTrimmedRight(2);
q = q.withLeft(q.getRight() - 10);
auto q = b.withTrimmedRight(5);
q = q.withLeft(q.getRight() - 6);
auto cy = q.getCentreY();
auto au = cy - 2;
auto ad = cy + 2;

auto cx = q.getCentreX();
auto aL = cx - 3;
auto aR = cx + 3;
auto p = juce::Path();
p.startNewSubPath(aL, au);
p.lineTo(aR, au);
p.lineTo(cx, ad);
p.closeSubPath();
if (!that->centerTextAndExcludeArrow)
{
auto cx = q.getCentreX();
auto aL = cx - 3;
auto aR = cx + 3;
auto p = juce::Path();
p.startNewSubPath(aL, au);
p.lineTo(aR, au);
p.lineTo(cx, ad);
p.closeSubPath();

g.fillPath(p);
g.fillPath(p);
}
}

void MenuButton::paint(juce::Graphics &g) { paintMenuButton(g, label); }
Expand Down
21 changes: 17 additions & 4 deletions src/sst/jucegui/components/ToolTip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void ToolTip::paint(juce::Graphics &g)
auto bg = style()->getColour(Styles::styleClass, Styles::background);
auto bord = style()->getColour(Styles::styleClass, Styles::brightoutline);
auto lbord = style()->getColour(Styles::styleClass, Styles::outline);
auto txt = style()->getColour(Styles::styleClass, Styles::labelcolor);
auto txtColour = style()->getColour(Styles::styleClass, Styles::labelcolor);

g.setColour(bg);
g.fillRect(getLocalBounds());
Expand All @@ -48,7 +48,7 @@ void ToolTip::paint(juce::Graphics &g)
g.drawLine(3, rowHeight + margin - rowPad / 2, getWidth() - 3, rowHeight + margin - rowPad / 2,
1);

g.setColour(txt);
g.setColour(txtColour);
auto bx = juce::Rectangle<int>(margin, margin, getWidth() - 2 * margin, rowHeight);
g.setFont(f);
g.drawText(tooltipTitle, bx, juce::Justification::topLeft);
Expand All @@ -58,7 +58,7 @@ void ToolTip::paint(juce::Graphics &g)
g.setFont(df);

bx = bx.translated(0, rowHeight + rowTitlePad);
g.setColour(txt);
g.setColour(txtColour);
for (auto i = 0; i < tooltipData.size(); ++i)
{
auto &row = tooltipData[i];
Expand All @@ -69,13 +69,26 @@ void ToolTip::paint(juce::Graphics &g)
auto txtbx = bx;
if (row.rowLeadingGlyph.has_value())
{
GlyphPainter::paintGlyph(g, bx.withWidth(glyphSize), *(row.rowLeadingGlyph), txt);
GlyphPainter::paintGlyph(g, bx.withWidth(glyphSize), *(row.rowLeadingGlyph), txtColour);
txtbx = bx.withTrimmedLeft(glyphSize + 2);
}
g.setFont(row.leftIsMonospace ? df : f);
g.drawText(row.leftAlignText, txtbx, juce::Justification::centredLeft);

// if (row.drawLRArrow && !row.drawRLArrow)
// GlyphPainter::paintGlyph(g, txtbx.withTrimmedLeft(txtbx.getWidth() / 3),
// GlyphPainter::GlyphType::ARROW_L_TO_R, txtColour);
// else if (row.drawLRArrow && row.drawRLArrow)
// GlyphPainter::paintGlyph(g, txtbx.withTrimmedLeft(txtbx.getWidth() / 3),
// GlyphPainter::GlyphType::ARROW_L_TO_R, txtColour); // should
// be R_TO_L glyph
g.setFont(row.centerIsMonospace ? df : f);
g.drawText(row.centerAlignText, txtbx, juce::Justification::centred);
// if (row.drawLRArrow && row.drawRLArrow)
//{
// GlyphPainter::paintGlyph(g, txtbx.withTrimmedLeft(2 * txtbx.getWidth() / 3),
// GlyphPainter::GlyphType::ARROW_L_TO_R, txtColour);
// }
g.setFont(row.rightIsMonospace ? df : f);
g.drawText(row.rightAlignText, txtbx, juce::Justification::centredRight);
bx = bx.translated(0, rh + rowPad);
Expand Down

0 comments on commit 73f8c0d

Please sign in to comment.