The Battle for Wesnoth  1.19.7+dev
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 
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  */
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*
59  const point& coordinate,
60  const bool must_be_active)
61  {
62 
65 
66  W* result = scrollbar_container.container_base::find_at(coordinate,
67  must_be_active);
68 
69  if(result == scrollbar_container.content_) {
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*
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
Base class for creating containers with one or two scrollbar(s).
spacer * content_
Dummy spacer to hold the contents location.
std::unique_ptr< grid > content_grid_
The grid that holds the content.
Generic file dialog.
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
typename const_clone< D, S >::reference const_clone_ref
Definition: const_clone.hpp:63
Helper to implement private functions without modifying the header.
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&,...
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&,...
Holds a 2D point.
Definition: point.hpp:25