The Battle for Wesnoth  1.19.0-dev
viewport.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 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 #include "gui/widgets/widget.hpp"
20 
21 namespace gui2
22 {
23 
24 // ------------ WIDGET -----------{
25 
26 namespace implementation
27 {
28 struct builder_viewport;
29 } // namespace implementation
30 
31 
32 /**
33  * @ingroup GUIWidgetWML
34  *
35  * A viewport is an special widget used to view only a part of the widget it 'holds'.
36  *
37  * List with the viewport specific variables:
38  * Key |Type |Default |Description
39  * ---------------|------------------------------------------------|---------|-----------
40  * grow_direction | @ref guivartype_grow_direction "grow_direction"|mandatory|The direction in which new items grow.
41  * parallel_items | @ref guivartype_unsigned "unsigned" |mandatory|The number of items that are growing in parallel.
42  * item_definition| @ref guivartype_section "section" |mandatory|The definition of a new item.
43  */
44 class viewport : public widget
45 {
46  friend struct viewport_implementation;
47 
48 public:
50  const builder_widget::replacements_map& replacements);
51 
52  ~viewport();
53 
54  /** See @ref widget::place. */
55  virtual void place(const point& origin, const point& size) override;
56 
57  /** See @ref widget::layout_initialize. */
58  virtual void layout_initialize(const bool full_initialization) override;
59 
60  /** See @ref widget::impl_draw_children. */
61  virtual void impl_draw_children() override;
62 
63  /** See @ref widget::request_reduce_width. */
64  virtual void request_reduce_width(const unsigned maximum_width) override;
65 
66  /** See @ref widget::find_at. */
67  virtual widget* find_at(const point& coordinate,
68  const bool must_be_active) override;
69 
70  /** See @ref widget::find_at. */
71  virtual const widget* find_at(const point& coordinate,
72  const bool must_be_active) const override;
73 
74  /** See @ref widget::find. */
75  widget* find(const std::string& id, const bool must_be_active) override;
76 
77  /** See @ref widget::find. */
78  const widget* find(const std::string& id,
79  const bool must_be_active) const override;
80 
81 private:
82  /** See @ref widget::calculate_best_size. */
83  virtual point calculate_best_size() const override;
84 
85 public:
86  /** See @ref widget::disable_click_dismiss. */
87  bool disable_click_dismiss() const override;
88 
89  /** See @ref widget::create_walker. */
90  virtual iteration::walker_ptr create_walker() override;
91 
92 private:
93  std::unique_ptr<widget> widget_;
94 };
95 
96 // }---------- BUILDER -----------{
97 
98 namespace implementation
99 {
100 
102 {
103  explicit builder_viewport(const config& cfg);
104 
105  virtual std::unique_ptr<widget> build() const override;
106 
107  virtual std::unique_ptr<widget> build(const replacements_map& replacements) const override;
108 
110 };
111 
112 } // namespace implementation
113 
114 // }------------ END --------------
115 
116 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
A viewport is an special widget used to view only a part of the widget it 'holds'.
Definition: viewport.hpp:45
virtual void layout_initialize(const bool full_initialization) override
See widget::layout_initialize.
Definition: viewport.cpp:101
virtual point calculate_best_size() const override
See widget::calculate_best_size.
Definition: viewport.cpp:145
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
Definition: viewport.cpp:150
std::unique_ptr< widget > widget_
Definition: viewport.hpp:93
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
Definition: viewport.cpp:119
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
Definition: viewport.cpp:134
virtual iteration::walker_ptr create_walker() override
See widget::create_walker.
Definition: viewport.cpp:155
virtual void impl_draw_children() override
See widget::impl_draw_children.
Definition: viewport.cpp:110
viewport(const implementation::builder_viewport &builder, const builder_widget::replacements_map &replacements)
Definition: viewport.cpp:82
virtual void place(const point &origin, const point &size) override
See widget::place.
Definition: viewport.cpp:94
virtual widget * find_at(const point &coordinate, const bool must_be_active) override
See widget::find_at.
Definition: viewport.cpp:123
Base class for all widgets.
Definition: widget.hpp:53
std::unique_ptr< class walker_base > walker_ptr
Definition: widget.hpp:42
Generic file dialog.
std::shared_ptr< builder_widget > builder_widget_ptr
Contains the implementation details for lexical_cast and shouldn't be used directly.
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:85
Contains the info needed to instantiate a widget.
std::map< std::string, std::shared_ptr< builder_widget > > replacements_map
The replacements type is used to define replacement types.
virtual std::unique_ptr< widget > build() const override
Definition: viewport.cpp:174
Helper to implement private functions without modifying the header.
Definition: viewport.cpp:41
Holds a 2D point.
Definition: point.hpp:25