Skip to content
Snippets Groups Projects
Commit 20b46ef6 authored by Richard Linden's avatar Richard Linden
Browse files

EXP-1851 FIX Crash when trying to resize the bottom sections

 more layout logic fixes and added renormalization to fractional sizes to eliminate drift
parent f3ddb75b
No related branches found
No related tags found
No related merge requests found
...@@ -129,6 +129,10 @@ void LLLayoutPanel::setOrientation( LLLayoutStack::ELayoutOrientation orientatio ...@@ -129,6 +129,10 @@ void LLLayoutPanel::setOrientation( LLLayoutStack::ELayoutOrientation orientatio
? getRect().getWidth() ? getRect().getWidth()
: getRect().getHeight())); : getRect().getHeight()));
if (mAutoResize == FALSE && mMinDim == -1)
{
setMinDim(layout_dim);
}
mTargetDim = llmax(layout_dim, getMinDim()); mTargetDim = llmax(layout_dim, getMinDim());
} }
...@@ -246,7 +250,7 @@ void LLLayoutStack::removeChild(LLView* view) ...@@ -246,7 +250,7 @@ void LLLayoutStack::removeChild(LLView* view)
{ {
mPanels.erase(std::find(mPanels.begin(), mPanels.end(), embedded_panelp)); mPanels.erase(std::find(mPanels.begin(), mPanels.end(), embedded_panelp));
delete embedded_panelp; delete embedded_panelp;
updateFractionalSizes(); normalizeFractionalSizes();
mNeedsLayout = true; mNeedsLayout = true;
} }
...@@ -271,7 +275,7 @@ bool LLLayoutStack::addChild(LLView* child, S32 tab_group) ...@@ -271,7 +275,7 @@ bool LLLayoutStack::addChild(LLView* child, S32 tab_group)
} }
BOOL result = LLView::addChild(child, tab_group); BOOL result = LLView::addChild(child, tab_group);
updateFractionalSizes(); normalizeFractionalSizes();
return result; return result;
} }
...@@ -306,7 +310,6 @@ void LLLayoutStack::updateLayout() ...@@ -306,7 +310,6 @@ void LLLayoutStack::updateLayout()
bool animation_in_progress = animatePanels(); bool animation_in_progress = animatePanels();
F32 total_visible_fraction = 0.f; F32 total_visible_fraction = 0.f;
F32 total_open_fraction = 0.f;
S32 space_to_distribute = (mOrientation == HORIZONTAL) S32 space_to_distribute = (mOrientation == HORIZONTAL)
? getRect().getWidth() ? getRect().getWidth()
: getRect().getHeight(); : getRect().getHeight();
...@@ -318,20 +321,17 @@ void LLLayoutStack::updateLayout() ...@@ -318,20 +321,17 @@ void LLLayoutStack::updateLayout()
if (panelp->mAutoResize) if (panelp->mAutoResize)
{ {
panelp->mTargetDim = panelp->getRelevantMinDim(); panelp->mTargetDim = panelp->getRelevantMinDim();
if (!panelp->mCollapsed && panelp->getVisible())
{
total_open_fraction += panelp->mFractionalSize;
}
} }
space_to_distribute -= panelp->getVisibleDim() + llround((F32)mPanelSpacing * panelp->getVisibleAmount()); space_to_distribute -= panelp->getVisibleDim() + llround((F32)mPanelSpacing * panelp->getVisibleAmount());
total_visible_fraction += panelp->mFractionalSize; total_visible_fraction += panelp->mFractionalSize * panelp->getVisibleAmount();
} }
llassert(total_visible_fraction < 1.01f); llassert(total_visible_fraction < 1.05f);
// don't need spacing after last panel // don't need spacing after last panel
space_to_distribute += panelp ? llround((F32)mPanelSpacing * panelp->getVisibleAmount()) : 0; space_to_distribute += panelp ? llround((F32)mPanelSpacing * panelp->getVisibleAmount()) : 0;
S32 remaining_space = space_to_distribute;
F32 fraction_distributed = 0.f; F32 fraction_distributed = 0.f;
if (space_to_distribute > 0 && total_visible_fraction > 0.f) if (space_to_distribute > 0 && total_visible_fraction > 0.f)
{ // give space proportionally to visible auto resize panels { // give space proportionally to visible auto resize panels
...@@ -343,26 +343,23 @@ void LLLayoutStack::updateLayout() ...@@ -343,26 +343,23 @@ void LLLayoutStack::updateLayout()
S32 delta = llround((F32)space_to_distribute * fraction_to_distribute); S32 delta = llround((F32)space_to_distribute * fraction_to_distribute);
fraction_distributed += fraction_to_distribute; fraction_distributed += fraction_to_distribute;
panelp->mTargetDim += delta; panelp->mTargetDim += delta;
remaining_space -= delta;
} }
} }
} }
if (fraction_distributed < total_visible_fraction) // distribute any left over pixels to non-collapsed, visible panels
{ // distribute any left over pixels to non-collapsed, visible panels BOOST_FOREACH(LLLayoutPanel* panelp, mPanels)
F32 fraction_left = total_visible_fraction - fraction_distributed; {
S32 space_left = llround((F32)space_to_distribute * (fraction_left / total_visible_fraction)); if (remaining_space == 0) break;
BOOST_FOREACH(LLLayoutPanel* panelp, mPanels) if (panelp->mAutoResize
&& !panelp->mCollapsed
&& panelp->getVisible())
{ {
if (panelp->mAutoResize S32 space_for_panel = remaining_space > 0 ? 1 : -1;
&& !panelp->mCollapsed panelp->mTargetDim += space_for_panel;
&& panelp->getVisible()) remaining_space -= space_for_panel;
{
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;
}
} }
} }
...@@ -492,7 +489,7 @@ void LLLayoutStack::updateClass() ...@@ -492,7 +489,7 @@ void LLLayoutStack::updateClass()
} }
} }
void LLLayoutStack::updateFractionalSizes() void LLLayoutStack::normalizeFractionalSizes()
{ {
F32 total_resizable_dim = 0; F32 total_resizable_dim = 0;
S32 num_auto_resize_panels = 0; S32 num_auto_resize_panels = 0;
...@@ -691,7 +688,9 @@ void LLLayoutStack::updatePanelRect( LLLayoutPanel* resized_panel, const LLRect& ...@@ -691,7 +688,9 @@ void LLLayoutStack::updatePanelRect( LLLayoutPanel* resized_panel, const LLRect&
case BEFORE_RESIZED_PANEL: case BEFORE_RESIZED_PANEL:
if (panelp->mAutoResize) if (panelp->mAutoResize)
{ // freeze current size as fraction of overall auto_resize space { // freeze current size as fraction of overall auto_resize space
F32 fractional_adjustment_factor = total_auto_resize_headroom / updated_auto_resize_headroom; F32 fractional_adjustment_factor = updated_auto_resize_headroom == 0.f
? 1.f
: total_auto_resize_headroom / updated_auto_resize_headroom;
F32 new_fractional_size = llclamp(panelp->mFractionalSize * fractional_adjustment_factor, F32 new_fractional_size = llclamp(panelp->mFractionalSize * fractional_adjustment_factor,
MIN_FRACTIONAL_SIZE, MIN_FRACTIONAL_SIZE,
MAX_FRACTIONAL_SIZE); MAX_FRACTIONAL_SIZE);
...@@ -720,7 +719,6 @@ void LLLayoutStack::updatePanelRect( LLLayoutPanel* resized_panel, const LLRect& ...@@ -720,7 +719,6 @@ void LLLayoutStack::updatePanelRect( LLLayoutPanel* resized_panel, const LLRect&
else else
{ // freeze new size as original size { // freeze new size as original size
panelp->mTargetDim = new_dim; panelp->mTargetDim = new_dim;
fraction_remaining -= fraction_given_up;
} }
which_panel = NEXT_PANEL; which_panel = NEXT_PANEL;
break; break;
...@@ -728,7 +726,7 @@ void LLLayoutStack::updatePanelRect( LLLayoutPanel* resized_panel, const LLRect& ...@@ -728,7 +726,7 @@ void LLLayoutStack::updatePanelRect( LLLayoutPanel* resized_panel, const LLRect&
if (panelp->mAutoResize) if (panelp->mAutoResize)
{ {
fraction_remaining -= panelp->mFractionalSize; fraction_remaining -= panelp->mFractionalSize;
if (fraction_given_up != 0.f) if (resized_panel->mAutoResize)
{ {
panelp->mFractionalSize = llclamp(panelp->mFractionalSize + fraction_given_up, MIN_FRACTIONAL_SIZE, MAX_FRACTIONAL_SIZE); panelp->mFractionalSize = llclamp(panelp->mFractionalSize + fraction_given_up, MIN_FRACTIONAL_SIZE, MAX_FRACTIONAL_SIZE);
fraction_given_up = 0.f; fraction_given_up = 0.f;
...@@ -750,7 +748,7 @@ void LLLayoutStack::updatePanelRect( LLLayoutPanel* resized_panel, const LLRect& ...@@ -750,7 +748,7 @@ void LLLayoutStack::updatePanelRect( LLLayoutPanel* resized_panel, const LLRect&
which_panel = AFTER_RESIZED_PANEL; which_panel = AFTER_RESIZED_PANEL;
break; break;
case AFTER_RESIZED_PANEL: case AFTER_RESIZED_PANEL:
if (panelp->mAutoResize) if (panelp->mAutoResize && fraction_given_up != 0.f)
{ {
panelp->mFractionalSize = llclamp(panelp->mFractionalSize + (panelp->mFractionalSize / fraction_remaining) * fraction_given_up, panelp->mFractionalSize = llclamp(panelp->mFractionalSize + (panelp->mFractionalSize / fraction_remaining) * fraction_given_up,
MIN_FRACTIONAL_SIZE, MIN_FRACTIONAL_SIZE,
...@@ -760,6 +758,8 @@ void LLLayoutStack::updatePanelRect( LLLayoutPanel* resized_panel, const LLRect& ...@@ -760,6 +758,8 @@ void LLLayoutStack::updatePanelRect( LLLayoutPanel* resized_panel, const LLRect&
break; break;
} }
} }
updateLayout();
normalizeFractionalSizes();
} }
void LLLayoutStack::reshape(S32 width, S32 height, BOOL called_from_parent) void LLLayoutStack::reshape(S32 width, S32 height, BOOL called_from_parent)
......
...@@ -72,7 +72,7 @@ class LLLayoutStack : public LLView, public LLInstanceTracker<LLLayoutStack> ...@@ -72,7 +72,7 @@ class LLLayoutStack : public LLView, public LLInstanceTracker<LLLayoutStack>
/*virtual*/ void draw(); /*virtual*/ void draw();
/*virtual*/ void removeChild(LLView*); /*virtual*/ void removeChild(LLView*);
/*virtual*/ BOOL postBuild(); /*virtual*/ BOOL postBuild();
/*virtual*/ bool addChild(LLView* child, S32 tab_group = 0); /*virtual*/ bool addChild(LLView* child, S32 tab_groupdatefractuiona = 0);
/*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE); /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
...@@ -111,7 +111,7 @@ class LLLayoutStack : public LLView, public LLInstanceTracker<LLLayoutStack> ...@@ -111,7 +111,7 @@ class LLLayoutStack : public LLView, public LLInstanceTracker<LLLayoutStack>
LLLayoutPanel* findEmbeddedPanel(LLPanel* panelp) const; LLLayoutPanel* findEmbeddedPanel(LLPanel* panelp) const;
LLLayoutPanel* findEmbeddedPanelByName(const std::string& name) const; LLLayoutPanel* findEmbeddedPanelByName(const std::string& name) const;
void updateFractionalSizes(); void normalizeFractionalSizes();
void updatePanelRect( LLLayoutPanel* param1, const LLRect& new_rect ); void updatePanelRect( LLLayoutPanel* param1, const LLRect& new_rect );
S32 mPanelSpacing; S32 mPanelSpacing;
...@@ -154,7 +154,7 @@ friend class LLUICtrlFactory; ...@@ -154,7 +154,7 @@ friend class LLUICtrlFactory;
void setVisible(BOOL visible); void setVisible(BOOL visible);
S32 getLayoutDim() const; S32 getLayoutDim() const;
S32 getMinDim() const { return (mMinDim >= 0 || mAutoResize) ? llmax(0, mMinDim) : getLayoutDim(); } S32 getMinDim() const { return llmax(0, mMinDim); }
void setMinDim(S32 value) { mMinDim = value; } void setMinDim(S32 value) { mMinDim = value; }
S32 getExpandedMinDim() const { return mExpandedMinDim >= 0 ? mExpandedMinDim : getMinDim(); } S32 getExpandedMinDim() const { return mExpandedMinDim >= 0 ? mExpandedMinDim : getMinDim(); }
......
...@@ -36,6 +36,16 @@ ...@@ -36,6 +36,16 @@
background_visible="true"> background_visible="true">
<text follows="top|left|right" halign="center" text_color="white">flex</text> <text follows="top|left|right" halign="center" text_color="white">flex</text>
</layout_panel> </layout_panel>
<layout_panel name="flex"
auto_resize="true"
user_resize="true"
bg_alpha_color="blue"
height="11"
min_height="0"
visible="true"
background_visible="true">
<text follows="top|left|right" halign="center" text_color="white">flex</text>
</layout_panel>
<layout_panel name="flex" <layout_panel name="flex"
auto_resize="true" auto_resize="true"
user_resize="true" user_resize="true"
...@@ -61,7 +71,7 @@ ...@@ -61,7 +71,7 @@
background_visible="true"> background_visible="true">
<text follows="top|left|right" halign="center" text_color="white">flex</text> <text follows="top|left|right" halign="center" text_color="white">flex</text>
</layout_panel> </layout_panel>
<!--<layout_panel name="flex" <layout_panel name="flex"
auto_resize="true" auto_resize="true"
user_resize="true" user_resize="true"
visible="false" visible="false"
...@@ -69,7 +79,7 @@ ...@@ -69,7 +79,7 @@
height="100" height="100"
background_visible="true"> background_visible="true">
<text follows="top|left|right" halign="center" text_color="white">flex</text> <text follows="top|left|right" halign="center" text_color="white">flex</text>
</layout_panel>--> </layout_panel>
<layout_panel name="fixed" <layout_panel name="fixed"
auto_resize="false" auto_resize="false"
user_resize="true" user_resize="true"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment