The Battle for Wesnoth
1.21.0-dev
Loading...
Searching...
No Matches
gui
widgets
multimenu_button.hpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2008 - 2025
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/core/widget_definition.hpp
"
19
20
#include "
gui/dialogs/drop_down_menu.hpp
"
21
22
#include "
gui/widgets/styled_widget.hpp
"
23
24
25
26
namespace
gui2
27
{
28
namespace
implementation
29
{
30
struct
builder_multimenu_button;
31
}
32
33
// ------------ WIDGET -----------{
34
35
class
multimenu_button
:
public
styled_widget
36
{
37
public
:
38
explicit
multimenu_button
(
const
implementation::builder_multimenu_button
& builder);
39
40
/***** ***** ***** ***** Inherited ***** ***** ***** *****/
41
42
/** See @ref styled_widget::set_active. */
43
virtual
void
set_active
(
const
bool
active)
override
;
44
45
/** See @ref styled_widget::get_active. */
46
virtual
bool
get_active
()
const override
;
47
48
/** See @ref styled_widget::get_state. */
49
virtual
unsigned
get_state
()
const override
;
50
51
/***** ***** ***** setters / getters for members ***** ****** *****/
52
53
/**
54
* Sets the maximum number of selected elements shown on the label.
55
* If more are selected, the label will say "and N others".
56
*
57
* @param max The maximum number of elements to show
58
*/
59
void
set_max_shown
(
const
unsigned
max)
60
{
61
max_shown_
= max;
62
}
63
64
/**
65
* Get the maximum number of selected elements shown on the label.
66
*
67
* @returns The maximum number of elements to show
68
*/
69
unsigned
get_max_shown
()
70
{
71
return
max_shown_
;
72
}
73
74
/**
75
* Get the number of options available in the menu
76
*
77
* @returns The number of options in the menu
78
*/
79
unsigned
num_options
()
80
{
81
return
values_
.size();
82
}
83
84
/**
85
* Select an option in the menu
86
*
87
* @param option The option to select
88
* @param selected True to select it, or false to deselect it
89
*/
90
void
select_option
(
const
unsigned
option,
const
bool
selected =
true
);
91
92
/**
93
* Set the options selected in the menu.
94
*
95
* @param states A mask specifying which options to select and deselect
96
*/
97
void
select_options
(
const
boost::dynamic_bitset<>& states);
98
99
/**
100
* Set the available menu options.
101
*
102
* @param values A list of options to show in the menu
103
*/
104
void
set_values
(
const
std::vector<::config>& values);
105
106
/**
107
* Get the current state of the menu options.
108
*
109
* @returns A mask specifying which options are selected
110
*/
111
boost::dynamic_bitset<>
get_toggle_states
()
const
112
{
113
return
toggle_states_
;
114
}
115
116
/**
117
* Deselect all the menu options.
118
*/
119
void
reset_toggle_states
();
120
121
private
:
122
/**
123
* Possible states of the widget.
124
*
125
* Note the order of the states must be the same as defined in settings.hpp.
126
*/
127
enum
state_t
{
128
ENABLED
,
129
DISABLED
,
130
PRESSED
,
131
FOCUSED
,
132
};
133
134
void
set_state
(
const
state_t
state);
135
136
/**
137
* Current state of the widget.
138
*
139
* The state of the widget determines what to render and how the widget
140
* reacts to certain 'events'.
141
*/
142
state_t
state_
;
143
144
/**
145
* The maximum number of selected states to list in the label
146
*/
147
unsigned
max_shown_
;
148
149
std::vector<::config>
values_
;
150
151
boost::dynamic_bitset<>
toggle_states_
;
152
153
dialogs::drop_down_menu
*
droplist_
;
154
155
void
update_config_from_toggle_states
();
156
void
update_label
();
157
158
public
:
159
/** Static type getter that does not rely on the widget being constructed. */
160
static
const
std::string&
type
();
161
162
private
:
163
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
164
virtual
const
std::string&
get_control_type
()
const override
;
165
166
/***** ***** ***** signal handlers ***** ****** *****/
167
168
void
signal_handler_mouse_enter
(
const
event::ui_event
event,
bool
& handled);
169
170
void
signal_handler_mouse_leave
(
const
event::ui_event
event,
bool
& handled);
171
172
void
signal_handler_left_button_down
(
const
event::ui_event
event,
bool
& handled);
173
174
void
signal_handler_left_button_up
(
const
event::ui_event
event,
bool
& handled);
175
176
void
signal_handler_left_button_click
(
const
event::ui_event
event,
bool
& handled);
177
178
void
signal_handler_notify_changed
();
179
};
180
181
// }---------- DEFINITION ---------{
182
183
struct
multimenu_button_definition
:
public
styled_widget_definition
184
{
185
explicit
multimenu_button_definition
(
const
config
&
cfg
);
186
187
struct
resolution
:
public
resolution_definition
188
{
189
explicit
resolution
(
const
config
&
cfg
);
190
};
191
};
192
193
// }---------- BUILDER -----------{
194
195
196
namespace
implementation
197
{
198
199
struct
builder_multimenu_button
:
public
builder_styled_widget
200
{
201
public
:
202
explicit
builder_multimenu_button
(
const
config
&
cfg
);
203
204
using
builder_styled_widget::build
;
205
206
virtual
std::unique_ptr<widget>
build
()
const override
;
207
208
private
:
209
unsigned
max_shown_
;
210
std::vector<::config>
options_
;
211
};
212
213
}
// namespace implementation
214
215
// }------------ END --------------
216
217
}
// namespace gui2
config
A config object defines a single node in a WML file, with access to child nodes.
Definition
config.hpp:157
gui2::dialogs::drop_down_menu
Used by the menu_button widget.
Definition
drop_down_menu.hpp:34
gui2::multimenu_button
Definition
multimenu_button.hpp:36
gui2::multimenu_button::toggle_states_
boost::dynamic_bitset toggle_states_
Definition
multimenu_button.hpp:151
gui2::multimenu_button::signal_handler_mouse_enter
void signal_handler_mouse_enter(const event::ui_event event, bool &handled)
Definition
multimenu_button.cpp:95
gui2::multimenu_button::state_
state_t state_
Current state of the widget.
Definition
multimenu_button.hpp:142
gui2::multimenu_button::type
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
gui2::multimenu_button::signal_handler_notify_changed
void signal_handler_notify_changed()
Definition
multimenu_button.cpp:201
gui2::multimenu_button::set_max_shown
void set_max_shown(const unsigned max)
Sets the maximum number of selected elements shown on the label.
Definition
multimenu_button.hpp:59
gui2::multimenu_button::signal_handler_left_button_click
void signal_handler_left_button_click(const event::ui_event event, bool &handled)
Definition
multimenu_button.cpp:132
gui2::multimenu_button::reset_toggle_states
void reset_toggle_states()
Deselect all the menu options.
Definition
multimenu_button.cpp:194
gui2::multimenu_button::get_control_type
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
gui2::multimenu_button::get_max_shown
unsigned get_max_shown()
Get the maximum number of selected elements shown on the label.
Definition
multimenu_button.hpp:69
gui2::multimenu_button::update_label
void update_label()
Definition
multimenu_button.cpp:159
gui2::multimenu_button::select_options
void select_options(const boost::dynamic_bitset<> &states)
Set the options selected in the menu.
Definition
multimenu_button.cpp:217
gui2::multimenu_button::set_values
void set_values(const std::vector<::config > &values)
Set the available menu options.
Definition
multimenu_button.cpp:225
gui2::multimenu_button::num_options
unsigned num_options()
Get the number of options available in the menu.
Definition
multimenu_button.hpp:79
gui2::multimenu_button::signal_handler_left_button_up
void signal_handler_left_button_up(const event::ui_event event, bool &handled)
Definition
multimenu_button.cpp:124
gui2::multimenu_button::update_config_from_toggle_states
void update_config_from_toggle_states()
Definition
multimenu_button.cpp:185
gui2::multimenu_button::values_
std::vector<::config > values_
Definition
multimenu_button.hpp:149
gui2::multimenu_button::get_active
virtual bool get_active() const override
See styled_widget::get_active.
Definition
multimenu_button.cpp:77
gui2::multimenu_button::state_t
state_t
Possible states of the widget.
Definition
multimenu_button.hpp:127
gui2::multimenu_button::DISABLED
@ DISABLED
Definition
multimenu_button.hpp:129
gui2::multimenu_button::PRESSED
@ PRESSED
Definition
multimenu_button.hpp:130
gui2::multimenu_button::ENABLED
@ ENABLED
Definition
multimenu_button.hpp:128
gui2::multimenu_button::FOCUSED
@ FOCUSED
Definition
multimenu_button.hpp:131
gui2::multimenu_button::set_active
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition
multimenu_button.cpp:70
gui2::multimenu_button::signal_handler_left_button_down
void signal_handler_left_button_down(const event::ui_event event, bool &handled)
Definition
multimenu_button.cpp:111
gui2::multimenu_button::select_option
void select_option(const unsigned option, const bool selected=true)
Select an option in the menu.
Definition
multimenu_button.cpp:209
gui2::multimenu_button::droplist_
dialogs::drop_down_menu * droplist_
Definition
multimenu_button.hpp:153
gui2::multimenu_button::signal_handler_mouse_leave
void signal_handler_mouse_leave(const event::ui_event event, bool &handled)
Definition
multimenu_button.cpp:103
gui2::multimenu_button::get_toggle_states
boost::dynamic_bitset get_toggle_states() const
Get the current state of the menu options.
Definition
multimenu_button.hpp:111
gui2::multimenu_button::max_shown_
unsigned max_shown_
The maximum number of selected states to list in the label.
Definition
multimenu_button.hpp:147
gui2::multimenu_button::set_state
void set_state(const state_t state)
Definition
multimenu_button.cpp:87
gui2::multimenu_button::get_state
virtual unsigned get_state() const override
See styled_widget::get_state.
Definition
multimenu_button.cpp:82
gui2::styled_widget
Definition
styled_widget.hpp:35
drop_down_menu.hpp
cfg
const config * cfg
Definition
faction_select.cpp:44
gui2::event::ui_event
ui_event
The event sent to the dispatcher.
Definition
handler.hpp:115
gui2
Generic file dialog.
Definition
draw_manager.hpp:21
implementation
Contains the implementation details for lexical_cast and shouldn't be used directly.
gui2::implementation::builder_multimenu_button
Definition
multimenu_button.hpp:200
gui2::implementation::builder_multimenu_button::options_
std::vector<::config > options_
Definition
multimenu_button.hpp:210
gui2::implementation::builder_multimenu_button::max_shown_
unsigned max_shown_
Definition
multimenu_button.hpp:209
gui2::implementation::builder_multimenu_button::build
virtual std::unique_ptr< widget > build() const override
Definition
multimenu_button.cpp:271
gui2::implementation::builder_styled_widget
Definition
styled_widget.hpp:514
gui2::implementation::builder_styled_widget::build
virtual std::unique_ptr< widget > build() const=0
gui2::multimenu_button_definition::resolution
Definition
multimenu_button.hpp:188
gui2::multimenu_button_definition
Definition
multimenu_button.hpp:184
gui2::resolution_definition
Definition
widget_definition.hpp:50
gui2::styled_widget_definition
Definition
widget_definition.hpp:84
styled_widget.hpp
widget_definition.hpp
Generated by
1.9.8