-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
register_widget.hpp
62 lines (57 loc) · 3.76 KB
/
register_widget.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Copyright (C) 2007 - 2017 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
/**
* Registers a widget.
*
* Call this function to register a widget. Use this macro in the
* implementation, inside the gui2 namespace.
*
* See @ref gui2::load_widget_definitions for more information.
*
* @note When the type is foo_definition, the id "foo" and no special key best
* use RESISTER_WIDGET(foo) instead.
*
* @param type Class type of the window to register.
* @param id Id of the widget
* @param key The id to load if differs from id.
*/
#define REGISTER_WIDGET3(type, id, key) \
namespace \
{ \
namespace ns_##type##id \
{ \
struct register_helper \
{ \
register_helper() \
{ \
register_widget(#id, [](const config& cfg) { return std::make_shared<type>(cfg); }, key); \
\
register_builder_widget(#id, &make_builder<implementation::builder_##id>); \
} \
}; \
\
static struct register_helper register_helper; \
} \
}
/**
* Wrapper for REGISTER_WIDGET3.
*
* "Calls" REGISTER_WIDGET3(id_definition, id, nullptr)
*/
#define REGISTER_WIDGET(id) REGISTER_WIDGET3(id##_definition, id, nullptr) \
\
const std::string& id::get_control_type() const \
{ \
static const std::string result(#id); \
return result; \
}