Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
WidgetContainer.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 Julien Bernard
4 * Copyright (C) 2018 Lilian Franchi
5 *
6 * This software is provided 'as-is', without any express or implied
7 * warranty. In no event will the authors be held liable for any damages
8 * arising from the use of this software.
9 *
10 * Permission is granted to anyone to use this software for any purpose,
11 * including commercial applications, and to alter it and redistribute it
12 * freely, subject to the following restrictions:
13 *
14 * 1. The origin of this software must not be misrepresented; you must not
15 * claim that you wrote the original software. If you use this software
16 * in a product, an acknowledgment in the product documentation would be
17 * appreciated but is not required.
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 * 3. This notice may not be removed or altered from any source distribution.
21 */
22#ifndef GF_WIDGET_CONTAINER_H
23#define GF_WIDGET_CONTAINER_H
24
25#include <vector>
26
27#include "GraphicsApi.h"
28#include "Ref.h"
29#include "RenderStates.h"
30
31namespace gf {
32#ifndef DOXYGEN_SHOULD_SKIP_THIS
33inline namespace v1 {
34#endif
35
36 class Widget;
37 class RenderTarget;
38
45 class GF_GRAPHICS_API WidgetContainer {
46 public:
51
61 void render(RenderTarget &target, const RenderStates& states = RenderStates());
62
68 void pointTo(Vector2f coords);
69
75 void addWidget(Widget& widget);
76
85
90
95
100
104 void clear();
105
106 private:
107 void unselectCurrentlySelected();
108
109 void computePreviousIndex();
110 void computeNextIndex();
111
112 Widget& getCurrent();
113
114 private:
115 std::vector<Ref<Widget>> m_widgets;
116 std::size_t m_selectedWidgetIndex;
117 bool m_widgetIsSelected;
118 };
119
120#ifndef DOXYGEN_SHOULD_SKIP_THIS
121}
122#endif
123}
124
125#endif // WIDGETS_WIDGET_CONTAINER_H
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:102
A collection of widgets.
Definition: WidgetContainer.h:45
void render(RenderTarget &target, const RenderStates &states=RenderStates())
Render the widgets on the target.
Widget * removeWidget(Widget *widget)
Remove a widget from the list.
void clear()
Remove all widgets.
WidgetContainer()
Construct a widget wontainer with a given view.
void selectPreviousWidget()
Select the previous widget in the list as the current selected widget.
void addWidget(Widget &widget)
Add a widget to the list of widgets.
void pointTo(Vector2f coords)
Check if the given coords are hover a widget and set it selected if so.
void triggerAction()
Trigger the callback of the current selected widget.
void selectNextWidget()
Select the next widget in the list as the current selected widget.
The widgets abstract class.
Definition: Widget.h:55
The namespace for gf classes.
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82