Преглед изворни кода

#313: the empty-state card is an overlay above its view, never inside the view's cached picture

The Playlist keeps its picture in a cache that a scroll shifts and a zoom scales
(PlayheadCache, paintEntireComponent), and the card, a child of the Playlist, was
painted into it: each wheel step left shifted or stretched copies of the card
(the issue's video). The card is now a sibling right above its view in the view's
parent, placed in view coordinates, following the view's moves, size, visibility
and docking. (round 190rs)
Ka1-S пре 1 недеља
родитељ
комит
78490a332a
3 измењених фајлова са 53 додато и 30 уклоњено
  1. 1 1
      src/ui/MainOnboarding.cpp
  2. 42 21
      src/ui/Onboarding.cpp
  3. 10 8
      src/ui/Onboarding.h

+ 1 - 1
src/ui/MainOnboarding.cpp

@@ -483,7 +483,7 @@ void MainComponent::updateEmptyHint()
             kind = EmptyHint::none;
     }
     juce::Component* parent = kind == EmptyHint::clipGrid ? clipGridView.get() : kind == EmptyHint::none ? nullptr : static_cast<juce::Component*> (&playlist);
-    if (emptyHint != nullptr && (emptyHint->getKind() != kind || emptyHint->getParentComponent() != parent))
+    if (emptyHint != nullptr && (emptyHint->getKind() != kind || emptyHint->getView() != parent))
     {
         emptyHint->attachTo (nullptr);
         emptyHint.reset();

+ 42 - 21
src/ui/Onboarding.cpp

@@ -816,53 +816,74 @@ int EmptyHintCard::idealHeight() const
          + (buttons.isEmpty() ? 0 : 30) + 22;
 }
 
-void EmptyHintCard::attachTo (juce::Component* parent)
+// Issue #313 (round 190rs): the card is an overlay ABOVE its view, a sibling of it in the view's parent, never a child of the
+// view. The Playlist (and the clip grid) keep their picture in a cache that a scroll shifts and a zoom scales
+// (PlaylistComponent::PlayheadCache); as a child the card was painted into that picture, so every wheel step left shifted
+// or stretched copies of it in the view (#313's video: two or three cards side by side). It is placed in view coordinates
+// and follows the view's moves, size and visibility.
+void EmptyHintCard::attachTo (juce::Component* view)
 {
-    if (watched != nullptr && watched != parent)
+    if (watched != nullptr && watched != view)
         watched->removeComponentListener (this);
-    if (parent == nullptr)
+    auto* host = view != nullptr ? view->getParentComponent() : nullptr;
+    if (view == nullptr || host == nullptr)
     {
         if (auto* p = getParentComponent())
             p->removeChildComponent (this);
         watched = nullptr;
         return;
     }
-    const auto fresh = getParentComponent() != parent;
+    const auto fresh = watched != view || getParentComponent() != host;
     if (fresh)
     {
-        parent->addAndMakeVisible (*this);
-        parent->addComponentListener (this);
-        watched = parent;
+        if (auto* p = getParentComponent())
+            p->removeChildComponent (this);
+        view->addComponentListener (this);
+        watched = view;
+    }
+    // right above the view in its parent's z-order (a window docked over the view stays over the card)
+    if (fresh || host->getIndexOfChildComponent (this) != host->getIndexOfChildComponent (view) + 1)
+    {
+        if (! fresh)
+            host->removeChildComponent (this);
+        host->addChildComponent (this, host->getIndexOfChildComponent (view) + 1);
     }
-    toFront (false);
     place (fresh || ! pinned);
 }
 
 void EmptyHintCard::place (bool force)
 {
-    auto* parent = getParentComponent();
-    if (parent == nullptr)
+    auto* view = watched.getComponent();
+    if (view == nullptr || getParentComponent() == nullptr || view->getParentComponent() != getParentComponent())
         return;
-    // issue #313: a card already laid out for this size of its parent stays where it is, also when it is shown again (the
-    // area it centres in moved by a lane's height while the view was scrolled, and the card jumped with it)
-    // (a card made again for the same view, after a hide, takes the place the last one of its kind had there)
+    const auto viewBounds = view->getBoundsInParent();
+    const auto show = [this, view] (bool fits) { setVisible (fits && view->isVisible()); };
+    // issue #313: a card already laid out for this place and size of its view stays where it is, also when it is shown
+    // again (a card made again for the same view takes the place the last one of its kind had there)
     static std::map<int, std::pair<juce::Rectangle<int>, juce::Rectangle<int>>> lastPlace;
     if (pinned && placed.isEmpty())
-        if (const auto it = lastPlace.find ((int) kind); it != lastPlace.end() && it->second.first == parent->getLocalBounds())
+        if (const auto it = lastPlace.find ((int) kind); it != lastPlace.end() && it->second.first == viewBounds)
             placedFor = it->second.first, placed = it->second.second;
-    if (pinned && ! placed.isEmpty() && placedFor == parent->getLocalBounds())
+    if (pinned && ! force && ! placed.isEmpty() && placedFor == viewBounds)
     {
         if (getBounds() != placed)
             setBounds (placed);
-        juce::ignoreUnused (force);
+        show (placedFits);
+        return;
+    }
+    if (pinned && force && ! placed.isEmpty() && placedFor == viewBounds)
+    {
+        setBounds (placed);
+        show (placedFits);
         return;
     }
-    placedFor = parent->getLocalBounds();
-    auto area = where ? where() : parent->getLocalBounds();
-    area = area.getIntersection (parent->getLocalBounds()).reduced (12);
+    placedFor = viewBounds;
+    auto area = where ? where() : view->getLocalBounds();
+    area = area.getIntersection (view->getLocalBounds()).reduced (12);
     const auto w = juce::jmin (width, area.getWidth()), h = juce::jmin (idealHeight(), area.getHeight());
-    setVisible (w >= 260 && h >= 120); // (a tiny view: no hint)
-    setBounds (area.withSizeKeepingCentre (w, h));
+    placedFits = w >= 260 && h >= 120; // (a tiny view: no hint)
+    setBounds (area.withSizeKeepingCentre (w, h) + viewBounds.getPosition());
+    show (placedFits);
     placed = getBounds();
     lastPlace[(int) kind] = { placedFor, placed };
 }

