00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_XRB_LAYOUT_HPP_)
00012 #define _XRB_LAYOUT_HPP_
00013
00014 #include "xrb.hpp"
00015
00016 #include "xrb_containerwidget.hpp"
00017 #include "xrb_enums.hpp"
00018
00019 namespace Xrb
00020 {
00021
00022 class Layout : public ContainerWidget
00023 {
00024 public:
00025
00026 Layout (
00027 LineDirection major_direction,
00028 Uint32 major_count,
00029 ContainerWidget *parent,
00030 std::string const &name = "Layout");
00031 Layout (
00032 Orientation orientation,
00033 ContainerWidget *parent,
00034 std::string const &name = "Layout");
00035 virtual ~Layout ();
00036
00037 inline LineDirection MajorDirection () const
00038 {
00039 return m_major_direction;
00040 }
00041 inline LineDirection MinorDirection () const
00042 {
00043 return (m_major_direction == ROW) ? COLUMN : ROW;
00044 }
00045 inline Uint32 MajorCount () const
00046 {
00047 return m_major_count;
00048 }
00049 Uint32 MinorCount () const
00050 {
00051 return (m_child_vector.size() + m_major_count - 1) / m_major_count;
00052 }
00053
00054 inline bool IsUsingZeroedFrameMargins () const
00055 {
00056 return m_is_using_zeroed_frame_margins;
00057 }
00058 inline bool IsUsingZeroedLayoutSpacingMargins () const
00059 {
00060 return m_is_using_zeroed_layout_spacing_margins;
00061 }
00062
00063 Widget *GridChild (
00064 Uint32 major_index,
00065 Uint32 minor_index) const;
00066 Widget *GridChildByColumnAndRow (
00067 Uint32 column_index,
00068 Uint32 row_index) const;
00069
00070 ScreenCoordVector2 const &TotalSpacing () const;
00071
00072 Uint32 ColumnCount () const;
00073 Bool2 const &ColumnMinSizeEnabled (Uint32 index) const;
00074 ScreenCoordVector2 const &ColumnMinSize (Uint32 index) const;
00075 Bool2 const &ColumnMaxSizeEnabled (Uint32 index) const;
00076 ScreenCoordVector2 const &ColumnMaxSize (Uint32 index) const;
00077 ScreenCoord ColumnWidth (Uint32 index) const;
00078 Uint32 HiddenColumnCount () const;
00079
00080 Uint32 RowCount () const;
00081 Bool2 const &RowMinSizeEnabled (Uint32 index) const;
00082 ScreenCoordVector2 const &RowMinSize (Uint32 index) const;
00083 Bool2 const &RowMaxSizeEnabled (Uint32 index) const;
00084 ScreenCoordVector2 const &RowMaxSize (Uint32 index) const;
00085 ScreenCoord RowHeight (Uint32 index) const;
00086 Uint32 HiddenRowCount () const;
00087
00088 virtual Bool2 ContentsMinSizeEnabled () const;
00089 virtual ScreenCoordVector2 ContentsMinSize () const;
00090 virtual Bool2 ContentsMaxSizeEnabled () const;
00091 virtual ScreenCoordVector2 ContentsMaxSize () const;
00092
00093 void SetMajorDirection (LineDirection major_direction);
00094 void SetMajorCount (Uint32 major_count);
00095
00096 void SetIsUsingZeroedFrameMargins (
00097 bool const is_using_zeroed_frame_margins);
00098 void SetIsUsingZeroedLayoutSpacingMargins (
00099 bool const is_using_zeroed_layout_spacing_margins);
00100
00101 virtual void SetSizePropertyEnabled (
00102 SizeProperties::Property property,
00103 Uint32 component,
00104 bool value);
00105 virtual void SetSizePropertyEnabled (
00106 SizeProperties::Property property,
00107 Bool2 const &value);
00108
00109 virtual void SetSizeProperty (
00110 SizeProperties::Property property,
00111 Uint32 component,
00112 ScreenCoord value);
00113 virtual void SetSizeProperty (
00114 SizeProperties::Property property,
00115 ScreenCoordVector2 const &value);
00116
00117 virtual void SetMainWidget (Widget *main_widget)
00118 {
00119
00120 ASSERT0(false && "You can't set a main widget in a Layout");
00121 }
00122
00123 virtual ScreenCoordVector2 Resize (ScreenCoordVector2 const &size);
00124 virtual void AttachChild (Widget *child);
00125 virtual void DetachChild (Widget *child);
00126
00127 virtual void MoveChildDown (Widget *child);
00128 virtual void MoveChildUp (Widget *child);
00129 virtual void MoveChildToBottom (Widget *child);
00130 virtual void MoveChildToTop (Widget *child);
00131
00132 protected:
00133
00134 inline ScreenCoordVector2 const &CalculateLayoutFrameMargins () const
00135 {
00136 return IsUsingZeroedFrameMargins() ?
00137 ScreenCoordVector2::ms_zero :
00138 WidgetSkinMargins(WidgetSkin::LAYOUT_FRAME_MARGINS);
00139 }
00140 inline ScreenCoordVector2 const &CalculateLayoutSpacingMargins () const
00141 {
00142 return IsUsingZeroedLayoutSpacingMargins() ?
00143 ScreenCoordVector2::ms_zero :
00144 WidgetSkinMargins(WidgetSkin::LAYOUT_SPACING_MARGINS);
00145 }
00146
00147
00148 virtual void HandleChangedWidgetSkinMargins (
00149 WidgetSkin::MarginsType margins_type);
00150
00151
00152 virtual void HandleChangedLayoutFrameMargins ();
00153 virtual void HandleChangedLayoutSpacingMargins ();
00154
00155 virtual void ChildSizePropertiesChanged (Widget *child);
00156 virtual void ChildStackPriorityChanged (
00157 Widget *child,
00158 StackPriority previous_stack_priority);
00159
00160 private:
00161
00162 static int SizePropertiesSortingFunction (
00163 SizeProperties const *properties_a,
00164 SizeProperties const *properties_b,
00165 Uint32 index);
00166
00167 static int ColumnCompareConstraints (void const *a, void const *b);
00168 static int RowCompareConstraints (void const *a, void const *b);
00169
00170
00171
00172 void DelegateWidthsToColumns ();
00173
00174
00175 void DelegateHeightsToRows ();
00176
00177
00178
00179 void ResizeAndRepositionChildWidgets ();
00180
00181
00182 void ConstrainPreferredSizeProperties ();
00183
00184 void CalculateLineSizeProperties (
00185 LineDirection line_direction,
00186 Uint32 line_index,
00187 SizeProperties *size_properties,
00188 bool *line_is_hidden) const;
00189
00190
00191 void DirtyTotalSpacing ();
00192 void DirtyColumnSizePropertyAllocations ();
00193 void DirtyColumnSizeProperties ();
00194 void DirtyRowSizePropertyAllocations ();
00195 void DirtyRowSizeProperties ();
00196 void DirtyContentsSizeProperties ();
00197
00198
00199 void UpdateTotalSpacing () const;
00200 void UpdateColumnSizePropertyAllocation () const;
00201 void UpdateColumnSizeProperties () const;
00202 void UpdateRowSizePropertyAllocation () const;
00203 void UpdateRowSizeProperties () const;
00204 void UpdateContentsSizeProperties () const;
00205
00206 void DeleteColumnSizePropertyArrays () const;
00207 void DeleteRowSizePropertyArrays () const;
00208
00209 void Initialize (
00210 LineDirection major_direction,
00211 Uint32 major_count);
00212
00213
00214 LineDirection m_major_direction;
00215
00216
00217 Uint32 m_major_count;
00218
00219
00220
00221 bool m_is_using_zeroed_frame_margins;
00222
00223
00224 bool m_is_using_zeroed_layout_spacing_margins;
00225
00226 mutable bool m_total_spacing_needs_update;
00227
00228 mutable ScreenCoordVector2 m_total_spacing;
00229
00230 mutable bool m_column_size_property_arrays_need_reallocation;
00231 mutable bool m_column_size_properties_need_update;
00232
00233 mutable Uint32 m_column_count;
00234 mutable SizeProperties *m_column_size_properties;
00235 mutable ScreenCoord *m_column_width;
00236 mutable bool *m_column_is_hidden;
00237 mutable Uint32 m_hidden_column_count;
00238
00239 mutable bool m_row_size_property_arrays_need_reallocation;
00240 mutable bool m_row_size_properties_need_update;
00241
00242 mutable Uint32 m_row_count;
00243 mutable SizeProperties *m_row_size_properties;
00244 mutable ScreenCoord *m_row_height;
00245 mutable bool *m_row_is_hidden;
00246 mutable Uint32 m_hidden_row_count;
00247
00248
00249 mutable bool m_contents_size_properties_need_update;
00250 mutable SizeProperties m_contents_size_properties;
00251
00252
00253 ScreenCoordVector2 m_line_share_of_size;
00254 };
00255
00256 }
00257
00258 #endif // !defined(_XRB_LAYOUT_HPP_)