1 // Copyright (c) 2006 by Mike Sharov <msharov@users.sourceforge.net>
8 //----------------------------------------------------------------------
10 /// Default constructor.
11 CLayout::CLayout (void)
15 /// Default destructor.
16 CLayout::~CLayout (void)
20 /// Resizes to fit everything into \p r.
21 void CLayout::OnResize (rcrect_t
)
25 /// Returns recommended size to fit everything into \p r.
26 void CLayout::SizeHints (rrect_t wr
) const
31 /// \brief Deletes all pointers in the layout item list.
32 /// This is normally called by #CWindow. Non-window layout objects do not own
33 /// the layout pointers stored in their lists.
35 void CLayout::DeleteAllLayoutItems (void)
37 foreach (itemvec_t::iterator
, i
, m_Items
)
42 //----------------------------------------------------------------------
44 /// Constructs a tile layout with axis \p dir, \p spacing, and margins.
45 CTileLayout::CTileLayout (ELayoutDir dir
, uint8_t spacing
, uint8_t lmargin
, uint8_t rmargin
)
54 /// Resizes all items to their tiled locations.
55 void CTileLayout::OnResize (rcrect_t r
)
58 tr
[0][m_Dir
] += m_LMargin
;
59 for (uoff_t i
= 0; i
< NLI(); ++i
) {
60 LI(i
).SizeHints (cwr
=tr
);
61 Size2d
cs (cwr
.Size());
62 tr
[1][m_Dir
] = tr
[0][m_Dir
] + cs
[m_Dir
];
64 tr
[0][m_Dir
] += cs
[m_Dir
] + m_Spacing
;
69 /// Returns the size of the tiled items.
70 void CTileLayout::SizeHints (rrect_t tr
) const
75 tr
[0][m_Dir
] += m_LMargin
;
76 sz
[m_Dir
] += m_LMargin
;
77 for (uoff_t i
= 0; i
< NLI(); ++i
) {
78 LI(i
).SizeHints (cwr
=tr
);
79 Size2d
cs (cwr
.Size());
80 cs
[m_Dir
] += m_Spacing
;
81 sz
[!m_Dir
] = max (sz
[!m_Dir
], cs
[!m_Dir
]);
82 sz
[m_Dir
] += cs
[m_Dir
];
83 tr
[0][m_Dir
] += cs
[m_Dir
];
85 sz
[m_Dir
] += m_RMargin
- m_Spacing
;
90 //----------------------------------------------------------------------
92 /// Creates alignment layout with axis \p dir, gravity \p where, and margins.
93 CAlignLayout::CAlignLayout (ELayoutDir dir
, ELayoutAlign where
, uint8_t lmargin
, uint8_t rmargin
)
102 /// Aligns item using parameters.
103 void CAlignLayout::OnResize (rcrect_t r
)
107 nr
[0][m_Dir
] += m_LMargin
;
108 nr
[1][m_Dir
] -= m_RMargin
;
112 /// Returns the rect of the aligned item.
113 void CAlignLayout::SizeHints (rrect_t nr
) const
116 LI(0).SizeHints (cwr
);
117 Size2d
sz (cwr
.Size());
118 sz
[m_Dir
] += m_LMargin
+ m_RMargin
;
119 if (m_Where
== la_Center
)
120 nr
[0][m_Dir
] += ((nr
[1][m_Dir
] - nr
[0][m_Dir
]) - sz
[m_Dir
]) / 2;
121 else if (m_Where
== la_Right
)
122 nr
[0][m_Dir
] = nr
[1][m_Dir
] - sz
[m_Dir
];
126 //----------------------------------------------------------------------
128 /// Resizes item to fit inside the border.
129 void CBorderLayout::OnResize (rcrect_t r
)
135 LI(0).OnResize (intr
);
138 /// Returns rect of item with border.
139 void CBorderLayout::SizeHints (rrect_t intr
) const
144 LI(0).SizeHints (intr
);
148 //----------------------------------------------------------------------