Skip to content

Commit

Permalink
Add support for JUCE 8.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJimmi committed Sep 30, 2024
1 parent d93bace commit f61a3f3
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions jive_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ target_sources(jive_core
algorithms/jive_Interpolate.h
algorithms/jive_TransferFunction.h
algorithms/jive_Visitor.h
compile-time-helpers/jive_JuceVersion.h
geometry/jive_BorderRadii.h
geometry/jive_BoxModel.cpp
geometry/jive_BoxModel.h
Expand Down
3 changes: 3 additions & 0 deletions jive_core/compile-time-helpers/jive_JuceVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#define JIVE_JUCE_VERSION(major, minor, patch) ((major << 16) + (minor << 8) + patch)
11 changes: 10 additions & 1 deletion jive_core/graphics/jive_FontUtilities.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "jive_FontUtilities.h"

#include <juce_graphics/juce_graphics.h>
#include <jive_core/compile-time-helpers/jive_JuceVersion.h>

namespace jive
{
Expand All @@ -18,4 +18,13 @@ namespace jive

return flags;
}

float calculateStringWidth(const juce::String& text, const juce::Font& font)
{
#if JUCE_VERSION > JIVE_JUCE_VERSION(8, 0, 1)
return juce::GlyphArrangement::getStringWidth(font, text);
#else
return font.getStringWidthFloat(text);
#endif
}
} // namespace jive
5 changes: 3 additions & 2 deletions jive_core/graphics/jive_FontUtilities.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <juce_core/juce_core.h>
#include <juce_graphics/juce_graphics.h>

namespace jive
{
int parseFontStyleFlags(const juce::String& styleString);
[[nodiscard]] int parseFontStyleFlags(const juce::String& styleString);
[[nodiscard]] float calculateStringWidth(const juce::String& text, const juce::Font& font);
} // namespace jive
1 change: 1 addition & 0 deletions jive_core/jive_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ END_JUCE_MODULE_DECLARATION */

#include <juce_gui_basics/juce_gui_basics.h>

#include "compile-time-helpers/jive_JuceVersion.h"
#include "logging/jive_ConsoleProgressBar.h"
#include "logging/jive_ScopeIndentedLogger.h"
#include "logging/jive_StringStreams.h"
Expand Down
7 changes: 7 additions & 0 deletions jive_core/values/jive_Object.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <jive_core/compile-time-helpers/jive_JuceVersion.h>

#include <juce_data_structures/juce_data_structures.h>

namespace jive
Expand All @@ -23,8 +25,13 @@ namespace jive
Object(Object&& other);
Object(const juce::DynamicObject& other);

#if JUCE_VERSION > JIVE_JUCE_VERSION(8, 0, 1)
void setProperty(const juce::Identifier& propertyName,
const juce::var& newValue);
#else
void setProperty(const juce::Identifier& propertyName,
const juce::var& newValue) override;
#endif
const juce::NamedValueSet& getProperties() const;

Object* getParent() noexcept;
Expand Down
6 changes: 3 additions & 3 deletions jive_core/values/jive_Property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class PropertyUnitTest : public juce::UnitTest
};
state["object"].getDynamicObject()->setProperty("foo", 111);
expect(!receivedCallback);
state["object"].getDynamicObject()->setProperty("value", 11358);
dynamic_cast<jive::Object*>(state["object"].getDynamicObject())->setProperty("value", 11358);
expect(receivedCallback);
}

Expand All @@ -342,10 +342,10 @@ class PropertyUnitTest : public juce::UnitTest
value.onValueChange = [&receivedCallback]() {
receivedCallback = true;
};
state["object"]["inner"].getDynamicObject()->setProperty("value", 11358);
dynamic_cast<jive::Object*>(state["object"]["inner"].getDynamicObject())->setProperty("value", 11358);
expect(receivedCallback);
receivedCallback = false;
state["object"].getDynamicObject()->setProperty("value", 34544);
dynamic_cast<jive::Object*>(state["object"].getDynamicObject())->setProperty("value", 34544);
expect(receivedCallback);
}

Expand Down
7 changes: 4 additions & 3 deletions jive_layouts/layout/gui-items/content/jive_Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ namespace jive
} // namespace jive

#if JIVE_UNIT_TESTS
#include <jive_core/graphics/jive_FontUtilities.h>
#include <jive_layouts/layout/jive_Interpreter.h>

class TextTest : public juce::UnitTest
Expand Down Expand Up @@ -525,14 +526,14 @@ class TextTest : public juce::UnitTest

const auto& boxModel = jive::boxModel(item);
expectEquals(boxModel.getWidth(),
std::ceil(font.getStringWidthFloat("This side up.")));
std::ceil(jive::calculateStringWidth("This side up.", font)));
expectEquals(boxModel.getHeight(), std::ceil(font.getHeight()));

textTree.setProperty("text", "This one spans\nmultiple lines.", nullptr);
expectEquals(boxModel.getWidth(),
std::ceil(std::max({
font.getStringWidthFloat("This one spans"),
font.getStringWidthFloat("multiple lines."),
jive::calculateStringWidth("This one spans", font),
jive::calculateStringWidth("multiple lines.", font),
})));
expectEquals(boxModel.getHeight(),
std::ceil(font.getHeight()) * 2.0f);
Expand Down
2 changes: 1 addition & 1 deletion jive_layouts/layout/gui-items/flex/jive_FlexContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ class FlexContainerUnitTest : public juce::UnitTest
const auto& container = *window->getChildren()[0];
const auto& boxModel = jive::boxModel(container);
expectEquals(boxModel.getContentBounds().getWidth(),
std::ceil(font.getStringWidthFloat(textState["text"])));
std::ceil(jive::calculateStringWidth(textState["text"], font)));
expectEquals(boxModel.getContentBounds().getHeight(),
font.getHeight());
}
Expand Down
2 changes: 1 addition & 1 deletion jive_layouts/layout/gui-items/grid/jive_GridContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ class GridContainerTest : public juce::UnitTest
->getTextComponent()
.getFont();

const auto expectedWidth = std::ceil(font.getStringWidthFloat("hello")) + std::ceil(font.getStringWidthFloat("world"));
const auto expectedWidth = std::ceil(jive::calculateStringWidth("hello", font)) + std::ceil(jive::calculateStringWidth("world", font));
expectEquals(boxModel.getContentBounds().getWidth(), expectedWidth);

const auto expectedHeight = std::ceil(font.getHeight()) * 2.0f;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CPMDeclarePackage(JUCE
GIT_TAG 8.0.1
GIT_TAG 8.0.2
GITHUB_REPOSITORY juce-framework/JUCE
SYSTEM YES
EXCLUDE_FROM_ALL YES
Expand Down
4 changes: 3 additions & 1 deletion runners/demo-runner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ target_link_libraries(jive-demo
juce::juce_recommended_warning_flags
)

add_melatonin_inspector(jive-demo)
if (JIVE_ENABLE_MELATONIN_INSPECTOR)
add_melatonin_inspector(jive-demo)
endif ()

juce_add_gui_app(jive-demo-app
PRODUCT_NAME
Expand Down

0 comments on commit f61a3f3

Please sign in to comment.