PageRenderTime 31ms CodeModel.GetById 2ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llui/lllayoutstack.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 203 lines | 127 code | 49 blank | 27 comment | 2 complexity | 0dfb5bf6a362eb9d6dd87b774a71e13d MD5 | raw file
  1/** 
  2 * @file lllayoutstack.h
  3 * @author Richard Nelson
  4 * @brief LLLayout class - dynamic stacking of UI elements
  5 *
  6 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Reshasearch, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#ifndef LL_LLLAYOUTSTACK_H
 29#define LL_LLLAYOUTSTACK_H
 30
 31#include "llpanel.h"
 32
 33
 34class LLLayoutPanel;
 35
 36
 37class LLLayoutStack : public LLView, public LLInstanceTracker<LLLayoutStack>
 38{
 39public:
 40	typedef enum e_layout_orientation
 41	{
 42		HORIZONTAL,
 43		VERTICAL
 44	} ELayoutOrientation;
 45
 46	struct OrientationNames
 47	:	public LLInitParam::TypeValuesHelper<ELayoutOrientation, OrientationNames>
 48	{
 49		static void declareValues();
 50	};
 51
 52	struct LayoutStackRegistry : public LLChildRegistry<LayoutStackRegistry>
 53	{};
 54
 55	struct Params : public LLInitParam::Block<Params, LLView::Params>
 56	{
 57		Mandatory<ELayoutOrientation, OrientationNames>	orientation;
 58		Optional<S32>			border_size;
 59		Optional<bool>			animate,
 60								clip;
 61		Optional<F32>			open_time_constant,
 62								close_time_constant;
 63		Optional<S32>			resize_bar_overlap;
 64
 65		Params();
 66	};
 67
 68	typedef LayoutStackRegistry child_registry_t;
 69
 70	virtual ~LLLayoutStack();
 71
 72	/*virtual*/ void draw();
 73	/*virtual*/ void removeChild(LLView*);
 74	/*virtual*/ BOOL postBuild();
 75	/*virtual*/ bool addChild(LLView* child, S32 tab_group = 0);
 76	/*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
 77
 78
 79	static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLXMLNodePtr output_node = NULL);
 80
 81	typedef enum e_animate
 82	{
 83		NO_ANIMATE,
 84		ANIMATE
 85	} EAnimate;
 86
 87	void addPanel(LLLayoutPanel* panel, EAnimate animate = NO_ANIMATE);
 88	void collapsePanel(LLPanel* panel, BOOL collapsed = TRUE);
 89	S32 getNumPanels() { return mPanels.size(); }
 90
 91	void updateLayout();
 92
 93	S32 getPanelSpacing() const { return mPanelSpacing; }
 94	
 95	static void updateClass();
 96
 97protected:
 98	LLLayoutStack(const Params&);
 99	friend class LLUICtrlFactory;
100	friend class LLLayoutPanel;
101
102private:
103	void updateResizeBarLimits();
104	bool animatePanels();
105	void createResizeBar(LLLayoutPanel* panel);
106
107	const ELayoutOrientation mOrientation;
108
109	typedef std::vector<LLLayoutPanel*> e_panel_list_t;
110	e_panel_list_t mPanels;
111
112	LLLayoutPanel* findEmbeddedPanel(LLPanel* panelp) const;
113	LLLayoutPanel* findEmbeddedPanelByName(const std::string& name) const;
114	void updateFractionalSizes();
115	void updatePanelRect( LLLayoutPanel* param1, const LLRect& new_rect );
116
117	S32 mPanelSpacing;
118
119	// true if we already applied animation this frame
120	bool mAnimatedThisFrame;
121	bool mAnimate;
122	bool mClip;
123	F32  mOpenTimeConstant;
124	F32  mCloseTimeConstant;
125	bool mNeedsLayout;
126	S32  mResizeBarOverlap;
127}; // end class LLLayoutStack
128
129
130class LLLayoutPanel : public LLPanel
131{
132friend class LLLayoutStack;
133friend class LLUICtrlFactory;
134public:
135	struct Params : public LLInitParam::Block<Params, LLPanel::Params>
136	{
137		Optional<S32>			expanded_min_dim,
138								min_dim;
139		Optional<bool>			user_resize,
140								auto_resize;
141
142		Params();
143	};
144
145	~LLLayoutPanel();
146
147	void initFromParams(const Params& p);
148
149	void handleReshape(const LLRect& new_rect, bool by_user);
150
151	void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
152	
153
154	void setVisible(BOOL visible);
155
156	S32 getLayoutDim() const;
157	S32 getMinDim() const { return (mMinDim >= 0 || mAutoResize) ? llmax(0, mMinDim) : getLayoutDim(); }
158	void setMinDim(S32 value) { mMinDim = value; }
159
160	S32 getExpandedMinDim() const { return mExpandedMinDim >= 0 ? mExpandedMinDim : mMinDim; }
161	void setExpandedMinDim(S32 value) { mExpandedMinDim = value; }
162	
163	S32 getRelevantMinDim() const
164	{
165		S32 min_dim = mMinDim;
166		
167		if (!mCollapsed)
168		{
169			min_dim = getExpandedMinDim();
170		}
171		
172		return min_dim;
173	}
174
175	F32 getAutoResizeFactor() const;
176	F32 getVisibleAmount() const;
177	S32 getVisibleDim() const;
178
179	void setOrientation(LLLayoutStack::ELayoutOrientation orientation);
180	void storeOriginalDim();
181
182	void setIgnoreReshape(bool ignore) { mIgnoreReshape = ignore; }
183
184protected:
185	LLLayoutPanel(const Params& p);
186	
187	const bool	mAutoResize;
188	const bool	mUserResize;
189
190	S32		mExpandedMinDim;
191	S32		mMinDim;
192	bool	mCollapsed;
193	F32		mVisibleAmt;
194	F32		mCollapseAmt;
195	F32		mFractionalSize;
196	S32		mTargetDim;
197	bool	mIgnoreReshape;
198	LLLayoutStack::ELayoutOrientation mOrientation;
199	class LLResizeBar* mResizeBar;
200};
201
202
203#endif