add basic data members and methods for adding an explicit size allocation for Canvas...
authorPaul Davis <paul@linuxaudiosystems.com>
Fri, 20 Jan 2017 11:08:58 +0000 (12:08 +0100)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 1 Feb 2017 20:58:20 +0000 (21:58 +0100)
libs/canvas/canvas/item.h
libs/canvas/item.cc

index 517b4401baefc89e0f5c7bb8597e2fe5eaad8a64..a480ec38a1a8ce891fe20c731f2ea5dd5ed05adc 100644 (file)
@@ -136,7 +136,18 @@ public:
 
        ScrollGroup* scroll_parent() const { return _scroll_parent; }
 
-       Rect bounding_box () const;
+       /* item implementations can override this if they need to */
+       virtual Rect size_request() const { return bounding_box (true); }
+       void size_allocate (Rect const&);
+
+       /** bounding box is the public API to get the size of the item.
+          If @param for_own_purposes is false, then it will return the
+          allocated bounding box (if there is one) in preference to the
+          one that would naturally be computed by the item.
+       */
+       Rect bounding_box (bool for_own_purposes = false) const;
+       Rect allocation() const { return _allocation; }
+
         Coord height() const;
         Coord width() const;
 
@@ -281,6 +292,7 @@ protected:
        mutable Rect _bounding_box;
        /** true if _bounding_box might be out of date, false if its definitely not */
        mutable bool _bounding_box_dirty;
+       Rect _allocation;
 
        /* XXX: this is a bit grubby */
        std::map<std::string, void *> _data;
index 06ad24f2e630c2d8c7c3154863c05baa4f219d56..589f1214b7d4f2b96b01129942a958548b08bdb9 100644 (file)
@@ -571,9 +571,15 @@ Item::grab_focus ()
        /* XXX */
 }
 
+void
+Item::size_allocate (Rect const & r)
+{
+       _allocation = r;
+}
+
 /** @return Bounding box in this item's coordinates */
 ArdourCanvas::Rect
-Item::bounding_box () const
+Item::bounding_box (bool for_own_purposes) const
 {
        if (_bounding_box_dirty) {
                compute_bounding_box ();
@@ -581,6 +587,12 @@ Item::bounding_box () const
                add_child_bounding_boxes ();
        }
 
+       if (!for_own_purposes) {
+               if (_allocation) {
+                       return _allocation;
+               }
+       }
+
        return _bounding_box;
 }