From e360d8305718ce74f03ff7f8e207f60d0c2233d2 Mon Sep 17 00:00:00 2001 From: Oliver James Date: Wed, 11 Dec 2024 15:20:40 +0000 Subject: [PATCH] PopupMenu: Move IdealSize modifiers to LookAndFeel --- BREAKING_CHANGES.md | 25 +++++++++++++++++++ .../lookandfeel/juce_LookAndFeel_V2.cpp | 3 +++ .../lookandfeel/juce_LookAndFeel_V4.cpp | 3 +++ .../juce_gui_basics/menus/juce_PopupMenu.cpp | 2 -- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 403b6bace7..1093d1cebc 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -3,6 +3,31 @@ # Version 8.0.4 +## Change + +HeaderItemComponent::getIdealSize no longer applies modifiers to the result +directly. Instead, these changes have been moved to the respective LookAndFeel +methods, enabling better customization. + +**Possible Issues** + +Code that overrides LookAndFeel::getIdealPopupMenuItemSize and relied on the +previous modifiers applied in HeaderItemComponent::getIdealSize may now behave +differently. + +**Workaround** + +Review any overrides of LookAndFeel::getIdealPopupMenuItemSize and apply the +necessary adjustments to account for any missing modifiers or changes in +behavior. + +**Rationale** + +The previous approach did not allow users to customize the applied modifiers +through the LookAndFeel class. Moving this logic to LookAndFeel methods ensures +consistent and flexible customization. + + ## Change The behavior of AudioTransportSource::hasStreamFinished has been updated to diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp index 909ead8057..755e691b3f 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp @@ -899,6 +899,9 @@ void LookAndFeel_V2::getIdealPopupMenuItemSizeWithOptions (const String& text, standardMenuItemHeight, idealWidth, idealHeight); + + idealHeight += idealHeight / 2; + idealWidth += idealWidth / 4; } void LookAndFeel_V2::drawPopupMenuBackground (Graphics& g, int width, int height) diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp index a9ed7700fb..d611bb9a95 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp @@ -884,6 +884,9 @@ void LookAndFeel_V4::getIdealPopupMenuItemSize (const String& text, const bool i idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f); idealWidth = GlyphArrangement::getStringWidthInt (font, text) + idealHeight * 2; } + + idealHeight += idealHeight / 2; + idealWidth += idealWidth / 4; } void LookAndFeel_V4::drawMenuBarBackground (Graphics& g, int width, int height, diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp index 5359695365..69129d3696 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp @@ -90,8 +90,6 @@ struct HeaderItemComponent final : public PopupMenu::CustomComponent idealWidth, idealHeight, options); - idealHeight += idealHeight / 2; - idealWidth += idealWidth / 4; } std::unique_ptr createAccessibilityHandler() override