/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. #ifndef LL_LLLAYOUTSTACK_H
  28. #define LL_LLLAYOUTSTACK_H
  29. #include "llpanel.h"
  30. class LLLayoutPanel;
  31. class LLLayoutStack : public LLView, public LLInstanceTracker<LLLayoutStack>
  32. {
  33. public:
  34. typedef enum e_layout_orientation
  35. {
  36. HORIZONTAL,
  37. VERTICAL
  38. } ELayoutOrientation;
  39. struct OrientationNames
  40. : public LLInitParam::TypeValuesHelper<ELayoutOrientation, OrientationNames>
  41. {
  42. static void declareValues();
  43. };
  44. struct LayoutStackRegistry : public LLChildRegistry<LayoutStackRegistry>
  45. {};
  46. struct Params : public LLInitParam::Block<Params, LLView::Params>
  47. {
  48. Mandatory<ELayoutOrientation, OrientationNames> orientation;
  49. Optional<S32> border_size;
  50. Optional<bool> animate,
  51. clip;
  52. Optional<F32> open_time_constant,
  53. close_time_constant;
  54. Optional<S32> resize_bar_overlap;
  55. Params();
  56. };
  57. typedef LayoutStackRegistry child_registry_t;
  58. virtual ~LLLayoutStack();
  59. /*virtual*/ void draw();
  60. /*virtual*/ void removeChild(LLView*);
  61. /*virtual*/ BOOL postBuild();
  62. /*virtual*/ bool addChild(LLView* child, S32 tab_group = 0);
  63. /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
  64. static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLXMLNodePtr output_node = NULL);
  65. typedef enum e_animate
  66. {
  67. NO_ANIMATE,
  68. ANIMATE
  69. } EAnimate;
  70. void addPanel(LLLayoutPanel* panel, EAnimate animate = NO_ANIMATE);
  71. void collapsePanel(LLPanel* panel, BOOL collapsed = TRUE);
  72. S32 getNumPanels() { return mPanels.size(); }
  73. void updateLayout();
  74. S32 getPanelSpacing() const { return mPanelSpacing; }
  75. static void updateClass();
  76. protected:
  77. LLLayoutStack(const Params&);
  78. friend class LLUICtrlFactory;
  79. friend class LLLayoutPanel;
  80. private:
  81. void updateResizeBarLimits();
  82. bool animatePanels();
  83. void createResizeBar(LLLayoutPanel* panel);
  84. const ELayoutOrientation mOrientation;
  85. typedef std::vector<LLLayoutPanel*> e_panel_list_t;
  86. e_panel_list_t mPanels;
  87. LLLayoutPanel* findEmbeddedPanel(LLPanel* panelp) const;
  88. LLLayoutPanel* findEmbeddedPanelByName(const std::string& name) const;
  89. void updateFractionalSizes();
  90. void updatePanelRect( LLLayoutPanel* param1, const LLRect& new_rect );
  91. S32 mPanelSpacing;
  92. // true if we already applied animation this frame
  93. bool mAnimatedThisFrame;
  94. bool mAnimate;
  95. bool mClip;
  96. F32 mOpenTimeConstant;
  97. F32 mCloseTimeConstant;
  98. bool mNeedsLayout;
  99. S32 mResizeBarOverlap;
  100. }; // end class LLLayoutStack
  101. class LLLayoutPanel : public LLPanel
  102. {
  103. friend class LLLayoutStack;
  104. friend class LLUICtrlFactory;
  105. public:
  106. struct Params : public LLInitParam::Block<Params, LLPanel::Params>
  107. {
  108. Optional<S32> expanded_min_dim,
  109. min_dim;
  110. Optional<bool> user_resize,
  111. auto_resize;
  112. Params();
  113. };
  114. ~LLLayoutPanel();
  115. void initFromParams(const Params& p);
  116. void handleReshape(const LLRect& new_rect, bool by_user);
  117. void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
  118. void setVisible(BOOL visible);
  119. S32 getLayoutDim() const;
  120. S32 getMinDim() const { return (mMinDim >= 0 || mAutoResize) ? llmax(0, mMinDim) : getLayoutDim(); }
  121. void setMinDim(S32 value) { mMinDim = value; }
  122. S32 getExpandedMinDim() const { return mExpandedMinDim >= 0 ? mExpandedMinDim : mMinDim; }
  123. void setExpandedMinDim(S32 value) { mExpandedMinDim = value; }
  124. S32 getRelevantMinDim() const
  125. {
  126. S32 min_dim = mMinDim;
  127. if (!mCollapsed)
  128. {
  129. min_dim = getExpandedMinDim();
  130. }
  131. return min_dim;
  132. }
  133. F32 getAutoResizeFactor() const;
  134. F32 getVisibleAmount() const;
  135. S32 getVisibleDim() const;
  136. void setOrientation(LLLayoutStack::ELayoutOrientation orientation);
  137. void storeOriginalDim();
  138. void setIgnoreReshape(bool ignore) { mIgnoreReshape = ignore; }
  139. protected:
  140. LLLayoutPanel(const Params& p);
  141. const bool mAutoResize;
  142. const bool mUserResize;
  143. S32 mExpandedMinDim;
  144. S32 mMinDim;
  145. bool mCollapsed;
  146. F32 mVisibleAmt;
  147. F32 mCollapseAmt;
  148. F32 mFractionalSize;
  149. S32 mTargetDim;
  150. bool mIgnoreReshape;
  151. LLLayoutStack::ELayoutOrientation mOrientation;
  152. class LLResizeBar* mResizeBar;
  153. };
  154. #endif