Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Themes support for components #13

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4a5d8a5
Allow ReferenceCountedObject to send around const pointers
kunitoki Aug 1, 2024
0132fa1
Allow fonts to be constructed without a rive::Factory
kunitoki Aug 1, 2024
af88187
Add ApplicationThheme and initial theme (v1)
kunitoki Aug 1, 2024
94b5835
Code formatting
yup-bot Aug 1, 2024
bbd4d38
Fix ide grouping
kunitoki Aug 1, 2024
d58539d
Code formatting
yup-bot Aug 1, 2024
27f9450
Fix formatting
kunitoki Aug 1, 2024
e4822d4
Code formatting
yup-bot Aug 1, 2024
2d7bb67
Fix formatted comment tricking the clang formatter
kunitoki Aug 1, 2024
c06f8c3
Code formatting
yup-bot Aug 1, 2024
929aa2d
Added tests
kunitoki Aug 1, 2024
25e8fc3
Get rid of formatting issues
kunitoki Aug 1, 2024
157d810
Code formatting
yup-bot Aug 1, 2024
24cfc18
Allow using Identifier in std::unordered_map
kunitoki Aug 1, 2024
e34cc87
Allow components to work with colors
kunitoki Aug 1, 2024
0e20445
Code formatting
yup-bot Aug 1, 2024
7ddfdce
Avoid getting crazy with clang format
kunitoki Aug 1, 2024
cfeac25
Code formatting
yup-bot Aug 1, 2024
53a1104
Code formatting
kunitoki Aug 1, 2024
1c29716
Code formatting
yup-bot Aug 1, 2024
3ee53ea
Merge branch 'main' into dev/themes
kunitoki Aug 20, 2024
e449cb0
Code formatting
yup-bot Aug 20, 2024
4bb408e
Merge branch 'main' into dev/themes
kunitoki Oct 30, 2024
24005e2
Code formatting
yup-bot Oct 30, 2024
c7883ea
Merge branch 'main' into dev/themes
kunitoki Oct 30, 2024
c006fca
Code formatting
yup-bot Oct 30, 2024
0a045a9
More themes work
kunitoki Nov 4, 2024
2a5d42f
Code formatting
yup-bot Nov 4, 2024
d494894
Merge branch 'main' into dev/themes
kunitoki Nov 4, 2024
133f1db
Merge branch 'main' into dev/themes
kunitoki Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions cmake/yup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,3 @@ function (_yup_setup_platform)
set (yup_platform "${yup_platform}" PARENT_SCOPE)
endfunction()

#==============================================================================

include (${CMAKE_CURRENT_LIST_DIR}/yup_utilities.cmake)
include (${CMAKE_CURRENT_LIST_DIR}/yup_platforms.cmake)
include (${CMAKE_CURRENT_LIST_DIR}/yup_dependencies.cmake)
include (${CMAKE_CURRENT_LIST_DIR}/yup_modules.cmake)
include (${CMAKE_CURRENT_LIST_DIR}/yup_standalone.cmake)
include (${CMAKE_CURRENT_LIST_DIR}/yup_audio_plugin.cmake)
include (${CMAKE_CURRENT_LIST_DIR}/yup_embed_binary.cmake)
3 changes: 1 addition & 2 deletions examples/graphics/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ class CustomWindow

setTitle ("main");

// Load the font
yup::File fontFilePath =
#if JUCE_WASM
yup::File ("/data")
Expand All @@ -146,7 +145,7 @@ class CustomWindow
#endif
.getChildFile ("Roboto-Regular.ttf");

if (auto result = font.loadFromFile (fontFilePath, factory); result.failed())
if (auto result = font.loadFromFile (fontFilePath); result.failed())
yup::Logger::outputDebugString (result.getErrorMessage());

// Initialize the audio device
Expand Down
4 changes: 3 additions & 1 deletion modules/juce_audio_basics/juce_audio_basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@
==============================================================================
*/

// clang-format off
#ifdef JUCE_AUDIO_BASICS_H_INCLUDED
/* When you add this cpp file to your project, you mustn't include it in a file where you've
already included any other headers - just put it inside a file on its own, possibly with your config
flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix
header files that the compiler may be using.
*/
*/
#error "Incorrect use of JUCE cpp file"
#endif
// clang-format on

#include "juce_audio_basics.h"

Expand Down
18 changes: 13 additions & 5 deletions modules/juce_audio_devices/juce_audio_devices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@
==============================================================================
*/

// clang-format off
#ifdef JUCE_AUDIO_DEVICES_H_INCLUDED
/* When you add this cpp file to your project, you mustn't include it in a file where you've
already included any other headers - just put it inside a file on its own, possibly with your config
flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix
header files that the compiler may be using.
*/
*/
#error "Incorrect use of JUCE cpp file"
#endif
// clang-format on

#define JUCE_CORE_INCLUDE_OBJC_HELPERS 1
#define JUCE_CORE_INCLUDE_COM_SMART_PTR 1
Expand Down Expand Up @@ -114,6 +116,7 @@
#include "native/juce_DirectSound_windows.cpp"
#endif

