Skip to content

Commit

Permalink
Deal with the getFontWidth rapid deprecatation (#131)
Browse files Browse the repository at this point in the history
`font.getStringWidth` was deprecated between juce 801 and 802 in favor of a function which doesn't exist in 801 or earlier. Deal with this particular choice by adding a version-switching function and using it.
  • Loading branch information
baconpaul authored Sep 28, 2024
1 parent 82f578b commit 8e83fbd
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 18 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,29 @@ jobs:
cmakeArgs: -DCMAKE_BUILD_TYPE=Debug

- os: windows-latest
name: windows msvc Juce 8
name: windows msvc Juce 801
cmakeArgs: -DCMAKE_BUILD_TYPE=Debug -DSST_JUCEGUI_JUCE_VERSION="8.0.1"

- os: windows-latest
name: windows msvc Juce 802
cmakeArgs: -DCMAKE_BUILD_TYPE=Debug -DSST_JUCEGUI_JUCE_VERSION="8.0.2"

- os: macos-latest
name: macos Juce 802
cmakeArgs: -DCMAKE_BUILD_TYPE=Debug -DSST_JUCEGUI_JUCE_VERSION="8.0.2" -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"

- os: macos-latest
name: macos Juce 8
name: macos Juce 801
cmakeArgs: -DCMAKE_BUILD_TYPE=Debug -DSST_JUCEGUI_JUCE_VERSION="8.0.1" -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"

- os: ubuntu-latest
name: ubuntu Juce 8
name: ubuntu Juce 801
cmakeArgs: -DCMAKE_BUILD_TYPE=Debug -DSST_JUCEGUI_JUCE_VERSION="8.0.1"

- os: ubuntu-latest
name: ubuntu Juce 802
cmakeArgs: -DCMAKE_BUILD_TYPE=Debug -DSST_JUCEGUI_JUCE_VERSION="8.0.2"

- os: windows-latest
name: windows unity
cmakeArgs: -DCMAKE_BUILD_TYPE=Debug -DCMAKE_UNITY_BUILD=TRUE
Expand Down
53 changes: 53 additions & 0 deletions fix_string_width.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/perl


use File::Find;
use File::Basename;

find(
{
wanted => \&findfiles,
},
'include'
);


find(
{
wanted => \&findfiles,
},
'src'
);

sub findfiles
{
$f = $File::Find::name;
if ($f =~ m/StyleSheet\.h$/)
{
return;
}

if ($f =~ m/\.cpp$/ || $f =~ m/\.h$/)
{
print $f . " \n";
$q = basename($f);

open (IN, "< $q") || die "Cant open $q from $f";
open (OUT, "> $q.bak");
while(<IN>)
{
if (m/getStringWidth/)
{
print;
s/([^\s\{]+)\.getStringWidth\(/SST_STRING_WIDTH_INT\($1, /;
print;
#die;
}
print OUT;

}
close(IN);
close(OUT);
system("mv ${q}.bak ${q}");
}
}
2 changes: 1 addition & 1 deletion include/sst/jucegui/components/RuledLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct RuledLabel : public juce::Component,
g.setFont(getFont(Styles::labelfont));
g.drawText(text, getLocalBounds(), juce::Justification::centred);

auto labelWidth = g.getCurrentFont().getStringWidth(text);
auto labelWidth = SST_STRING_WIDTH_INT(g.getCurrentFont(), text);

auto ht = getLocalBounds();
g.setColour(getColour(Styles::brightoutline));
Expand Down
2 changes: 1 addition & 1 deletion include/sst/jucegui/components/TabbedComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ struct TabbedComponent : juce::TabbedComponent, style::StyleConsumer
return minTab;

auto ft = parentComp->style()->getFont(Styles::styleClass, Styles::labelfont);
auto fw = ft.getStringWidthFloat(name) + 2 * marginPad;
auto fw = SST_STRING_WIDTH_FLOAT(ft, name) + 2 * marginPad;
return std::max((int)std::ceil(fw), minTab);
}
};
Expand Down
9 changes: 9 additions & 0 deletions include/sst/jucegui/style/StyleSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
#define SST_JUCE_FONT_CTOR(...) juce::Font(__VA_ARGS__)
#endif

// Yes, a non-compatible point release! Fun eh?
#if JUCE_VERSION >= 0x080002
#define SST_STRING_WIDTH_INT(a, b) juce::GlyphArrangement::getStringWidthInt(a, b)
#define SST_STRING_WIDTH_FLOAT(a, b) juce::GlyphArrangement::getStringWidth(a, b)
#else
#define SST_STRING_WIDTH_INT(a, b) a.getStringWidth(b)
#define SST_STRING_WIDTH_FLOAT(a, b) a.getStringWidthFloat(b)
#endif

namespace sst::jucegui::style
{
struct StyleConsumer;
Expand Down
6 changes: 3 additions & 3 deletions src/sst/jucegui/components/NamedPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ void NamedPanel::paintHeader(juce::Graphics &g)
g.setFont(getFont(Styles::labelfont));
g.setColour(getColour(Styles::labelcolor));
g.drawText(name, ht, juce::Justification::centred);
labelWidth = g.getCurrentFont().getStringWidth(name);
labelWidth = SST_STRING_WIDTH_INT(g.getCurrentFont(), name);
}
else
{
g.setFont(getFont(Styles::labelfont));
g.setColour(getColour(Styles::labelcolor));
g.drawText(name, ht, juce::Justification::centredLeft);
labelWidth = g.getCurrentFont().getStringWidth(name);
labelWidth = SST_STRING_WIDTH_INT(g.getCurrentFont(), name);
}

g.setColour(getColour(Styles::labelrule));
Expand Down Expand Up @@ -295,7 +295,7 @@ void NamedPanel::resetTabState()
tabPositions.clear();
for (const auto &t : tabNames)
{
auto fw = f.getStringWidth("[ " + t + " ]");
auto fw = SST_STRING_WIDTH_INT(f, "[ " + t + " ]");
auto tt = ht.withLeft(totalTabSize + 4).withWidth(fw);
tabPositions.push_back(tt);
totalTabSize += fw;
Expand Down
20 changes: 10 additions & 10 deletions src/sst/jucegui/components/ToolTip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void ToolTip::resetSizeFromData()
{
auto f = style()->getFont(Styles::styleClass, Styles::labelfont);
auto rowHeight = f.getHeight() + rowPad;
auto maxw = std::max(f.getStringWidthFloat(tooltipTitle), 60.f);
auto maxw = std::max(SST_STRING_WIDTH_FLOAT(f, tooltipTitle), 60.f);

auto df = style()->getFont(Styles::styleClass, Styles::datafont);
auto drowHeight = 0.f;
Expand Down Expand Up @@ -142,24 +142,24 @@ int ToolTip::getRowWidth(int ri)
row.rightAlignText.empty())
{
if (row.leftIsMonospace)
return df.getStringWidthFloat(row.leftAlignText);
return SST_STRING_WIDTH_FLOAT(df, row.leftAlignText);
else
return f.getStringWidth(row.leftAlignText);
return SST_STRING_WIDTH_INT(f, row.leftAlignText);
}

auto blankStringWidth{4.f};
auto res = 0.f;
if (row.rowLeadingGlyph.has_value())
res += glyphSize;
res +=
std::min(blankStringWidth, row.leftIsMonospace ? df.getStringWidthFloat(row.leftAlignText)
: f.getStringWidthFloat(row.leftAlignText));
res += std::min(blankStringWidth, row.leftIsMonospace
? SST_STRING_WIDTH_FLOAT(df, row.leftAlignText)
: SST_STRING_WIDTH_FLOAT(f, row.leftAlignText));
res += std::min(blankStringWidth, row.centerIsMonospace
? df.getStringWidthFloat(row.centerAlignText)
: f.getStringWidthFloat(row.centerAlignText));
? SST_STRING_WIDTH_FLOAT(df, row.centerAlignText)
: SST_STRING_WIDTH_FLOAT(f, row.centerAlignText));
res += std::min(blankStringWidth, row.rightIsMonospace
? df.getStringWidthFloat(row.rightAlignText)
: f.getStringWidthFloat(row.rightAlignText));
? SST_STRING_WIDTH_FLOAT(df, row.rightAlignText)
: SST_STRING_WIDTH_FLOAT(f, row.rightAlignText));

return res + 4;
}
Expand Down
1 change: 1 addition & 0 deletions src/sst/jucegui/style/StyleSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ struct DarkSheet : public StyleSheetBuiltInImpl
{
using n = components::MultiSwitch::Styles;
setColour(n::styleClass, n::unselected_hover, juce::Colour(0x50, 0x50, 0x50));
setColour(n::styleClass, n::valuebg, juce::Colour(0x30, 0x20, 0x00));
}

{
Expand Down

0 comments on commit 8e83fbd

Please sign in to comment.