Skip to content

Commit b38ca84

Browse files
committed
child_window documentation
1 parent 32c00a1 commit b38ca84

File tree

2 files changed

+88
-19
lines changed

2 files changed

+88
-19
lines changed

lib/include/elements/element/child_window.hpp

+88-16
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313

1414
namespace cycfi::elements
1515
{
16-
////////////////////////////////////////////////////////////////////////////
17-
// Child window: Are floating elements that may overlap and move to front
18-
// when clicked.
19-
////////////////////////////////////////////////////////////////////////////
16+
/**
17+
* \class child_window_element
18+
*
19+
* \brief
20+
* Class that represents a child window within a larger display context.
21+
*
22+
* Child windows are floating elements that may overlap with other
23+
* elements and can move to the front when clicked.
24+
*/
2025
class child_window_element : public floating_element
2126
{
2227
public:
@@ -26,26 +31,48 @@ namespace cycfi::elements
2631
bool click(context const& ctx, mouse_button btn) override;
2732
};
2833

34+
/**
35+
* \brief
36+
* Factory function to create a child window element.
37+
*
38+
* This function creates a child window by wrapping the given subject
39+
* (element) in a child_window_element. The resulting window has a
40+
* specified rectangular area.
41+
*
42+
* \tparam Subject
43+
* Subject must meet the `concepts::Element` concept.
44+
*
45+
* \param bounds
46+
* The boundaries of the child window.
47+
*
48+
* \param subject
49+
* An rvalue reference to the subject, the element to be wrapped in a
50+
* child window.
51+
*
52+
* \return
53+
* A proxy object of type `child_window_element` containing the
54+
* subject element, within defined boundaries.
55+
*/
2956
template <concepts::Element Subject>
3057
inline proxy<remove_cvref_t<Subject>, child_window_element>
3158
child_window(rect bounds, Subject&& subject)
3259
{
3360
return {std::forward<Subject>(subject), bounds};
3461
}
3562

36-
////////////////////////////////////////////////////////////////////////////
37-
// Movable: Allows an element (e.g. title_bar) to be movable if it is
38-
// contained inside a floating_element. The whole floating_element moves
39-
// when the element is dragged around.
40-
////////////////////////////////////////////////////////////////////////////
41-
4263
struct movable_tracker_info : tracker_info
4364
{
4465
using tracker_info::tracker_info;
4566

4667
float _offs_top, _offs_bottom;
4768
};
4869

70+
/**
71+
* \class movable_base
72+
*
73+
* \brief
74+
* A base class representing a movable element in the UI.
75+
*/
4976
class movable_base : public tracker<proxy_base, movable_tracker_info>
5077
{
5178
public:
@@ -58,18 +85,45 @@ namespace cycfi::elements
5885
void keep_tracking(context const& ctx, tracker_info& track_info) override;
5986
};
6087

88+
/**
89+
* \brief
90+
* Make an element movable.
91+
*
92+
* movable allows an element (e.g. title_bar) to be movable if it is
93+
* contained inside a floating_element. The whole floating_element
94+
* moves when the element is dragged around.
95+
*
96+
* \tparam Subject
97+
* The type of the subject. The Subject must meet the
98+
* `concepts::Element` concept.
99+
*
100+
* \param subject
101+
* The subject element that will be made movable.
102+
*
103+
* \return
104+
* The movable element.
105+
*/
61106
template <concepts::Element Subject>
62107
inline proxy<remove_cvref_t<Subject>, movable_base>
63108
movable(Subject&& subject)
64109
{
65110
return {std::forward<Subject>(subject)};
66111
}
67112

68-
////////////////////////////////////////////////////////////////////////////
69-
// Closable: When contained inside a floating_element, allows a button (or
70-
// any clickable element) to close the floating_element when it is
71-
// clicked.
72-
////////////////////////////////////////////////////////////////////////////
113+
/**
114+
* \class closable_element
115+
*
116+
* \brief
117+
* Class that encapsulates a closable UI element functionality.
118+
*
119+
* When contained inside a floating_element, this class allows a button
120+
* (or any clickable element) to close (or hide) the floating_element
121+
* when it is clicked.
122+
*
123+
* \tparam Subject
124+
* The type of the subject. Must satisfy the `concepts::Element`
125+
* concept.
126+
*/
73127
template <concepts::Element Subject>
74128
class closable_element : public proxy<Subject>
75129
{
@@ -80,6 +134,24 @@ namespace cycfi::elements
80134
void prepare_subject(context& ctx) override;
81135
};
82136

137+
/**
138+
* \brief
139+
* Create a closable element.
140+
*
141+
* If the subject is a part of a floating_element, this function
142+
* enables the subject to close its parent floating_element upon a
143+
* click event.
144+
*
145+
* \tparam Subject
146+
* The type of the subject. Must satisfy the `concepts::Element`
147+
* concept.
148+
*
149+
* \param subject
150+
* The element that is to be made closable.
151+
*
152+
* \return
153+
* The closable element.
154+
*/
83155
template <concepts::Element Subject>
84156
inline closable_element<remove_cvref_t<Subject>>
85157
closable(Subject&& subject)
@@ -100,7 +172,7 @@ namespace cycfi::elements
100172
{
101173
auto fl = find_parent<floating_element*>(ctx);
102174
if (fl)
103-
close_floating_element(ctx, fl);
175+
close_floating_element(ctx, fl);
104176
};
105177
}
106178
}

lib/src/element/child_window.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ namespace cycfi::elements
3333
return floating_element::click(ctx, btn);
3434
}
3535

36-
////////////////////////////////////////////////////////////////////////////
37-
// movable_base
38-
////////////////////////////////////////////////////////////////////////////
3936
element* movable_base::hit_test(context const& ctx, point p, bool /*leaf*/, bool /*control*/)
4037
{
4138
if (ctx.enabled && is_enabled() && ctx.bounds.includes(p))

0 commit comments

Comments
 (0)