summaryrefslogtreecommitdiff
path: root/indra/llui/lllayoutstack.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui/lllayoutstack.cpp')
-rw-r--r--indra/llui/lllayoutstack.cpp902
1 files changed, 492 insertions, 410 deletions
diff --git a/indra/llui/lllayoutstack.cpp b/indra/llui/lllayoutstack.cpp
index a250404292..2f1c2a47c9 100644
--- a/indra/llui/lllayoutstack.cpp
+++ b/indra/llui/lllayoutstack.cpp
@@ -34,6 +34,10 @@
#include "llpanel.h"
#include "llresizebar.h"
#include "llcriticaldamp.h"
+#include "boost/foreach.hpp"
+
+static const F32 MIN_FRACTIONAL_SIZE = 0.0001f;
+static const F32 MAX_FRACTIONAL_SIZE = 1.f;
static LLDefaultChildRegistry::Register<LLLayoutStack> register_layout_stack("layout_stack");
static LLLayoutStack::LayoutStackRegistry::Register<LLLayoutPanel> register_layout_panel("layout_panel");
@@ -47,26 +51,31 @@ void LLLayoutStack::OrientationNames::declareValues()
//
// LLLayoutPanel
//
+LLLayoutPanel::Params::Params()
+: expanded_min_dim("expanded_min_dim", 0),
+ min_dim("min_dim", -1),
+ user_resize("user_resize", false),
+ auto_resize("auto_resize", true)
+{
+ addSynonym(min_dim, "min_width");
+ addSynonym(min_dim, "min_height");
+}
+
LLLayoutPanel::LLLayoutPanel(const Params& p)
: LLPanel(p),
- mExpandedMinDimSpecified(false),
- mExpandedMinDim(p.min_dim),
+ mExpandedMinDim(p.expanded_min_dim.isProvided() ? p.expanded_min_dim : p.min_dim),
mMinDim(p.min_dim),
- mMaxDim(p.max_dim),
mAutoResize(p.auto_resize),
mUserResize(p.user_resize),
mCollapsed(FALSE),
mCollapseAmt(0.f),
mVisibleAmt(1.f), // default to fully visible
- mResizeBar(NULL)
+ mResizeBar(NULL),
+ mFractionalSize(MIN_FRACTIONAL_SIZE),
+ mTargetDim(0),
+ mIgnoreReshape(false),
+ mOrientation(LLLayoutStack::HORIZONTAL)
{
- // Set the expanded min dim if it is provided, otherwise it gets the p.min_dim value
- if (p.expanded_min_dim.isProvided())
- {
- mExpandedMinDimSpecified = true;
- mExpandedMinDim = p.expanded_min_dim();
- }
-
// panels initialized as hidden should not start out partially visible
if (!getVisible())
{
@@ -88,20 +97,83 @@ LLLayoutPanel::~LLLayoutPanel()
mResizeBar = NULL;
}
-F32 LLLayoutPanel::getCollapseFactor(LLLayoutStack::ELayoutOrientation orientation)
+F32 LLLayoutPanel::getAutoResizeFactor() const
+{
+ return mVisibleAmt * (1.f - mCollapseAmt);
+}
+
+F32 LLLayoutPanel::getVisibleAmount() const
+{
+ return mVisibleAmt;
+}
+
+S32 LLLayoutPanel::getLayoutDim() const
+{
+ return llround((F32)((mOrientation == LLLayoutStack::HORIZONTAL)
+ ? getRect().getWidth()
+ : getRect().getHeight()));
+}
+
+S32 LLLayoutPanel::getVisibleDim() const
{
- if (orientation == LLLayoutStack::HORIZONTAL)
+ F32 min_dim = getRelevantMinDim();
+ return llround(mVisibleAmt
+ * (min_dim
+ + (((F32)mTargetDim - min_dim) * (1.f - mCollapseAmt))));
+}
+
+void LLLayoutPanel::setOrientation( LLLayoutStack::ELayoutOrientation orientation )
+{
+ mOrientation = orientation;
+ S32 layout_dim = llround((F32)((mOrientation == LLLayoutStack::HORIZONTAL)
+ ? getRect().getWidth()
+ : getRect().getHeight()));
+
+ mTargetDim = llmax(layout_dim, getMinDim());
+}
+
+void LLLayoutPanel::setVisible( BOOL visible )
+{
+ if (visible != getVisible())
{
- F32 collapse_amt =
- clamp_rescale(mCollapseAmt, 0.f, 1.f, 1.f, (F32)getRelevantMinDim() / (F32)llmax(1, getRect().getWidth()));
- return mVisibleAmt * collapse_amt;
+ LLLayoutStack* stackp = dynamic_cast<LLLayoutStack*>(getParent());
+ if (stackp)
+ {
+ stackp->mNeedsLayout = true;
+ }
}
- else
+ LLPanel::setVisible(visible);
+}
+
+void LLLayoutPanel::reshape( S32 width, S32 height, BOOL called_from_parent /*= TRUE*/ )
+{
+ if (width == getRect().getWidth() && height == getRect().getHeight()) return;
+
+ if (!mIgnoreReshape && mAutoResize == false)
+ {
+ mTargetDim = (mOrientation == LLLayoutStack::HORIZONTAL) ? width : height;
+ LLLayoutStack* stackp = dynamic_cast<LLLayoutStack*>(getParent());
+ if (stackp)
+ {
+ stackp->mNeedsLayout = true;
+ }
+ }
+ LLPanel::reshape(width, height, called_from_parent);
+}
+
+void LLLayoutPanel::handleReshape(const LLRect& new_rect, bool by_user)
+{
+ LLLayoutStack* stackp = dynamic_cast<LLLayoutStack*>(getParent());
+ if (stackp)
{
- F32 collapse_amt =
- clamp_rescale(mCollapseAmt, 0.f, 1.f, 1.f, llmin(1.f, (F32)getRelevantMinDim() / (F32)llmax(1, getRect().getHeight())));
- return mVisibleAmt * collapse_amt;
+ stackp->mNeedsLayout = true;
+ if (by_user)
+ {
+ // tell layout stack to account for new shape
+ stackp->updatePanelRect(this, new_rect);
+ }
}
+ LLPanel::handleReshape(new_rect, by_user);
}
//
@@ -114,20 +186,21 @@ LLLayoutStack::Params::Params()
clip("clip", true),
open_time_constant("open_time_constant", 0.02f),
close_time_constant("close_time_constant", 0.03f),
+ resize_bar_overlap("resize_bar_overlap", 1),
border_size("border_size", LLCachedControl<S32>(*LLUI::sSettingGroups["config"], "UIResizeBarHeight", 0))
{}
LLLayoutStack::LLLayoutStack(const LLLayoutStack::Params& p)
: LLView(p),
- mMinWidth(0),
- mMinHeight(0),
mPanelSpacing(p.border_size),
mOrientation(p.orientation),
mAnimate(p.animate),
mAnimatedThisFrame(false),
+ mNeedsLayout(true),
mClip(p.clip),
mOpenTimeConstant(p.open_time_constant),
- mCloseTimeConstant(p.close_time_constant)
+ mCloseTimeConstant(p.close_time_constant),
+ mResizeBarOverlap(p.resize_bar_overlap)
{}
LLLayoutStack::~LLLayoutStack()
@@ -141,26 +214,26 @@ void LLLayoutStack::draw()
{
updateLayout();
- e_panel_list_t::iterator panel_it;
- for (panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
+ // always clip to stack itself
+ LLLocalClipRect clip(getLocalRect());
+ BOOST_FOREACH(LLLayoutPanel* panelp, mPanels)
{
// clip to layout rectangle, not bounding rectangle
- LLRect clip_rect = (*panel_it)->getRect();
+ LLRect clip_rect = panelp->getRect();
// scale clipping rectangle by visible amount
if (mOrientation == HORIZONTAL)
{
- clip_rect.mRight = clip_rect.mLeft + llround((F32)clip_rect.getWidth() * (*panel_it)->getCollapseFactor(mOrientation));
+ clip_rect.mRight = clip_rect.mLeft + panelp->getVisibleDim();
}
else
{
- clip_rect.mBottom = clip_rect.mTop - llround((F32)clip_rect.getHeight() * (*panel_it)->getCollapseFactor(mOrientation));
+ clip_rect.mBottom = clip_rect.mTop - panelp->getVisibleDim();
}
- LLPanel* panelp = (*panel_it);
-
- LLLocalClipRect clip(clip_rect, mClip);
- // only force drawing invisible children if visible amount is non-zero
- drawChild(panelp, 0, 0, !clip_rect.isEmpty());
+ {LLLocalClipRect clip(clip_rect, mClip);
+ // only force drawing invisible children if visible amount is non-zero
+ drawChild(panelp, 0, 0, !clip_rect.isEmpty());
+ }
}
mAnimatedThisFrame = false;
}
@@ -173,12 +246,10 @@ void LLLayoutStack::removeChild(LLView* view)
{
mPanels.erase(std::find(mPanels.begin(), mPanels.end(), embedded_panelp));
delete embedded_panelp;
+ updateFractionalSizes();
+ mNeedsLayout = true;
}
- // need to update resizebars
-
- calcMinExtents();
-
LLView::removeChild(view);
}
@@ -193,50 +264,15 @@ bool LLLayoutStack::addChild(LLView* child, S32 tab_group)
LLLayoutPanel* panelp = dynamic_cast<LLLayoutPanel*>(child);
if (panelp)
{
+ panelp->setOrientation(mOrientation);
mPanels.push_back(panelp);
+ createResizeBar(panelp);
+ mNeedsLayout = true;
}
- return LLView::addChild(child, tab_group);
-}
-
-
-S32 LLLayoutStack::getDefaultHeight(S32 cur_height)
-{
- // if we are spanning our children (crude upward propagation of size)
- // then don't enforce our size on our children
- if (mOrientation == HORIZONTAL)
- {
- cur_height = llmax(mMinHeight, getRect().getHeight());
- }
-
- return cur_height;
-}
-
-S32 LLLayoutStack::getDefaultWidth(S32 cur_width)
-{
- // if we are spanning our children (crude upward propagation of size)
- // then don't enforce our size on our children
- if (mOrientation == VERTICAL)
- {
- cur_width = llmax(mMinWidth, getRect().getWidth());
- }
-
- return cur_width;
-}
-
-void LLLayoutStack::movePanel(LLPanel* panel_to_move, LLPanel* target_panel, bool move_to_front)
-{
- LLLayoutPanel* embedded_panel_to_move = findEmbeddedPanel(panel_to_move);
- LLLayoutPanel* embedded_target_panel = move_to_front ? *mPanels.begin() : findEmbeddedPanel(target_panel);
+ BOOL result = LLView::addChild(child, tab_group);
- if (!embedded_panel_to_move || !embedded_target_panel || embedded_panel_to_move == embedded_target_panel)
- {
- llwarns << "One of the panels was not found in stack or NULL was passed instead of valid panel" << llendl;
- return;
- }
- e_panel_list_t::iterator it = std::find(mPanels.begin(), mPanels.end(), embedded_panel_to_move);
- mPanels.erase(it);
- it = move_to_front ? mPanels.begin() : std::find(mPanels.begin(), mPanels.end(), embedded_target_panel);
- mPanels.insert(it, embedded_panel_to_move);
+ updateFractionalSizes();
+ return result;
}
void LLLayoutStack::addPanel(LLLayoutPanel* panel, EAnimate animate)
@@ -251,82 +287,274 @@ void LLLayoutStack::addPanel(LLLayoutPanel* panel, EAnimate animate)
}
}
-void LLLayoutStack::removePanel(LLPanel* panel)
-{
- removeChild(panel);
-}
-
void LLLayoutStack::collapsePanel(LLPanel* panel, BOOL collapsed)
{
LLLayoutPanel* panel_container = findEmbeddedPanel(panel);
if (!panel_container) return;
panel_container->mCollapsed = collapsed;
+ mNeedsLayout = true;
}
-void LLLayoutStack::updatePanelAutoResize(const std::string& panel_name, BOOL auto_resize)
-{
- LLLayoutPanel* panel = findEmbeddedPanelByName(panel_name);
+static LLFastTimer::DeclareTimer FTM_UPDATE_LAYOUT("Update LayoutStacks");
+
+void LLLayoutStack::updateLayout()
+{
+ LLFastTimer ft(FTM_UPDATE_LAYOUT);
+
+ if (!mNeedsLayout) return;
- if (panel)
+ bool animation_in_progress = animatePanels();
+ F32 total_visible_fraction = 0.f;
+ F32 total_open_fraction = 0.f;
+ S32 space_to_distribute = (mOrientation == HORIZONTAL)
+ ? getRect().getWidth()
+ : getRect().getHeight();
+
+ // first, assign minimum dimensions
+ LLLayoutPanel* panelp = NULL;
+ BOOST_FOREACH(panelp, mPanels)
{
- panel->mAutoResize = auto_resize;
+ if (panelp->mAutoResize)
+ {
+ panelp->mTargetDim = panelp->getRelevantMinDim();
+ if (!panelp->mCollapsed && panelp->getVisible())
+ {
+ total_open_fraction += panelp->mFractionalSize;
+ }
+ }
+ space_to_distribute -= panelp->getVisibleDim() + llround((F32)mPanelSpacing * panelp->getVisibleAmount());
+ total_visible_fraction += panelp->mFractionalSize;
}
-}
-void LLLayoutStack::setPanelUserResize(const std::string& panel_name, BOOL user_resize)
+ llassert(total_visible_fraction < 1.01f);
+
+ // don't need spacing after last panel
+ space_to_distribute += panelp ? llround((F32)mPanelSpacing * panelp->getVisibleAmount()) : 0;
+
+ F32 fraction_distributed = 0.f;
+ if (space_to_distribute > 0 && total_visible_fraction > 0.f)
+ { // give space proportionally to visible auto resize panels
+ BOOST_FOREACH(LLLayoutPanel* panelp, mPanels)
+ {
+ if (panelp->mAutoResize)
+ {
+ F32 fraction_to_distribute = (panelp->mFractionalSize * panelp->getAutoResizeFactor()) / (total_visible_fraction);
+ S32 delta = llround((F32)space_to_distribute * fraction_to_distribute);
+ fraction_distributed += fraction_to_distribute;
+ panelp->mTargetDim += delta;
+ }
+ }
+ }
+
+ if (fraction_distributed < total_visible_fraction)
+ { // distribute any left over pixels to non-collapsed, visible panels
+ F32 fraction_left = total_visible_fraction - fraction_distributed;
+ S32 space_left = llround((F32)space_to_distribute * (fraction_left / total_visible_fraction));
+
+ BOOST_FOREACH(LLLayoutPanel* panelp, mPanels)
+ {
+ if (panelp->mAutoResize
+ && !panelp->mCollapsed
+ && panelp->getVisible())
+ {
+ S32 space_for_panel = llmax(0, llround((F32)space_left * (panelp->mFractionalSize / total_open_fraction)));
+ panelp->mTargetDim += space_for_panel;
+ space_left -= space_for_panel;
+ total_open_fraction -= panelp->mFractionalSize;
+ }
+ }
+ }
+
+ F32 cur_pos = (mOrientation == HORIZONTAL) ? 0.f : (F32)getRect().getHeight();
+
+ BOOST_FOREACH(LLLayoutPanel* panelp, mPanels)
+ {
+ F32 panel_dim = llmax(panelp->getExpandedMinDim(), panelp->mTargetDim);
+ F32 panel_visible_dim = panelp->getVisibleDim();
+
+ LLRect panel_rect;
+ if (mOrientation == HORIZONTAL)
+ {
+ panel_rect.setLeftTopAndSize(llround(cur_pos),
+ getRect().getHeight(),
+ llround(panel_dim),
+ getRect().getHeight());
+ }
+ else
+ {
+ panel_rect.setLeftTopAndSize(0,
+ llround(cur_pos),
+ getRect().getWidth(),
+ llround(panel_dim));
+ }
+ panelp->setIgnoreReshape(true);
+ panelp->setShape(panel_rect);
+ panelp->setIgnoreReshape(false);
+
+ LLRect resize_bar_rect(panel_rect);
+
+ F32 panel_spacing = (F32)mPanelSpacing * panelp->getVisibleAmount();
+ if (mOrientation == HORIZONTAL)
+ {
+ resize_bar_rect.mLeft = panel_rect.mRight - mResizeBarOverlap;
+ resize_bar_rect.mRight = panel_rect.mRight + (S32)(llround(panel_spacing)) + mResizeBarOverlap;
+
+ cur_pos += panel_visible_dim + panel_spacing;
+ }
+ else //VERTICAL
+ {
+ resize_bar_rect.mTop = panel_rect.mBottom + mResizeBarOverlap;
+ resize_bar_rect.mBottom = panel_rect.mBottom - (S32)(llround(panel_spacing)) - mResizeBarOverlap;
+
+ cur_pos -= panel_visible_dim + panel_spacing;
+ }
+ panelp->mResizeBar->setShape(resize_bar_rect);
+ }
+
+ updateResizeBarLimits();
+
+ // clear animation flag at end, since panel resizes will set it
+ // and leave it set if there is any animation in progress
+ mNeedsLayout = animation_in_progress;
+} // end LLLayoutStack::updateLayout
+
+LLLayoutPanel* LLLayoutStack::findEmbeddedPanel(LLPanel* panelp) const
{
- LLLayoutPanel* panel = findEmbeddedPanelByName(panel_name);
+ if (!panelp) return NULL;
- if (panel)
+ e_panel_list_t::const_iterator panel_it;
+ BOOST_FOREACH(LLLayoutPanel* p, mPanels)
{
- panel->mUserResize = user_resize;
+ if (p == panelp)
+ {
+ return p;
+ }
}
+ return NULL;
}
-bool LLLayoutStack::getPanelMinSize(const std::string& panel_name, S32* min_dimp)
+LLLayoutPanel* LLLayoutStack::findEmbeddedPanelByName(const std::string& name) const
{
- LLLayoutPanel* panel = findEmbeddedPanelByName(panel_name);
+ LLLayoutPanel* result = NULL;
- if (panel && min_dimp)
+ BOOST_FOREACH(LLLayoutPanel* p, mPanels)
{
- *min_dimp = panel->getRelevantMinDim();
+ if (p->getName() == name)
+ {
+ result = p;
+ break;
+ }
}
- return NULL != panel;
+ return result;
}
-bool LLLayoutStack::getPanelMaxSize(const std::string& panel_name, S32* max_dimp)
+void LLLayoutStack::createResizeBar(LLLayoutPanel* panelp)
{
- LLLayoutPanel* panel = findEmbeddedPanelByName(panel_name);
+ BOOST_FOREACH(LLLayoutPanel* lp, mPanels)
+ {
+ if (lp->mResizeBar == NULL)
+ {
+ LLResizeBar::Side side = (mOrientation == HORIZONTAL) ? LLResizeBar::RIGHT : LLResizeBar::BOTTOM;
+ LLRect resize_bar_rect = getRect();
- if (panel)
+ LLResizeBar::Params resize_params;
+ resize_params.name("resize");
+ resize_params.resizing_view(lp);
+ resize_params.min_size(lp->getRelevantMinDim());
+ resize_params.side(side);
+ resize_params.snapping_enabled(false);
+ LLResizeBar* resize_bar = LLUICtrlFactory::create<LLResizeBar>(resize_params);
+ lp->mResizeBar = resize_bar;
+ LLView::addChild(resize_bar, 0);
+ }
+ }
+ // bring all resize bars to the front so that they are clickable even over the panels
+ // with a bit of overlap
+ for (e_panel_list_t::iterator panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
{
- if (max_dimp) *max_dimp = panel->mMaxDim;
+ LLResizeBar* resize_barp = (*panel_it)->mResizeBar;
+ sendChildToFront(resize_barp);
}
+}
- return NULL != panel;
+// update layout stack animations, etc. once per frame
+// NOTE: we use this to size world view based on animating UI, *before* we draw the UI
+// we might still need to call updateLayout during UI draw phase, in case UI elements
+// are resizing themselves dynamically
+//static
+void LLLayoutStack::updateClass()
+{
+ for (instance_iter it = beginInstances(); it != endInstances(); ++it)
+ {
+ it->updateLayout();
+ }
}
-static LLFastTimer::DeclareTimer FTM_UPDATE_LAYOUT("Update LayoutStacks");
-void LLLayoutStack::updateLayout(BOOL force_resize)
+void LLLayoutStack::updateFractionalSizes()
{
- LLFastTimer ft(FTM_UPDATE_LAYOUT);
- static LLUICachedControl<S32> resize_bar_overlap ("UIResizeBarOverlap", 0);
- calcMinExtents();
- createResizeBars();
+ F32 total_resizable_dim = 0;
+ S32 num_auto_resize_panels = 0;
- // calculate current extents
- S32 total_width = 0;
- S32 total_height = 0;
+ BOOST_FOREACH(LLLayoutPanel* panelp, mPanels)
+ {
+ if (panelp->mAutoResize)
+ {
+ total_resizable_dim += llmax(0, panelp->getLayoutDim() - panelp->getRelevantMinDim());
+ num_auto_resize_panels++;
+ }
+ }
- e_panel_list_t::iterator panel_it;
- for (panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
+ F32 total_fractional_size = 0.f;
+
+ BOOST_FOREACH(LLLayoutPanel* panelp, mPanels)
{
- LLLayoutPanel* panelp = (*panel_it);
- if (panelp->getVisible())
+ if (panelp->mAutoResize)
{
- if (mAnimate)
+ F32 panel_resizable_dim = llmax(MIN_FRACTIONAL_SIZE, (F32)(panelp->getLayoutDim() - panelp->getRelevantMinDim()));
+ panelp->mFractionalSize = panel_resizable_dim > 0.f
+ ? llclamp(panel_resizable_dim / total_resizable_dim, MIN_FRACTIONAL_SIZE, MAX_FRACTIONAL_SIZE)
+ : MIN_FRACTIONAL_SIZE;
+ total_fractional_size += panelp->mFractionalSize;
+ llassert(!llisnan(panelp->mFractionalSize));
+ }
+ }
+
+ if (total_fractional_size == 0.f)
+ { // equal distribution
+ BOOST_FOREACH(LLLayoutPanel* panelp, mPanels)
+ {
+ if (panelp->mAutoResize)
+ {
+ panelp->mFractionalSize = MAX_FRACTIONAL_SIZE / (F32)num_auto_resize_panels;
+ }
+ }
+ }
+ else
+ { // renormalize
+ BOOST_FOREACH(LLLayoutPanel* panelp, mPanels)
+ {
+ if (panelp->mAutoResize)
+ {
+ panelp->mFractionalSize /= total_fractional_size;
+ }
+ }
+ }
+}
+
+bool LLLayoutStack::animatePanels()
+{
+ bool animation_in_progress = false;
+
+ //
+ // animate visibility
+ //
+ BOOST_FOREACH(LLLayoutPanel* panelp, mPanels)
+ {
+ if (panelp->getVisible())
+ {
+ if (mAnimate && panelp->mVisibleAmt < 1.f)
{
if (!mAnimatedThisFrame)
{
@@ -336,15 +564,21 @@ void LLLayoutStack::updateLayout(BOOL force_resize)
panelp->mVisibleAmt = 1.f;
}
}
+
+ animation_in_progress = true;
}
else
{
- panelp->mVisibleAmt = 1.f;
+ if (panelp->mVisibleAmt != 1.f)
+ {
+ panelp->mVisibleAmt = 1.f;
+ animation_in_progress = true;
+ }
}
}
else // not visible
{
- if (mAnimate)
+ if (mAnimate && panelp->mVisibleAmt > 0.f)
{
if (!mAnimatedThisFrame)
{
@@ -354,365 +588,213 @@ void LLLayoutStack::updateLayout(BOOL force_resize)
panelp->mVisibleAmt = 0.f;
}
}
+
+ animation_in_progress = true;
}
else
{
- panelp->mVisibleAmt = 0.f;
+ if (panelp->mVisibleAmt != 0.f)
+ {
+ panelp->mVisibleAmt = 0.f;
+ animation_in_progress = true;
+ }
}
}
- if (panelp->mCollapsed)
- {
- panelp->mCollapseAmt = lerp(panelp->mCollapseAmt, 1.f, LLCriticalDamp::getInterpolant(mCloseTimeConstant));
- }
- else
- {
- panelp->mCollapseAmt = lerp(panelp->mCollapseAmt, 0.f, LLCriticalDamp::getInterpolant(mCloseTimeConstant));
- }
-
- if (mOrientation == HORIZONTAL)
- {
- // enforce minimize size constraint by default
- if (panelp->getRect().getWidth() < panelp->getRelevantMinDim())
- {
- panelp->reshape(panelp->getRelevantMinDim(), panelp->getRect().getHeight());
- }
- total_width += llround(panelp->getRect().getWidth() * panelp->getCollapseFactor(mOrientation));
- // want n-1 panel gaps for n panels
- if (panel_it != mPanels.begin())
- {
- total_width += mPanelSpacing;
- }
- }
- else //VERTICAL
+ F32 collapse_state = panelp->mCollapsed ? 1.f : 0.f;
+ if (panelp->mCollapseAmt != collapse_state)
{
- // enforce minimize size constraint by default
- if (panelp->getRect().getHeight() < panelp->getRelevantMinDim())
+ if (!mAnimatedThisFrame)
{
- panelp->reshape(panelp->getRect().getWidth(), panelp->getRelevantMinDim());
+ panelp->mCollapseAmt = lerp(panelp->mCollapseAmt, collapse_state, LLCriticalDamp::getInterpolant(mCloseTimeConstant));
}
- total_height += llround(panelp->getRect().getHeight() * panelp->getCollapseFactor(mOrientation));
- if (panel_it != mPanels.begin())
+ animation_in_progress = true;
+
+ if (llabs(panelp->mCollapseAmt - collapse_state) < 0.001f)
{
- total_height += mPanelSpacing;
+ panelp->mCollapseAmt = collapse_state;
}
}
}
- S32 num_resizable_panels = 0;
- S32 shrink_headroom_available = 0;
- S32 shrink_headroom_total = 0;
- for (panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
+ mAnimatedThisFrame = true;
+
+ return animation_in_progress;
+}
+
+void LLLayoutStack::updatePanelRect( LLLayoutPanel* resized_panel, const LLRect& new_rect )
+{
+ S32 new_dim = (mOrientation == HORIZONTAL)
+ ? new_rect.getWidth()
+ : new_rect.getHeight();
+ S32 delta_dim = new_dim - resized_panel->getVisibleDim();
+ if (delta_dim == 0) return;
+
+ F32 total_visible_fraction = 0.f;
+ F32 delta_auto_resize_headroom = 0.f;
+ F32 total_auto_resize_headroom = 0.f;
+
+ LLLayoutPanel* other_resize_panel = NULL;
+ LLLayoutPanel* following_panel = NULL;
+
+ BOOST_REVERSE_FOREACH(LLLayoutPanel* panelp, mPanels)
{
- // panels that are not fully visible do not count towards shrink headroom
- if ((*panel_it)->getCollapseFactor(mOrientation) < 1.f)
+ if (panelp->mAutoResize)
{
- continue;
+ total_auto_resize_headroom += (F32)(panelp->mTargetDim - panelp->getRelevantMinDim());
+ total_visible_fraction += panelp->mFractionalSize * panelp->getAutoResizeFactor();
}
- S32 relevant_dimension = (mOrientation == HORIZONTAL) ? (*panel_it)->getRect().getWidth() : (*panel_it)->getRect().getHeight();
- S32 relevant_min = (*panel_it)->getRelevantMinDim();
-
- // if currently resizing a panel or the panel is flagged as not automatically resizing
- // only track total available headroom, but don't use it for automatic resize logic
- if ((*panel_it)->mResizeBar->hasMouseCapture()
- || (!(*panel_it)->mAutoResize
- && !force_resize))
+ if (panelp == resized_panel)
{
- shrink_headroom_total += relevant_dimension - relevant_min;
+ other_resize_panel = following_panel;
}
- else
+
+ if (panelp->getVisible() && !panelp->mCollapsed)
{
- num_resizable_panels++;
-
- shrink_headroom_available += relevant_dimension - relevant_min;
- shrink_headroom_total += relevant_dimension - relevant_min;
+ following_panel = panelp;
}
}
- // calculate how many pixels need to be distributed among layout panels
- // positive means panels need to grow, negative means shrink
- S32 pixels_to_distribute;
- if (mOrientation == HORIZONTAL)
+ if (resized_panel->mAutoResize == FALSE)
{
- pixels_to_distribute = getRect().getWidth() - total_width;
+ delta_auto_resize_headroom += -delta_dim;
}
- else //VERTICAL
+ if (other_resize_panel && other_resize_panel->mAutoResize == FALSE)
{
- pixels_to_distribute = getRect().getHeight() - total_height;
+ delta_auto_resize_headroom += delta_dim;
}
- // now we distribute the pixels...
- S32 cur_x = 0;
- S32 cur_y = getRect().getHeight();
+ F32 fraction_given_up = 0.f;
+ F32 fraction_remaining = 1.f;
+ F32 updated_auto_resize_headroom = total_auto_resize_headroom + delta_auto_resize_headroom;
- for (panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
+ enum
{
- LLLayoutPanel* panelp = (*panel_it);
+ BEFORE_RESIZED_PANEL,
+ RESIZED_PANEL,
+ NEXT_PANEL,
+ AFTER_RESIZED_PANEL
+ } which_panel = BEFORE_RESIZED_PANEL;
- S32 cur_width = panelp->getRect().getWidth();
- S32 cur_height = panelp->getRect().getHeight();
- S32 new_width = cur_width;
- S32 new_height = cur_height;
- S32 relevant_min = panelp->getRelevantMinDim();
+ BOOST_FOREACH(LLLayoutPanel* panelp, mPanels)
+ {
+ if (!panelp->getVisible() || panelp->mCollapsed) continue;
- if (mOrientation == HORIZONTAL)
- {
- new_width = llmax(relevant_min, new_width);
- }
- else
+ if (panelp == resized_panel)
{
- new_height = llmax(relevant_min, new_height);
+ which_panel = RESIZED_PANEL;
}
- S32 delta_size = 0;
- // if panel can automatically resize (not animating, and resize flag set)...
- if (panelp->getCollapseFactor(mOrientation) == 1.f
- && (force_resize || panelp->mAutoResize)
- && !panelp->mResizeBar->hasMouseCapture())
+ switch(which_panel)
{
- if (mOrientation == HORIZONTAL)
- {
- // if we're shrinking
- if (pixels_to_distribute < 0)
- {
- // shrink proportionally to amount over minimum
- // so we can do this in one pass
- delta_size = (shrink_headroom_available > 0) ? llround((F32)pixels_to_distribute * ((F32)(cur_width - relevant_min) / (F32)shrink_headroom_available)) : 0;
- shrink_headroom_available -= (cur_width - relevant_min);
- }
- else
- {
- // grow all elements equally
- delta_size = llround((F32)pixels_to_distribute / (F32)num_resizable_panels);
- num_resizable_panels--;
- }
- pixels_to_distribute -= delta_size;
- new_width = llmax(relevant_min, cur_width + delta_size);
+ case BEFORE_RESIZED_PANEL:
+ if (panelp->mAutoResize)
+ { // freeze current size as fraction of overall auto_resize space
+ F32 fractional_adjustment_factor = total_auto_resize_headroom / updated_auto_resize_headroom;
+ F32 new_fractional_size = llclamp(panelp->mFractionalSize * fractional_adjustment_factor,
+ MIN_FRACTIONAL_SIZE,
+ MAX_FRACTIONAL_SIZE);
+ F32 fraction_delta = (new_fractional_size - panelp->mFractionalSize);
+ fraction_given_up -= fraction_delta;
+ fraction_remaining -= panelp->mFractionalSize;
+ panelp->mFractionalSize += fraction_delta;
+ llassert(!llisnan(panelp->mFractionalSize));
}
else
{
- new_width = getDefaultWidth(new_width);
+ // leave non auto-resize panels alone
}
-
- if (mOrientation == VERTICAL)
+ break;
+ case RESIZED_PANEL:
+ if (panelp->mAutoResize)
+ { // freeze new size as fraction
+ F32 new_fractional_size = (updated_auto_resize_headroom == 0.f)
+ ? MAX_FRACTIONAL_SIZE
+ : llclamp((F32)(new_dim - panelp->getRelevantMinDim()) / updated_auto_resize_headroom, MIN_FRACTIONAL_SIZE, MAX_FRACTIONAL_SIZE);
+ fraction_given_up -= new_fractional_size - panelp->mFractionalSize;
+ fraction_remaining -= panelp->mFractionalSize;
+ panelp->mFractionalSize = new_fractional_size;
+ llassert(!llisnan(panelp->mFractionalSize));
+ }
+ else
+ { // freeze new size as original size
+ panelp->mTargetDim = new_dim;
+ fraction_remaining -= fraction_given_up;
+ }
+ which_panel = NEXT_PANEL;
+ break;
+ case NEXT_PANEL:
+ if (panelp->mAutoResize)
{
- if (pixels_to_distribute < 0)
+ fraction_remaining -= panelp->mFractionalSize;
+ if (fraction_given_up != 0.f)
{
- // shrink proportionally to amount over minimum
- // so we can do this in one pass
- delta_size = (shrink_headroom_available > 0) ? llround((F32)pixels_to_distribute * ((F32)(cur_height - relevant_min) / (F32)shrink_headroom_available)) : 0;
- shrink_headroom_available -= (cur_height - relevant_min);
+ panelp->mFractionalSize = llclamp(panelp->mFractionalSize + fraction_given_up, MIN_FRACTIONAL_SIZE, MAX_FRACTIONAL_SIZE);
+ fraction_given_up = 0.f;
}
else
{
- delta_size = llround((F32)pixels_to_distribute / (F32)num_resizable_panels);
- num_resizable_panels--;
+ F32 new_fractional_size = llclamp((F32)(panelp->mTargetDim - panelp->getRelevantMinDim() + delta_auto_resize_headroom)
+ / updated_auto_resize_headroom,
+ MIN_FRACTIONAL_SIZE,
+ MAX_FRACTIONAL_SIZE);
+ fraction_given_up -= new_fractional_size - panelp->mFractionalSize;
+ panelp->mFractionalSize = new_fractional_size;
}
- pixels_to_distribute -= delta_size;
- new_height = llmax(relevant_min, cur_height + delta_size);
}
else
{
- new_height = getDefaultHeight(new_height);
- }
- }
- else
- {
- if (mOrientation == HORIZONTAL)
- {
- new_height = getDefaultHeight(new_height);
+ panelp->mTargetDim -= delta_dim;
}
- else // VERTICAL
+ which_panel = AFTER_RESIZED_PANEL;
+ break;
+ case AFTER_RESIZED_PANEL:
+ if (panelp->mAutoResize)
{
- new_width = getDefaultWidth(new_width);
+ panelp->mFractionalSize = llclamp(panelp->mFractionalSize + (panelp->mFractionalSize / fraction_remaining) * fraction_given_up,
+ MIN_FRACTIONAL_SIZE,
+ MAX_FRACTIONAL_SIZE);
}
- }
-
- // adjust running headroom count based on new sizes
- shrink_headroom_total += delta_size;
-
- LLRect panel_rect;
- panel_rect.setLeftTopAndSize(cur_x, cur_y, new_width, new_height);
- panelp->setShape(panel_rect);
-
- LLRect resize_bar_rect = panel_rect;
- if (mOrientation == HORIZONTAL)
- {
- resize_bar_rect.mLeft = panel_rect.mRight - resize_bar_overlap;
- resize_bar_rect.mRight = panel_rect.mRight + mPanelSpacing + resize_bar_overlap;
- }
- else
- {
- resize_bar_rect.mTop = panel_rect.mBottom + resize_bar_overlap;
- resize_bar_rect.mBottom = panel_rect.mBottom - mPanelSpacing - resize_bar_overlap;
- }
- (*panel_it)->mResizeBar->setRect(resize_bar_rect);
-
- if (mOrientation == HORIZONTAL)
- {
- cur_x += llround(new_width * (*panel_it)->getCollapseFactor(mOrientation)) + mPanelSpacing;
- }
- else //VERTICAL
- {
- cur_y -= llround(new_height * (*panel_it)->getCollapseFactor(mOrientation)) + mPanelSpacing;
- }
- }
-
- // update resize bars with new limits
- LLLayoutPanel* last_resizeable_panel = NULL;
- for (panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
- {
- LLLayoutPanel* panelp = (*panel_it);
- S32 relevant_min = panelp->getRelevantMinDim();
-
- if (mOrientation == HORIZONTAL)
- {
- (*panel_it)->mResizeBar->setResizeLimits(
- relevant_min,
- relevant_min + shrink_headroom_total);
- }
- else //VERTICAL
- {
- (*panel_it)->mResizeBar->setResizeLimits(
- relevant_min,
- relevant_min + shrink_headroom_total);
- }
-
- // toggle resize bars based on panel visibility, resizability, etc
- BOOL resize_bar_enabled = panelp->getVisible() && (*panel_it)->mUserResize;
- (*panel_it)->mResizeBar->setVisible(resize_bar_enabled);
-
- if ((*panel_it)->mUserResize || (*panel_it)->mAutoResize)
- {
- last_resizeable_panel = (*panel_it);
- }
- }
-
- // hide last resize bar as there is nothing past it
- // resize bars need to be in between two resizable panels
- if (last_resizeable_panel)
- {
- last_resizeable_panel->mResizeBar->setVisible(FALSE);
- }
-
- // not enough room to fit existing contents
- if (force_resize == FALSE
- // layout did not complete by reaching target position
- && ((mOrientation == VERTICAL && cur_y != -mPanelSpacing)
- || (mOrientation == HORIZONTAL && cur_x != getRect().getWidth() + mPanelSpacing)))
- {
- // do another layout pass with all stacked elements contributing
- // even those that don't usually resize
- llassert_always(force_resize == FALSE);
- updateLayout(TRUE);
- }
-
- mAnimatedThisFrame = true;
-} // end LLLayoutStack::updateLayout
-
-
-LLLayoutPanel* LLLayoutStack::findEmbeddedPanel(LLPanel* panelp) const
-{
- if (!panelp) return NULL;
-
- e_panel_list_t::const_iterator panel_it;
- for (panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
- {
- if ((*panel_it) == panelp)
- {
- return *panel_it;
+ default:
+ break;
}
}
- return NULL;
}
-LLLayoutPanel* LLLayoutStack::findEmbeddedPanelByName(const std::string& name) const
+void LLLayoutStack::reshape(S32 width, S32 height, BOOL called_from_parent)
{
- LLLayoutPanel* result = NULL;
-
- for (e_panel_list_t::const_iterator panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
- {
- LLLayoutPanel* p = *panel_it;
-
- if (p->getName() == name)
- {
- result = p;
- break;
- }
- }
-
- return result;
+ mNeedsLayout = true;
+ LLView::reshape(width, height, called_from_parent);
}
-// Compute sum of min_width or min_height of children
-void LLLayoutStack::calcMinExtents()
+void LLLayoutStack::updateResizeBarLimits()
{
- mMinWidth = 0;
- mMinHeight = 0;
-
- e_panel_list_t::iterator panel_it;
- for (panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
+ LLLayoutPanel* previous_visible_panelp = NULL;
+ BOOST_REVERSE_FOREACH(LLLayoutPanel* visible_panelp, mPanels)
{
- if (mOrientation == HORIZONTAL)
+ if (!visible_panelp->getVisible() || visible_panelp->mCollapsed)
{
- mMinWidth += (*panel_it)->getRelevantMinDim();
- if (panel_it != mPanels.begin())
- {
- mMinWidth += mPanelSpacing;
- }
+ visible_panelp->mResizeBar->setVisible(FALSE);
+ continue;
}
- else //VERTICAL
+
+ // toggle resize bars based on panel visibility, resizability, etc
+ if (previous_visible_panelp
+ && (visible_panelp->mUserResize || previous_visible_panelp->mUserResize) // one of the pair is user resizable
+ && (visible_panelp->mAutoResize || visible_panelp->mUserResize) // current panel is resizable
+ && (previous_visible_panelp->mAutoResize || previous_visible_panelp->mUserResize)) // previous panel is resizable
{
- mMinHeight += (*panel_it)->getRelevantMinDim();
- if (panel_it != mPanels.begin())
- {
- mMinHeight += mPanelSpacing;
- }
+ visible_panelp->mResizeBar->setVisible(TRUE);
+ S32 previous_panel_headroom = previous_visible_panelp->getVisibleDim() - previous_visible_panelp->getRelevantMinDim();
+ visible_panelp->mResizeBar->setResizeLimits(visible_panelp->getRelevantMinDim(),
+ visible_panelp->getVisibleDim() + previous_panel_headroom);
}
- }
-}
-
-void LLLayoutStack::createResizeBars()
-{
- for (e_panel_list_t::iterator panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
- {
- LLLayoutPanel* lp = (*panel_it);
- if (lp->mResizeBar == NULL)
+ else
{
- LLResizeBar::Side side = (mOrientation == HORIZONTAL) ? LLResizeBar::RIGHT : LLResizeBar::BOTTOM;
- LLRect resize_bar_rect = getRect();
-
- LLResizeBar::Params resize_params;
- resize_params.name("resize");
- resize_params.resizing_view(lp);
- resize_params.min_size(lp->getRelevantMinDim());
- resize_params.side(side);
- resize_params.snapping_enabled(false);
- LLResizeBar* resize_bar = LLUICtrlFactory::create<LLResizeBar>(resize_params);
- lp->mResizeBar = resize_bar;
- LLView::addChild(resize_bar, 0);
-
- // bring all resize bars to the front so that they are clickable even over the panels
- // with a bit of overlap
- for (e_panel_list_t::iterator panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
- {
- LLResizeBar* resize_barp = (*panel_it)->mResizeBar;
- sendChildToFront(resize_barp);
- }
+ visible_panelp->mResizeBar->setVisible(FALSE);
}
- }
-}
-// update layout stack animations, etc. once per frame
-// NOTE: we use this to size world view based on animating UI, *before* we draw the UI
-// we might still need to call updateLayout during UI draw phase, in case UI elements
-// are resizing themselves dynamically
-//static
-void LLLayoutStack::updateClass()
-{
- for (instance_iter it = beginInstances(); it != endInstances(); ++it)
- {
- it->updateLayout();
+ previous_visible_panelp = visible_panelp;
}
}