// clang-format off
#if JUCE_USE_WINRT_MIDI && (JUCE_MSVC || JUCE_CLANG)
/* If you cannot find any of the header files below then you are probably
attempting to use the Windows 10 Bluetooth Low Energy API. For this to work you
Expand All @@ -136,10 +139,12 @@ JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4467)
#include <robuffer.h>
JUCE_END_IGNORE_WARNINGS_MSVC
#endif
// clang-format on

#include <juce_audio_basics/midi/juce_MidiDataConcatenator.h>
#include "native/juce_Midi_windows.cpp"

// clang-format off
#if JUCE_ASIO
/* This is very frustrating - we only need to use a handful of definitions from
a couple of the header files in Steinberg's ASIO SDK, and it'd be easy to copy
Expand All @@ -163,9 +168,11 @@ JUCE_END_IGNORE_WARNINGS_MSVC
#include <iasiodrv.h>
#include "native/juce_ASIO_windows.cpp"
#endif
// clang-format oon

//==============================================================================
#elif JUCE_LINUX || JUCE_BSD
// clang-format off
#if JUCE_ALSA
/* Got an include error here? If so, you've either not got ALSA installed, or you've
not got your paths set up correctly to find its header files.
Expand Down Expand Up @@ -195,15 +202,16 @@ JUCE_END_IGNORE_WARNINGS_GCC_LIKE
#endif

#if (JUCE_LINUX && JUCE_BELA)
/* Got an include error here? If so, you've either not got the bela headers
installed, or you've not got your paths set up correctly to find its header
files.
*/
/* Got an include error here? If so, you've either not got the bela headers
installed, or you've not got your paths set up correctly to find its header
files.
*/
#include <Bela.h>
#include <Midi.h>
#include <juce_audio_basics/midi/juce_MidiDataConcatenator.h>
#include "native/juce_Bela_linux.cpp"
#endif
// clang-format on

#undef SIZEOF

Expand Down
4 changes: 3 additions & 1 deletion modules/juce_core/juce_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@
==============================================================================
*/

// clang-format off
#ifdef JUCE_CORE_H_INCLUDED
/* When you add this cpp file to your project, you mustn't include it in a file where you've
already included any other headers - just put it inside a file on its own, possibly with your config
flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix
header files that the compiler may be using.
*/
*/
#error "Incorrect use of JUCE cpp file"
#endif
// clang-format on

#define JUCE_CORE_INCLUDE_OBJC_HELPERS 1
#define JUCE_CORE_INCLUDE_COM_SMART_PTR 1
Expand Down
2 changes: 1 addition & 1 deletion modules/juce_core/memory/juce_ReferenceCountedObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class JUCE_API ReferenceCountedObject
/** Resets the reference count to zero without deleting the object.
You should probably never need to use this!
*/
void resetReferenceCount() noexcept
void resetReferenceCount() const noexcept
{
refCount = 0;
}
Expand Down
6 changes: 4 additions & 2 deletions modules/juce_events/juce_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@
==============================================================================
*/

// clang-format off
#ifdef JUCE_EVENTS_H_INCLUDED
/* When you add this cpp file to your project, you mustn't include it in a file where you've
/* When you add this cpp file to your project, you mustn't include it in a file where you've
already included any other headers - just put it inside a file on its own, possibly with your config
flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix
header files that the compiler may be using.
*/
*/
#error "Incorrect use of JUCE cpp file"
#endif
// clang-format on

#define JUCE_CORE_INCLUDE_OBJC_HELPERS 1
#define JUCE_CORE_INCLUDE_JNI_HELPERS 1
Expand Down
4 changes: 3 additions & 1 deletion modules/yup_audio_plugin_client/yup_audio_plugin_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
==============================================================================
*/

// clang-format off
#ifdef YUP_AUDIO_PLUGIN_CLIENT_H_INCLUDED
/* When you add this cpp file to your project, you mustn't include it in a file where you've
already included any other headers - just put it inside a file on its own, possibly with your config
flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix
header files that the compiler may be using.
*/
*/
#error "Incorrect use of YUP cpp file"
#endif
// clang-format on

#include "yup_audio_plugin_client.h"

Expand Down
4 changes: 3 additions & 1 deletion modules/yup_audio_processors/yup_audio_processors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
==============================================================================
*/

// clang-format off
#ifdef YUP_AUDIO_PROCESSORS_H_INCLUDED
/* When you add this cpp file to your project, you mustn't include it in a file where you've
already included any other headers - just put it inside a file on its own, possibly with your config
flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix
header files that the compiler may be using.
*/
*/
#error "Incorrect use of YUP cpp file"
#endif
// clang-format on

#include "yup_audio_processors.h"

Expand Down
16 changes: 8 additions & 8 deletions modules/yup_graphics/fonts/yup_Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ namespace yup

//==============================================================================

Font::Font (const MemoryBlock& fontBytes, rive::Factory* factory)
Font::Font (const MemoryBlock& fontBytes)
{
loadFromData (fontBytes, factory);
loadFromData (fontBytes);
}

