Skip to content

Commit

Permalink
add some code to later add tooltip arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
luismrguimaraes committed Aug 28, 2024
1 parent b53bb6a commit 99e5afe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
10 changes: 2 additions & 8 deletions include/sst/jucegui/components/MenuButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ struct MenuButton : public CallbackButtonComponent<MenuButton>,

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

bool centerTextAndExcludeArrow;

public:
void setCenterTextAndExcludeArrow(bool);
bool centerTextAndExcludeArrow{false};

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MenuButton)
};
Expand All @@ -85,10 +82,7 @@ struct MenuButtonDiscreteEditor : public DiscreteParamEditor,

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

bool centerTextAndExcludeArrow;

public:
void setCenterTextAndExcludeArrow(bool);
bool centerTextAndExcludeArrow{false};

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MenuButtonDiscreteEditor);
};
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
7 changes: 0 additions & 7 deletions src/sst/jucegui/components/MenuButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ MenuButton::MenuButton() {}

MenuButton::~MenuButton() {}

void MenuButton::setCenterTextAndExcludeArrow(bool value) { centerTextAndExcludeArrow = value; }

void MenuButtonDiscreteEditor::setCenterTextAndExcludeArrow(bool value)
{
centerTextAndExcludeArrow = value;
}

template <typename T>
void MenuButtonPainter<T>::paintMenuButton(juce::Graphics &g, const std::string &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 99e5afe

Please sign in to comment.