+ 10 - 8
src/ui/Onboarding.h

@@ -118,8 +118,10 @@ public:
     EmptyHintCard (onboarding::EmptyHint kind, std::vector<Button> buttons, std::function<juce::Rectangle<int>()> where = {});
     ~EmptyHintCard() override;
     onboarding::EmptyHint getKind() const noexcept { return kind; }
-    // shown over `parent` (or hidden: nullptr); placed again when the parent is resized
-    void attachTo (juce::Component* parent);
+    // shown over `view` (or hidden: nullptr), as an overlay in the view's parent right above it (issue #313); placed again
+    // when the view moves or changes size
+    void attachTo (juce::Component* view);
+    juce::Component* getView() const noexcept { return watched.getComponent(); }
     // Issue #313 (round 190rs): the card is laid out when it is attached and when its parent changes size, never again in
     // between (a zoom or scroll step of the view under it re-asked for its place and the card jumped). `force`: lay out now.
     void place (bool force = true);
@@ -131,12 +133,12 @@ public:
     bool hitTest (int x, int y) override; // only the buttons take the mouse
 
 private:
-    void componentMovedOrResized (juce::Component&, bool, bool wasResized) override
-    {
-        if (wasResized)
-            place();
-    }
-    juce::Rectangle<int> placedFor, placed; // the parent's bounds the card was laid out for, and where it went
+    void componentMovedOrResized (juce::Component&, bool, bool) override { place(); }
+    void componentVisibilityChanged (juce::Component&) override { place(); }
+    void componentParentHierarchyChanged (juce::Component& view) override { attachTo (&view); } // (a view docked elsewhere)
+    void componentBeingDeleted (juce::Component&) override { attachTo (nullptr); }
+    juce::Rectangle<int> placedFor, placed; // the view's bounds (in its parent) the card was laid out for, and where it went
+    bool placedFits = true;
     onboarding::EmptyHint kind;
     std::function<juce::Rectangle<int>()> where;
     juce::OwnedArray<juce::TextButton> buttons;