From 5265bbf81ef860d2dbeb6cc12e7821fabf85708b Mon Sep 17 00:00:00 2001 From: hogliux Date: Mon, 20 Jul 2015 15:05:58 +0100 Subject: [PATCH] Add optional setDrawsInRightMargin to disable clipping of right edge of TreeViewItems --- modules/juce_gui_basics/widgets/juce_TreeView.cpp | 10 ++++++++-- modules/juce_gui_basics/widgets/juce_TreeView.h | 13 +++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/modules/juce_gui_basics/widgets/juce_TreeView.cpp b/modules/juce_gui_basics/widgets/juce_TreeView.cpp index 2e811d8e79..ef3593aec4 100644 --- a/modules/juce_gui_basics/widgets/juce_TreeView.cpp +++ b/modules/juce_gui_basics/widgets/juce_TreeView.cpp @@ -1150,6 +1150,7 @@ TreeViewItem::TreeViewItem() drawLinesInside (false), drawLinesSet (false), drawsInLeftMargin (false), + drawsInRightMargin (false), openness (opennessDefault) { static int nextUID = 0; @@ -1505,6 +1506,11 @@ void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) noexcept drawsInLeftMargin = canDrawInLeftMargin; } +void TreeViewItem::setDrawsInRightMargin (bool canDrawInRightMargin) noexcept +{ + drawsInRightMargin = canDrawInRightMargin; +} + namespace TreeViewHelpers { static int calculateDepth (const TreeViewItem* item, const bool rootIsVisible) noexcept @@ -1532,7 +1538,7 @@ void TreeViewItem::paintRecursively (Graphics& g, int width) return; const int indent = getIndentX(); - const int itemW = itemWidth < 0 ? width - indent : itemWidth; + const int itemW = (itemWidth < 0 || drawsInRightMargin) ? width - indent : itemWidth; { Graphics::ScopedSaveState ss (g); @@ -1544,7 +1550,7 @@ void TreeViewItem::paintRecursively (Graphics& g, int width) if (isSelected()) g.fillAll (ownerView->findColour (TreeView::selectedItemBackgroundColourId)); - paintItem (g, itemW, itemHeight); + paintItem (g, itemWidth < 0 ? width - indent : itemWidth, itemHeight); } } diff --git a/modules/juce_gui_basics/widgets/juce_TreeView.h b/modules/juce_gui_basics/widgets/juce_TreeView.h index a5a51e53ae..79725e8b93 100644 --- a/modules/juce_gui_basics/widgets/juce_TreeView.h +++ b/modules/juce_gui_basics/widgets/juce_TreeView.h @@ -446,6 +446,18 @@ public: */ void setDrawsInLeftMargin (bool canDrawInLeftMargin) noexcept; + /** Sets a flag to indicate that the item wants to be allowed + to draw all the way across to the left edge of the treeview. + + Similar to setDrawsInLeftMargin: when this flag is set to true, + then the graphics context isn't clipped on the right side. Note, + that, in contrast to setDrawsInLeftMargin, you will very rarely need + to use this function, as, by default, the paintItem() method + won't be clipped on the right hand side, unless your TreeViewItem + overrides getItemWidth. + */ + void setDrawsInRightMargin (bool canDrawInRightMargin) noexcept; + //============================================================================== /** Saves the current state of open/closed nodes so it can be restored later. @@ -544,6 +556,7 @@ private: bool drawLinesInside : 1; bool drawLinesSet : 1; bool drawsInLeftMargin : 1; + bool drawsInRightMargin : 1; unsigned int openness : 2; friend class TreeView;