00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <omgui/api/tablelayout.h>
00024 #include <omgui/common/panel.h>
00025 #include <omgui/tablelayout.h>
00026
00027 #include <set>
00028 #include <list>
00029 #include <map>
00030
00031 namespace omgui {
00032 namespace common {
00033
00037 namespace tablelayoutdetails {
00038
00039 enum GROUP {
00040 COLUMN,
00041 ROW,
00042 };
00043
00044 const float DEFAULT_WEIGHT = 1;
00045
00046 class LayoutData
00047 {
00048 public:
00049 LayoutData();
00050
00054 int flags;
00055
00059 int pad_left, pad_top, pad_right, pad_bottom;
00060
00064 int anchor_left, anchor_top, anchor_right, anchor_bottom;
00065 };
00066
00067 struct WidgetInfo
00068 {
00070 omgui::Widget * const widget;
00071
00072 omgui::Size m_min_size;
00073 omgui::Size m_max_size;
00074 omgui::Size m_natural_size;
00075 omgui::Rect m_rect;
00076
00078 LayoutData data;
00079
00080 WidgetInfo(omgui::Widget *w, const LayoutData &d) : widget(w), data(d) { }
00081
00082 bool operator < (const WidgetInfo &other) const
00083 {
00084 return widget < other.widget;
00085 }
00086 };
00087
00088 typedef std::list<WidgetInfo> Widgets;
00089 typedef std::map<int, WidgetInfo *> GroupWidgets;
00090
00094 struct GroupData {
00095 GroupWidgets m_widgets;
00096 bool m_done;
00097 float m_weight;
00098 int m_min_size;
00099 omgui::Rect m_rect;
00100
00101 GroupData(float weight = DEFAULT_WEIGHT)
00102 : m_done(false),
00103 m_weight(weight),
00104 m_min_size(0)
00105 { }
00106
00111 bool empty() const;
00112 };
00113
00114 typedef std::map<int, GroupData> Groups;
00115
00116 }
00117
00118 class TableLayout : public virtual Panel, public virtual omgui::api::TableLayout
00119 {
00120 public:
00121 TableLayout();
00122
00123 void create(const omgui::initializer::TableLayoutData ¶ms);
00124
00125 void remove_child(const Pointer<omgui::Widget> &);
00126
00127 void invalidate_cached_child_values();
00128
00129 void set_widget_layout_info(omgui::Widget *widget, const omgui::TableLayoutInfo &info);
00130 void set_column_weight(int column, float weight);
00131 void set_row_weight(int row, float weight);
00132 void set_column_gap(int gap);
00133 void set_row_gap(int gap);
00134 void set_gap(int gap);
00135 void set_margins(int margin);
00136 void set_margins(int left, int top, int right, int bottom);
00137 void set_left_margin(int margin);
00138 void set_top_margin(int margin);
00139 void set_right_margin(int margin);
00140 void set_bottom_margin(int margin);
00141
00142 omgui::Size get_min_size() const;
00143
00147 void update_layout();
00148
00149 private:
00150 typedef std::map<omgui::Widget*, omgui::Rect> WidgetRects;
00151
00152 mutable omgui::Size m_min_size, m_natural_size;
00153
00158 mutable bool m_values_invalid;
00159
00160 mutable tablelayoutdetails::Widgets m_widgets;
00161 mutable tablelayoutdetails::Groups m_rows, m_columns;
00162 mutable int m_non_empty_rows, m_non_empty_columns;
00163
00164 int m_row_gap, m_column_gap;
00165 int m_margin_top, m_margin_left, m_margin_right, m_margin_bottom;
00166
00171 void update_sizes() const;
00172
00176 template<tablelayoutdetails::GROUP> void update_group_sizes() const;
00177
00182 float &get_column_weight(int index);
00183
00188 float &get_row_weight(int index);
00189
00194 template<tablelayoutdetails::GROUP> void calc_group_sizes();
00195
00199 template<tablelayoutdetails::GROUP> tablelayoutdetails::Groups &get_widgets() const;
00200
00204 template<tablelayoutdetails::GROUP> tablelayoutdetails::GroupData &get_group_data(int index) const;
00205
00210 template<tablelayoutdetails::GROUP> bool get_group_data(int index, tablelayoutdetails::GroupData &data) const;
00211
00215 template<tablelayoutdetails::GROUP> int &get_size_value(omgui::Size &size) const;
00216
00220 template<tablelayoutdetails::GROUP> int get_size_value(const omgui::Size &size) const;
00221
00225 template<tablelayoutdetails::GROUP> int &get_pos_value(omgui::Point &pos) const;
00226
00230 template<tablelayoutdetails::GROUP> int get_pos_value(const omgui::Point &pos) const;
00231
00236 template<tablelayoutdetails::GROUP> void get_pad_values(const tablelayoutdetails::LayoutData &data, int &pad1, int &pad2) const;
00237
00242 template<tablelayoutdetails::GROUP> void get_margin_values(int &margin1, int &margin2) const;
00243
00247 template<tablelayoutdetails::GROUP> int get_gap() const;
00248
00252 template<tablelayoutdetails::GROUP> int &get_non_empty_groups() const;
00253
00257 template<tablelayoutdetails::GROUP> void get_anchors(const tablelayoutdetails::LayoutData &data, int &anchor1, int &anchor2) const;
00258 };
00259
00260 }
00261 }