Show cursor on exit
[utui.git] / layout.cc
blob6020c4ef12c26f434be8149f43896047a00c9ba6
1 // Copyright (c) 2006 by Mike Sharov <msharov@users.sourceforge.net>
2 //
3 // layout.cc
4 //
6 #include "layout.h"
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
28 wr = Rect();
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.
34 ///
35 void CLayout::DeleteAllLayoutItems (void)
37 foreach (itemvec_t::iterator, i, m_Items)
38 Delete (*i);
39 m_Items.clear();
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)
46 : CLayout (),
47 m_Dir (dir),
48 m_Spacing (spacing),
49 m_LMargin (lmargin),
50 m_RMargin (rmargin)
54 /// Resizes all items to their tiled locations.
55 void CTileLayout::OnResize (rcrect_t r)
57 Rect tr (r), cwr;
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];
63 LI(i).OnResize (tr);
64 tr[0][m_Dir] += cs[m_Dir] + m_Spacing;
65 tr[1] = r[1];
69 /// Returns the size of the tiled items.
70 void CTileLayout::SizeHints (rrect_t tr) const
72 Rect cwr;
73 Size2d sz;
74 Point2d tl (tr[0]);
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;
86 tr[0] = tl;
87 tr[1] = tr[0] + sz;
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)
94 : CLayout (),
95 m_Dir (dir),
96 m_Where (where),
97 m_LMargin (lmargin),
98 m_RMargin (rmargin)
102 /// Aligns item using parameters.
103 void CAlignLayout::OnResize (rcrect_t r)
105 Rect nr (r);
106 SizeHints (nr);
107 nr[0][m_Dir] += m_LMargin;
108 nr[1][m_Dir] -= m_RMargin;
109 LI(0).OnResize (nr);
112 /// Returns the rect of the aligned item.
113 void CAlignLayout::SizeHints (rrect_t nr) const
115 Rect cwr (nr);
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];
123 nr[1] = nr[0] + sz;
126 //----------------------------------------------------------------------
128 /// Resizes item to fit inside the border.
129 void CBorderLayout::OnResize (rcrect_t r)
131 if (!NLI())
132 return;
133 Rect intr (r);
134 intr.Expand (-1);
135 LI(0).OnResize (intr);
138 /// Returns rect of item with border.
139 void CBorderLayout::SizeHints (rrect_t intr) const
141 if (!NLI())
142 return;
143 intr.Expand (-1);
144 LI(0).SizeHints (intr);
145 intr.Expand (1);
148 //----------------------------------------------------------------------