Font::Font (const File& fontFile, rive::Factory* factory)
Font::Font (const File& fontFile)
{
loadFromFile (fontFile, factory);
loadFromFile (fontFile);
}

//==============================================================================

Result Font::loadFromData (const MemoryBlock& fontBytes, rive::Factory* factory)
Result Font::loadFromData (const MemoryBlock& fontBytes)
{
font = factory->decodeFont (rive::Span<const uint8_t> { static_cast<const uint8_t*> (fontBytes.getData()), fontBytes.getSize() });
font = HBFont::Decode (rive::Span<const uint8_t> { static_cast<const uint8_t*> (fontBytes.getData()), fontBytes.getSize() });
return font ? Result::ok() : Result::fail ("Unable to load font");
}

Result Font::loadFromFile (const File& fontFile, rive::Factory* factory)
Result Font::loadFromFile (const File& fontFile)
{
if (! fontFile.existsAsFile())
return Result::fail ("Unable to load font from non existing file");
Expand All @@ -52,7 +52,7 @@ Result Font::loadFromFile (const File& fontFile, rive::Factory* factory)
yup::MemoryBlock mb;
is->readIntoMemoryBlock (mb);

font = factory->decodeFont (rive::Span<const uint8_t> { static_cast<const uint8_t*> (mb.getData()), mb.getSize() });
font = HBFont::Decode (rive::Span<const uint8_t> { static_cast<const uint8_t*> (mb.getData()), mb.getSize() });
if (! font)
return Result::fail ("Unable to load font");
}
Expand Down
8 changes: 4 additions & 4 deletions modules/yup_graphics/fonts/yup_Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class JUCE_API Font
Font() = default;

//==============================================================================
Font (const MemoryBlock& fontBytes, rive::Factory* factory);
Font (const File& fontFile, rive::Factory* factory);
Font (const MemoryBlock& fontBytes);
Font (const File& fontFile);

//==============================================================================
/** Copy and move constructors and assignment operators. */
Expand All @@ -42,10 +42,10 @@ class JUCE_API Font
Font& operator= (Font&& other) noexcept = default;

//==============================================================================
Result loadFromData (const MemoryBlock& fontBytes, rive::Factory* factory);
Result loadFromData (const MemoryBlock& fontBytes);

//==============================================================================
Result loadFromFile (const File& fontFile, rive::Factory* factory);
Result loadFromFile (const File& fontFile);

//==============================================================================
rive::rcp<rive::Font> getFont() const;
Expand Down
8 changes: 7 additions & 1 deletion modules/yup_graphics/yup_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@
==============================================================================
*/

// clang-format off
#ifdef YUP_GRAPHICS_H_INCLUDED
/* When you add this cpp file to your project, you mustn't include it in a file where you've
already included any other headers - just put it inside a file on its own, possibly with your config
flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix
header files that the compiler may be using.
*/
*/
#error "Incorrect use of YUP cpp file"
#endif
// clang-format on

#include "yup_graphics.h"

//==============================================================================

#include <rive/text/font_hb.hpp>

//==============================================================================

#if JUCE_WINDOWS

#if YUP_RIVE_USE_D3D
Expand Down
29 changes: 29 additions & 0 deletions modules/yup_gui/component/yup_Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,35 @@ bool Component::hasFocus() const

//==============================================================================

Color Component::findColor (const Identifier& colorId) const
{
if (auto color = getColor (colorId))
return *color;

if (parentComponent != nullptr)
return parentComponent->findColor (colorId);

return ApplicationTheme::findColor (colorId);
}

void Component::setColor (const Identifier& colorId, const std::optional<Color>& color)
{
if (color)
properties.set (colorId, static_cast<int64> (color->getARGB()));
else
properties.remove (colorId);
}

std::optional<Color> Component::getColor (const Identifier& colorId) const
{
if (auto color = properties.getVarPointer (colorId); color != nullptr && color->isInt64())
return Color (static_cast<uint32> (static_cast<int64> (*color)));

return std::nullopt;
}

//==============================================================================

NamedValueSet& Component::getProperties()
{
return properties;
Expand Down
6 changes: 6 additions & 0 deletions modules/yup_gui/component/yup_Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ class JUCE_API Component
void leaveFocus();
bool hasFocus() const;

//==============================================================================
Color findColor (const Identifier& colorId) const;

void setColor (const Identifier& colorId, const std::optional<Color>& color);
std::optional<Color> getColor (const Identifier& colorId) const;

//==============================================================================
NamedValueSet& getProperties();
const NamedValueSet& getProperties() const;
Expand Down
3 changes: 3 additions & 0 deletions modules/yup_gui/native/yup_Windowing_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,9 @@ void initialiseYup_Windowing()
// Initialise glfw
glfwInit();

// Initialize global theme
ApplicationTheme::setGlobalTheme (createThemeVersion1());

// Setup monitor callback
{
Desktop::getInstance()->updateDisplays();
Expand Down
1 change: 1 addition & 0 deletions modules/yup_gui/themes/theme_v1/RobotoRegularFont.inc

Large diffs are not rendered by default.

Loading
Loading