Browse Source

GUI: Ensure components refresh correctly when their look and feel changes

tags/2021-05-28
reuk 5 years ago
parent
commit
39b5c22a29
No known key found for this signature in database GPG Key ID: 9ADCD339CFC98A11
10 changed files with 48 additions and 14 deletions
  1. +9
    -5
      modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.cpp
  2. +6
    -3
      modules/juce_gui_basics/menus/juce_BurgerMenuComponent.cpp
  3. +3
    -0
      modules/juce_gui_basics/menus/juce_BurgerMenuComponent.h
  4. +9
    -1
      modules/juce_gui_basics/properties/juce_PropertyPanel.cpp
  5. +6
    -1
      modules/juce_gui_basics/widgets/juce_Toolbar.cpp
  6. +2
    -0
      modules/juce_gui_basics/widgets/juce_Toolbar.h
  7. +3
    -3
      modules/juce_gui_basics/windows/juce_CallOutBox.cpp
  8. +2
    -0
      modules/juce_gui_basics/windows/juce_CallOutBox.h
  9. +6
    -1
      modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp
  10. +2
    -0
      modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.h

+ 9
- 5
modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.cpp View File

@@ -105,16 +105,15 @@ FileBrowserComponent::FileBrowserComponent (int flags_,
addAndMakeVisible (fileLabel); addAndMakeVisible (fileLabel);
fileLabel.attachToComponent (&filenameBox, true); fileLabel.attachToComponent (&filenameBox, true);
goUpButton.reset (getLookAndFeel().createFileBrowserGoUpButton());
addAndMakeVisible (goUpButton.get());
goUpButton->onClick = [this] { goUp(); };
goUpButton->setTooltip (TRANS ("Go up to parent directory"));
if (previewComp != nullptr) if (previewComp != nullptr)
addAndMakeVisible (previewComp); addAndMakeVisible (previewComp);
lookAndFeelChanged(); lookAndFeelChanged();
addAndMakeVisible (goUpButton.get());
goUpButton->onClick = [this] { goUp(); };
goUpButton->setTooltip (TRANS ("Go up to parent directory"));
setRoot (currentRoot); setRoot (currentRoot);
if (filename.isNotEmpty()) if (filename.isNotEmpty())
@@ -351,12 +350,17 @@ void FileBrowserComponent::resized()
//============================================================================== //==============================================================================
void FileBrowserComponent::lookAndFeelChanged() void FileBrowserComponent::lookAndFeelChanged()
{ {
goUpButton.reset (getLookAndFeel().createFileBrowserGoUpButton());
currentPathBox.setColour (ComboBox::backgroundColourId, findColour (currentPathBoxBackgroundColourId)); currentPathBox.setColour (ComboBox::backgroundColourId, findColour (currentPathBoxBackgroundColourId));
currentPathBox.setColour (ComboBox::textColourId, findColour (currentPathBoxTextColourId)); currentPathBox.setColour (ComboBox::textColourId, findColour (currentPathBoxTextColourId));
currentPathBox.setColour (ComboBox::arrowColourId, findColour (currentPathBoxArrowColourId)); currentPathBox.setColour (ComboBox::arrowColourId, findColour (currentPathBoxArrowColourId));
filenameBox.setColour (TextEditor::backgroundColourId, findColour (filenameBoxBackgroundColourId)); filenameBox.setColour (TextEditor::backgroundColourId, findColour (filenameBoxBackgroundColourId));
filenameBox.setColour (TextEditor::textColourId, findColour (filenameBoxTextColourId)); filenameBox.setColour (TextEditor::textColourId, findColour (filenameBoxTextColourId));
resized();
repaint();
} }
//============================================================================== //==============================================================================


+ 6
- 3
modules/juce_gui_basics/menus/juce_BurgerMenuComponent.cpp View File

@@ -56,9 +56,7 @@ struct CustomMenuBarItemHolder : public Component
//============================================================================== //==============================================================================
BurgerMenuComponent::BurgerMenuComponent (MenuBarModel* modelToUse) BurgerMenuComponent::BurgerMenuComponent (MenuBarModel* modelToUse)
{ {
auto& lf = getLookAndFeel();
listBox.setRowHeight (roundToInt (lf.getPopupMenuFont().getHeight() * 2.0f));
lookAndFeelChanged();
listBox.addMouseListener (this, true); listBox.addMouseListener (this, true);
setModel (modelToUse); setModel (modelToUse);
@@ -283,4 +281,9 @@ void BurgerMenuComponent::handleCommandMessage (int commandID)
} }
} }
void BurgerMenuComponent::lookAndFeelChanged()
{
listBox.setRowHeight (roundToInt (getLookAndFeel().getPopupMenuFont().getHeight() * 2.0f));
}
} // namespace juce } // namespace juce

+ 3
- 0
modules/juce_gui_basics/menus/juce_BurgerMenuComponent.h View File

@@ -62,6 +62,9 @@ public:
/** Returns the current burger menu model being used. */ /** Returns the current burger menu model being used. */
MenuBarModel* getModel() const noexcept; MenuBarModel* getModel() const noexcept;
/** @internal */
void lookAndFeelChanged() override;
private: private:
//============================================================================== //==============================================================================
struct Row struct Row


+ 9
- 1
modules/juce_gui_basics/properties/juce_PropertyPanel.cpp View File

