The Battle for Wesnoth
1.19.7+dev
gui
widgets
scrollbar_container_private.hpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2009 - 2024
3
by Mark de Wever <koraq@xs4all.nl>
4
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY.
12
13
See the COPYING file for more details.
14
*/
15
16
#pragma once
17
18
#include "
gui/widgets/scrollbar_container.hpp
"
19
20
#include "
utils/const_clone.hpp
"
21
22
/**
23
* @file
24
* Helper for header for the scrollbar_container.
25
*
26
* @note This file should only be included by scrollbar_container.cpp.
27
*
28
* This file is being used for a small experiment in which some private
29
* functions of scrollbar_container are no longer in scrollbar_container
30
* but moved in a friend class with static functions. The goal is to have
31
* less header recompilations, when there's a need to add or remove a private
32
* function. Also non-trivial functions like 'const foo& bar() const' and
33
* 'foo& bar()' are wrapped in a template to avoid code duplication (for
34
* typing not for the binary) to make maintenance easier.
35
*/
36
37
namespace
gui2
38
{
39
40
/**
41
* Helper to implement private functions without modifying the header.
42
*
43
* The class is a helper to avoid recompilation and only has static
44
* functions.
45
*/
46
struct
scrollbar_container_implementation
47
{
48
/**
49
* Implementation for the wrappers for
50
* [const] widget* scrollbar_container::find_at(
51
* const point&, const bool) [const].
52
*
53
* @tparam W widget or const widget.
54
*/
55
template
<
class
W>
56
static
W*
57
find_at
(
utils::const_clone_ref<scrollbar_container, W>
58
scrollbar_container
,
59
const
point
&
coordinate
,
60
const
bool
must_be_active)
61
{
62
63
assert(
scrollbar_container
.
content_
64
&&
scrollbar_container
.
content_grid_
);
65
66
W* result =
scrollbar_container
.container_base::find_at(
coordinate
,
67
must_be_active);
68
69
if
(result ==
scrollbar_container
.
content_
) {
70
return
scrollbar_container
.
content_grid_
->find_at(
coordinate
,
71
must_be_active);
72
}
73
74
return
result;
75
}
76
77
/**
78
* Implementation for the wrappers for
79
* [const] widget* scrollbar_container::find(
80
* const std::string&, const bool) [const].
81
*
82
* @tparam W widget or const widget.
83
*/
84
template
<
class
W>
85
static
W*
86
find
(
utils::const_clone_ref<scrollbar_container, W>
87
scrollbar_container
,
88
const
std::string_view
id
,
89
const
bool
must_be_active)
90
{
91
// Inherited.
92
W* result =
scrollbar_container
.container_base::find(
id
, must_be_active);
93
94
// Can be called before finalize so test instead of assert for the grid.
95
if
(!result &&
scrollbar_container
.
content_grid_
) {
96
result =
scrollbar_container
.
content_grid_
->find(
id
,
97
must_be_active);
98
}
99
100
return
result;
101
}
102
};
103
104
}
// namespace gui2
gui2::scrollbar_container
Base class for creating containers with one or two scrollbar(s).
Definition:
scrollbar_container.hpp:42
gui2::scrollbar_container::content_
spacer * content_
Dummy spacer to hold the contents location.
Definition:
scrollbar_container.hpp:506
gui2::scrollbar_container::content_grid_
std::unique_ptr< grid > content_grid_
The grid that holds the content.
Definition:
scrollbar_container.hpp:503
const_clone.hpp
gui2
Generic file dialog.
Definition:
draw_manager.hpp:21
t_translation::coordinate
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
Definition:
translation.hpp:117
utils::const_clone_ref
typename const_clone< D, S >::reference const_clone_ref
Definition:
const_clone.hpp:63
scrollbar_container.hpp
gui2::scrollbar_container_implementation
Helper to implement private functions without modifying the header.
Definition:
scrollbar_container_private.hpp:47
gui2::scrollbar_container_implementation::find
static W * find(utils::const_clone_ref< scrollbar_container, W > scrollbar_container, const std::string_view id, const bool must_be_active)
Implementation for the wrappers for [const] widget* scrollbar_container::find( const std::string&,...
Definition:
scrollbar_container_private.hpp:86
gui2::scrollbar_container_implementation::find_at
static W * find_at(utils::const_clone_ref< scrollbar_container, W > scrollbar_container, const point &coordinate, const bool must_be_active)
Implementation for the wrappers for [const] widget* scrollbar_container::find_at( const point&,...
Definition:
scrollbar_container_private.hpp:57
point
Holds a 2D point.
Definition:
point.hpp:25
Generated by
1.9.1