45 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
59 auto wp = std::make_unique<gui2::window>(def);
61 if(!lua_isnoneornil(L, 2)) {
75 if (!lua_isnoneornil(L, 3)) {
81 lua_pushinteger(L, v);
89 for(; !lua_isnoneornil(L,
i); ++
i)
93 int v = lua_tointeger(L,
i);
95 throw std::invalid_argument(
"negative index");
97 int n = list->get_item_count();
100 throw std::invalid_argument(
"index out of range");
104 list->add_row(
dummy);
107 w = list->get_row_grid(v - 1);
109 int v = lua_tointeger(L,
i);
111 throw std::invalid_argument(
"negative index");
113 int n = multi_page->get_page_count();
116 throw std::invalid_argument(
"index out of range");
120 multi_page->add_page(
dummy);
123 w = &multi_page->page_grid(v - 1);
126 if(lua_isnumber(L,
i)) {
127 int v = lua_tointeger(L,
i);
129 throw std::invalid_argument(
"negative index");
133 throw std::invalid_argument(
"index out of range");
138 std::string m = luaL_checkstring(L,
i);
139 w = tvn.
find(m,
false);
142 if(lua_isnumber(L,
i)) {
143 int v = lua_tointeger(L,
i);
145 throw std::invalid_argument(
"negative index");
147 int n = tree_view_node->count_children();
149 throw std::invalid_argument(
"index out of range");
151 w = &tree_view_node->get_child_at(v - 1);
154 std::string m = luaL_checkstring(L,
i);
155 w = tree_view_node->find(m,
false);
158 if(lua_isnumber(L,
i)) {
159 int v = lua_tointeger(L,
i);
161 throw std::invalid_argument(
"negative index");
163 int n = stacked_widget->get_layer_count();
165 throw std::invalid_argument(
"index out of range");
167 w = stacked_widget->get_layer_grid(v - 1);
169 std::string m = luaL_checkstring(L,
i);
170 w = stacked_widget->find(m,
false);
173 char const *m = lua_tostring(L,
i);
175 throw std::invalid_argument(
"expected a string");
177 w =
w->find(m,
false);
180 throw std::invalid_argument(
"widget not found");
203 return mp.get_item_count();
207 return mp.get_page_count();
212 return mp.count_children();
217 return number_of_items(
mp.get_root_node());
222 template<
typename TW
idget>
223 int check_index(lua_State* L,
int arg, TWidget&
w,
bool for_insertion, utils::optional<int>&
index)
225 int nitems = number_of_items(
w);
228 int max = for_insertion ? nitems + 1 : nitems;
233 if(*index <= 0 || *index > max) {
234 luaL_argerror(L, arg,
"widget child index out of range");
249 for(
int i = 0;
i < number; ++
i) {
264 utils::optional<int> pos = lua_check<utils::optional<int>>(L, 2);
265 int number = lua_check<utils::optional<int>>(L, 3).value_or(1);
268 int realpos = check_index(L, 2, *list,
false, pos);
269 list->remove_row(realpos, number);
271 int realpos = check_index(L, 2, *multi_page,
false, pos);
272 multi_page->remove_page(realpos, number);
274 int realpos = check_index(L, 2, *tree_view,
false, pos);
275 remove_treeview_node(tree_view->get_root_node(), realpos, number);
277 int realpos = check_index(L, 2, *tree_view_node,
false, pos);
278 remove_treeview_node(*tree_view_node, realpos, number);
280 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
303 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
314 ERR_LUA <<
"widget was deleted";
319 ERR_LUA <<
"cannot find window in widget callback";
338 throw std::invalid_argument(
"the widget has no window assigned");
340 if(!lua_isfunction(L, 2)) {
341 return luaL_argerror(L, 2,
"callback must be a function");
354 c->connect_click_handler(std::bind(&dialog_callback, L, wp,
"callback"));
364 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
380 int i = luaL_checkinteger(L, 2);
383 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
386 std::vector<gui2::canvas> &cv =
c->get_canvases();
387 if(
i < 1 ||
static_cast<unsigned>(
i) > cv.size()) {
388 return luaL_argerror(L, 2,
"out of bounds");
392 cv[
i - 1].set_cfg(cfg);
421 const std::string node_type = luaL_checkstring(L, 2);
422 utils::optional<int> insert_pos = lua_check<utils::optional<int>>(L, 3);
426 int realpos = check_index(L, 2, *twn,
true, insert_pos);
427 res = &twn->add_child(node_type,
data, realpos);
429 int realpos = check_index(L, 2, *tw,
true, insert_pos);
430 res = &tw->get_root_node().add_child(node_type,
data, realpos);
432 int realpos = check_index(L, 2, *
mp,
true, insert_pos);
433 res = &
mp->add_page(node_type, realpos,
data);
435 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
452 utils::optional<int> insert_pos = lua_check<utils::optional<int>>(L, 2);
458 int realpos = check_index(L, 2, *lb,
true, insert_pos);
459 res = &lb->add_row(
data, realpos);
461 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
479 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
485 auto& lk = lua_kernel_base::get_lua_kernel<lua_kernel_base>(L);
486 lk.add_log(
"Adding widgets module...\n");
487 static luaL_Reg
const gui_callbacks[] = {
500 {
nullptr,
nullptr },
503 luaL_setfuncs(L, gui_callbacks, 0);
This file contains the canvas object which is the part where the widgets draw (temporally) images on.
A config object defines a single node in a WML file, with access to child nodes.
Small abstract helper class.
Small abstract helper class.
tree_view & get_tree_view()
tree_view_node & get_child_at(int index)
widget * find(const std::string_view id, const bool must_be_active) override
See widget::find.
std::size_t count_children() const
The number of children in this widget.
std::pair< std::shared_ptr< tree_view_node >, int > remove_node(tree_view_node *node)
Removes the given node as a child of its parent node.
base class of top level items, the only item which needs to store the final canvases to draw on.
void keyboard_capture(widget *widget)
void close()
Requests to close the window.
Tmust inherit enable_lua_ptr<T>
Definitions for the interface to Wesnoth Markup Language (WML).
Standard logging facilities (interface).
config luaW_checkconfig(lua_State *L, int index)
Converts an optional table or vconfig to a config object.
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
void remove_from_window_stack(window *window)
Removes a entry from the open_window_stack list.
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
std::vector< window * > open_window_stack
Keeps track of any open windows of any type (modal, non-modal, or tooltip) in the order in which they...
Main entry points of multiplayer mode.
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
void lua_push(lua_State *L, const T &val)
#define ON_SCOPE_EXIT(...)
Run some arbitrary code (a lambda) when the current scope exits The lambda body follows this header,...
static map_location::direction n