Skip to content

Commit

Permalink
Fixed tab button text position
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed May 9, 2023
1 parent b151d94 commit 165f751
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions Source/LookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -693,15 +693,9 @@ struct PlugDataLook : public LookAndFeel_V4 {

void drawTabButtonText (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown) override
{
auto area = button.getLocalBounds().toFloat();
auto area = button.getLocalBounds().reduced(4, 1).toFloat();

auto length = area.getWidth();
auto depth = area.getHeight();

if (button.getTabbedButtonBar().isVertical())
std::swap (length, depth);

Font font (getTabButtonFont (button, depth));
Font font (getTabButtonFont (button, area.getHeight()));
font.setUnderline (button.hasKeyboardFocus (false));

AffineTransform t;
Expand All @@ -726,20 +720,19 @@ struct PlugDataLook : public LookAndFeel_V4 {
else
col = button.getTabBackgroundColour().contrasting();

g.setColour (col);
g.setFont (font);
g.addTransform (t);
g.setColour(col);
g.setFont(font);
g.addTransform(t);

auto buttonText = button.getButtonText().trim();
auto textAreaWidth = button.getTextArea().getWidth() - 6;
if(font.getStringWidth(buttonText) > textAreaWidth) {
length = textAreaWidth;
if(font.getStringWidthFloat(buttonText) > area.getWidth() * 0.4f) {
area = button.getTextArea().toFloat();
}

g.drawFittedText (buttonText,
0, 0, (int) length, (int) depth,
area.getX(), area.getY(), (int) area.getWidth(), (int) area.getHeight(),
Justification::centred,
jmax (1, ((int) depth) / 12));
jmax (1, ((int) area.getHeight()) / 12));
}

void drawTabAreaBehindFrontButton(TabbedButtonBar& bar, Graphics& g, int const w, int const h) override
Expand Down

0 comments on commit 165f751

Please sign in to comment.