From 3df07bcb92418f906ab29f72f6cda96ac07fc7f6 Mon Sep 17 00:00:00 2001 From: Alex Levenson Date: Sun, 7 Dec 2025 14:37:35 -0800 Subject: [PATCH] Add caption-gap property to Decorator Adds a new 'caption-gap' property that controls the spacing between the caption text and the component content. Works for all caption placements (top, bottom, left, right). Defaults to 0 for backwards compatibility. --- .../Editor/foleys_PropertiesEditor.cpp | 1 + .../General/foleys_StringDefinitions.h | 1 + .../Layout/foleys_Decorator.cpp | 17 +++++++++++++++++ .../foleys_gui_magic/Layout/foleys_Decorator.h | 1 + 4 files changed, 20 insertions(+) diff --git a/modules/foleys_gui_magic/Editor/foleys_PropertiesEditor.cpp b/modules/foleys_gui_magic/Editor/foleys_PropertiesEditor.cpp index 7e94ec5a..e1ac3d7f 100644 --- a/modules/foleys_gui_magic/Editor/foleys_PropertiesEditor.cpp +++ b/modules/foleys_gui_magic/Editor/foleys_PropertiesEditor.cpp @@ -276,6 +276,7 @@ void PropertiesEditor::addDecoratorProperties() array.add (new StyleChoicePropertyComponent (builder, IDs::visibility, styleItem, builder.createPropertiesMenuLambda())); array.add (new StyleTextPropertyComponent (builder, IDs::caption, styleItem)); array.add (new StyleTextPropertyComponent (builder, IDs::captionSize, styleItem)); + array.add (new StyleTextPropertyComponent (builder, IDs::captionGap, styleItem)); array.add (new StyleColourPropertyComponent (builder, IDs::captionColour, styleItem)); array.add (new StyleChoicePropertyComponent (builder, IDs::captionPlacement, styleItem, getAllKeyNames (makeJustificationsChoices()))); array.add (new StyleTextPropertyComponent (builder, IDs::tooltip, styleItem)); diff --git a/modules/foleys_gui_magic/General/foleys_StringDefinitions.h b/modules/foleys_gui_magic/General/foleys_StringDefinitions.h index b07b9b77..1fc00313 100644 --- a/modules/foleys_gui_magic/General/foleys_StringDefinitions.h +++ b/modules/foleys_gui_magic/General/foleys_StringDefinitions.h @@ -63,6 +63,7 @@ namespace IDs static juce::Identifier captionPlacement { "caption-placement" }; static juce::Identifier captionColour { "caption-color" }; static juce::Identifier captionSize { "caption-size" }; + static juce::Identifier captionGap { "caption-gap" }; static juce::Identifier lookAndFeel { "lookAndFeel" }; static juce::Identifier tooltip { "tooltip" }; static juce::Identifier tooltipText { "tooltip-text" }; diff --git a/modules/foleys_gui_magic/Layout/foleys_Decorator.cpp b/modules/foleys_gui_magic/Layout/foleys_Decorator.cpp index 8b586b08..d14569ac 100644 --- a/modules/foleys_gui_magic/Layout/foleys_Decorator.cpp +++ b/modules/foleys_gui_magic/Layout/foleys_Decorator.cpp @@ -134,18 +134,30 @@ Decorator::ClientBounds Decorator::getClientBounds (juce::Rectangle overall if (justification == juce::Justification::centred) captionBox = overallBounds; else if (justification.getOnlyVerticalFlags() & juce::Justification::top) + { captionBox = box.removeFromTop (captionSize).toNearestInt(); + box.removeFromTop (captionGap); + } else if (justification.getOnlyVerticalFlags() & juce::Justification::bottom) + { captionBox = box.removeFromBottom (captionSize).toNearestInt(); + box.removeFromBottom (captionGap); + } else { juce::Font f (juce::FontOptions().withHeight (captionSize * 0.8f)); auto w = float (f.getStringWidth (caption)); if (justification.getOnlyHorizontalFlags() & juce::Justification::left) + { captionBox = box.removeFromLeft (w).toNearestInt(); + box.removeFromLeft (captionGap); + } else if (justification.getOnlyHorizontalFlags() & juce::Justification::right) + { captionBox = box.removeFromRight (w).toNearestInt(); + box.removeFromRight (captionGap); + } } } @@ -182,6 +194,10 @@ void Decorator::configure (MagicGUIBuilder& builder, const juce::ValueTree& node if (! sizeVar.isVoid()) captionSize = static_cast (sizeVar); + auto gapVar = builder.getStyleProperty (IDs::captionGap, node); + if (! gapVar.isVoid()) + captionGap = static_cast (gapVar); + auto placementVar = builder.getStyleProperty (IDs::captionPlacement, node); if (! placementVar.isVoid() && placementVar.toString().isNotEmpty()) justification = juce::Justification (makeJustificationsChoices()[placementVar.toString()]); @@ -220,6 +236,7 @@ void Decorator::reset() caption.clear(); justification = juce::Justification::centredTop; captionSize = 20.0f; + captionGap = 0.0f; captionColour = juce::Colours::silver; tabCaption.clear(); diff --git a/modules/foleys_gui_magic/Layout/foleys_Decorator.h b/modules/foleys_gui_magic/Layout/foleys_Decorator.h index 1e00b6c4..6570bfda 100644 --- a/modules/foleys_gui_magic/Layout/foleys_Decorator.h +++ b/modules/foleys_gui_magic/Layout/foleys_Decorator.h @@ -83,6 +83,7 @@ class Decorator juce::String caption; juce::Justification justification = juce::Justification::centredTop; float captionSize = 20.0f; + float captionGap = 0.0f; juce::Colour captionColour = juce::Colours::silver; juce::String tabCaption;