@@ -25,9 +25,10 @@ struct PropertyPanel::SectionComponent : public Component
const Array<PropertyComponent*>& newProperties, const Array<PropertyComponent*>& newProperties,
bool sectionIsOpen) bool sectionIsOpen)
: Component (sectionTitle), : Component (sectionTitle),
titleHeight (getLookAndFeel().getPropertyPanelSectionHeaderHeight (sectionTitle)),
isOpen (sectionIsOpen) isOpen (sectionIsOpen)
{ {
lookAndFeelChanged();
propertyComps.addArray (newProperties); propertyComps.addArray (newProperties);
for (auto* propertyComponent : propertyComps) for (auto* propertyComponent : propertyComps)
@@ -59,6 +60,13 @@ struct PropertyPanel::SectionComponent : public Component
} }
} }
void lookAndFeelChanged() override
{
titleHeight = getLookAndFeel().getPropertyPanelSectionHeaderHeight (getName());
resized();
repaint();
}
int getPreferredHeight() const int getPreferredHeight() const
{ {
auto y = titleHeight; auto y = titleHeight;


+ 6
- 1
modules/juce_gui_basics/widgets/juce_Toolbar.cpp View File

@@ -235,7 +235,7 @@ private:
//============================================================================== //==============================================================================
Toolbar::Toolbar() Toolbar::Toolbar()
{ {
missingItemsButton.reset (getLookAndFeel().createToolbarMissingItemsButton (*this));
lookAndFeelChanged();
addChildComponent (missingItemsButton.get()); addChildComponent (missingItemsButton.get());
missingItemsButton->setAlwaysOnTop (true); missingItemsButton->setAlwaysOnTop (true);
@@ -633,6 +633,11 @@ void Toolbar::itemDropped (const SourceDetails& dragSourceDetails)
tc->setState (Button::buttonNormal); tc->setState (Button::buttonNormal);
} }
void Toolbar::lookAndFeelChanged()
{
missingItemsButton.reset (getLookAndFeel().createToolbarMissingItemsButton (*this));
}
void Toolbar::mouseDown (const MouseEvent&) {} void Toolbar::mouseDown (const MouseEvent&) {}
//============================================================================== //==============================================================================


+ 2
- 0
modules/juce_gui_basics/widgets/juce_Toolbar.h View File

@@ -296,6 +296,8 @@ public:
/** @internal */ /** @internal */
void itemDropped (const SourceDetails&) override; void itemDropped (const SourceDetails&) override;
/** @internal */ /** @internal */
void lookAndFeelChanged() override;
/** @internal */
void updateAllItemPositions (bool animate); void updateAllItemPositions (bool animate);
/** @internal */ /** @internal */
static ToolbarItemComponent* createItem (ToolbarItemFactory&, int itemId); static ToolbarItemComponent* createItem (ToolbarItemFactory&, int itemId);


+ 3
- 3
modules/juce_gui_basics/windows/juce_CallOutBox.cpp View File

@@ -44,9 +44,7 @@ CallOutBox::CallOutBox (Component& c, Rectangle<int> area, Component* const pare
creationTime = Time::getCurrentTime(); creationTime = Time::getCurrentTime();
} }
CallOutBox::~CallOutBox()
{
}
CallOutBox::~CallOutBox() = default;
//============================================================================== //==============================================================================
class CallOutBoxCallback : public ModalComponentManager::Callback, class CallOutBoxCallback : public ModalComponentManager::Callback,
@@ -94,6 +92,8 @@ int CallOutBox::getBorderSize() const noexcept
return jmax (getLookAndFeel().getCallOutBoxBorderSize (*this), (int) arrowSize); return jmax (getLookAndFeel().getCallOutBoxBorderSize (*this), (int) arrowSize);
} }
void CallOutBox::lookAndFeelChanged() { resized(); repaint(); }
void CallOutBox::paint (Graphics& g) void CallOutBox::paint (Graphics& g)
{ {
getLookAndFeel().drawCallOutBoxBackground (*this, g, outline, background); getLookAndFeel().drawCallOutBoxBackground (*this, g, outline, background);


+ 2
- 0
modules/juce_gui_basics/windows/juce_CallOutBox.h View File

@@ -159,6 +159,8 @@ public:
void handleCommandMessage (int) override; void handleCommandMessage (int) override;
/** @internal */ /** @internal */
int getBorderSize() const noexcept; int getBorderSize() const noexcept;
/** @internal */
void lookAndFeelChanged() override;
private: private:
//============================================================================== //==============================================================================


+ 6
- 1
modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp View File

@@ -341,7 +341,7 @@ CodeEditorComponent::CodeEditorComponent (CodeDocument& doc, CodeTokeniser* cons
setMouseCursor (MouseCursor::IBeamCursor); setMouseCursor (MouseCursor::IBeamCursor);
setWantsKeyboardFocus (true); setWantsKeyboardFocus (true);
caret.reset (getLookAndFeel().createCaretComponent (this));
lookAndFeelChanged();
addAndMakeVisible (caret.get()); addAndMakeVisible (caret.get());
addAndMakeVisible (verticalScrollBar); addAndMakeVisible (verticalScrollBar);
@@ -1308,6 +1308,11 @@ bool CodeEditorComponent::perform (const InvocationInfo& info)
return performCommand (info.commandID); return performCommand (info.commandID);
} }
void CodeEditorComponent::lookAndFeelChanged()
{
caret.reset (getLookAndFeel().createCaretComponent (this));
}
bool CodeEditorComponent::performCommand (const CommandID commandID) bool CodeEditorComponent::performCommand (const CommandID commandID)
{ {
switch (commandID) switch (commandID)


+ 2
- 0
modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.h View File

@@ -371,6 +371,8 @@ public:
void getCommandInfo (CommandID, ApplicationCommandInfo&) override; void getCommandInfo (CommandID, ApplicationCommandInfo&) override;
/** @internal */ /** @internal */
bool perform (const InvocationInfo&) override; bool perform (const InvocationInfo&) override;
/** @internal */
void lookAndFeelChanged() override;
private: private:
//============================================================================== //==============================================================================


Loading…
Cancel
Save