Skip to content

Commit ea5d308

Browse files
committed
refactor window
1 parent ed8ce76 commit ea5d308

File tree

2 files changed

+32
-48
lines changed

2 files changed

+32
-48
lines changed

src/ruis/widget/group/window.cpp

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,8 @@ utki::shared_ref<container> make_caption(
208208

209209
utki::shared_ref<container> make_middle(
210210
utki::shared_ref<context> c, //
211-
container::parameters container_params,
212-
string title,
213-
widget_list children
211+
utki::shared_ref<container> content_conatiner,
212+
string title
214213
)
215214
{
216215
// clang-format off
@@ -228,30 +227,16 @@ utki::shared_ref<container> make_middle(
228227
make_caption(c,
229228
std::move(title)
230229
),
231-
m::container(c,
232-
{
233-
.layout_params = {
234-
.dims = {ruis::dim::fill, ruis::dim::fill},
235-
.weight = 1
236-
},
237-
.widget_params = {
238-
.id = "ruis_content"s,
239-
.clip = true
240-
},
241-
.container_params = std::move(container_params)
242-
},
243-
std::move(children)
244-
)
230+
std::move(content_conatiner)
245231
}
246232
);
247233
// clang-format on
248234
}
249235

250236
utki::shared_ref<container> make_middle_row(
251237
utki::shared_ref<context> c, //
252-
container::parameters container_params,
253-
string title,
254-
widget_list children
238+
utki::shared_ref<container> content_container,
239+
string title
255240
)
256241
{
257242
// clang-format off
@@ -277,9 +262,8 @@ utki::shared_ref<container> make_middle_row(
277262
}
278263
),
279264
make_middle(c,
280-
std::move(container_params),
281-
std::move(title),
282-
std::move(children)
265+
std::move(content_container),
266+
std::move(title)
283267
),
284268
m::mouse_proxy(c,
285269
{
@@ -298,9 +282,8 @@ utki::shared_ref<container> make_middle_row(
298282

299283
std::vector<utki::shared_ref<widget>> make_children(
300284
utki::shared_ref<context> c, //
301-
container::parameters container_params,
302-
string title,
303-
widget_list children
285+
utki::shared_ref<container> content_container,
286+
string title
304287
)
305288
{
306289
// clang-format off
@@ -317,9 +300,8 @@ std::vector<utki::shared_ref<widget>> make_children(
317300
{
318301
make_top_row(c),
319302
make_middle_row(c,
320-
std::move(container_params),
321-
std::move(title),
322-
std::move(children)
303+
std::move(content_container),
304+
std::move(title)
323305
),
324306
make_bottom_row(c)
325307
}
@@ -351,6 +333,23 @@ window::window(
351333
std::move(params.layout_params),
352334
std::move(params.widget_params)
353335
),
336+
content_wrapping(
337+
m::container(this->context,
338+
// clang-format off
339+
{
340+
.layout_params = {
341+
.dims = {ruis::dim::fill, ruis::dim::fill},
342+
.weight = 1
343+
},
344+
.widget_params = {
345+
.clip = true
346+
},
347+
.container_params = std::move(params.container_params)
348+
},
349+
// clang-format on
350+
std::move(children)
351+
)
352+
),
354353
// clang-format off
355354
container( //
356355
this->context,
@@ -361,9 +360,8 @@ window::window(
361360
},
362361
make_children(
363362
this->context, //
364-
std::move(params.container_params),
365-
std::move(params.title),
366-
std::move(children)
363+
this->content_container,
364+
std::move(params.title)
367365
)
368366
)
369367
// clang-format on
@@ -414,9 +412,6 @@ window::window(
414412
void ruis::window::setup_widgets()
415413
{
416414
// TODO: refactor to avoid widget lookup by id.
417-
this->content_area = this->try_get_widget_as<container>("ruis_content");
418-
ASSERT(this->content_area)
419-
420415
this->title = this->try_get_widget_as<text>("ruis_title");
421416
ASSERT(this->title)
422417

src/ruis/widget/group/window.hpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121

2222
#pragma once
2323

24+
#include "../../util/content_wrapping.hpp"
2425
#include "../../util/length.hpp"
2526
#include "../label/rectangle.hpp"
2627
#include "../label/text.hpp"
@@ -37,10 +38,10 @@ namespace ruis {
3738
* @param title - text of the window title.
3839
* @param look - style settings.
3940
*/
40-
// TODO: derive from padding
4141
// NOLINTNEXTLINE(bugprone-incorrect-enable-shared-from-this, "std::shared_from_this is public via widget")
4242
class window :
4343
virtual public widget, //
44+
public content_wrapping,
4445
private container
4546
{
4647
ruis::vector2 empty_min_dim; // minimal dimension of empty window
@@ -53,8 +54,6 @@ class window :
5354

5455
std::shared_ptr<text> title;
5556

56-
std::shared_ptr<container> content_area;
57-
5857
std::shared_ptr<widget> lt_border;
5958
std::shared_ptr<widget> rt_border;
6059
std::shared_ptr<widget> t_border;
@@ -110,16 +109,6 @@ class window :
110109

111110
void set_title(std::u32string str);
112111

113-
/**
114-
* @brief Get window content area.
115-
* This is where child widgets are stored.
116-
* @return Window content area.
117-
*/
118-
container& content()
119-
{
120-
return *this->content_area;
121-
}
122-
123112
/**
124113
* @brief Move the window to the Z order top within its parent.
125114
*/

0 commit comments

Comments
 (0)