48 #include <type_traits> 56 #define ERR_LUA LOG_STREAM(err, log_scripting_lua) 72 if(!lua_isnoneornil(L, 2)) {
82 if (!lua_isnoneornil(L, 3)) {
88 lua_pushinteger(L, v);
96 for(; !lua_isnoneornil(L, i); ++
i)
100 int v = lua_tointeger(L, i);
102 throw std::invalid_argument(
"negative index");
104 int n = list->get_item_count();
107 throw std::invalid_argument(
"index out of range");
111 list->add_row(dummy);
114 w = list->get_row_grid(v - 1);
115 }
else if(
gui2::multi_page* multi_page = dynamic_cast<gui2::multi_page*>(w)) {
116 int v = lua_tointeger(L, i);
118 throw std::invalid_argument(
"negative index");
120 int n = multi_page->get_page_count();
123 throw std::invalid_argument(
"index out of range");
127 multi_page->add_page(dummy);
130 w = &multi_page->page_grid(v - 1);
131 }
else if(
gui2::tree_view* tree_view = dynamic_cast<gui2::tree_view*>(w)) {
133 if(lua_isnumber(L, i)) {
134 int v = lua_tointeger(L, i);
136 throw std::invalid_argument(
"negative index");
140 throw std::invalid_argument(
"index out of range");
145 std::string m = luaL_checkstring(L, i);
146 w = tvn.
find(m,
false);
149 if(lua_isnumber(L, i)) {
150 int v = lua_tointeger(L, i);
152 throw std::invalid_argument(
"negative index");
154 int n = tree_view_node->count_children();
156 throw std::invalid_argument(
"index out of range");
158 w = &tree_view_node->get_child_at(v - 1);
161 std::string m = luaL_checkstring(L, i);
162 w = tree_view_node->
find(m,
false);
165 if(lua_isnumber(L, i)) {
166 int v = lua_tointeger(L, i);
168 throw std::invalid_argument(
"negative index");
170 int n = stacked_widget->get_layer_count();
172 throw std::invalid_argument(
"index out of range");
174 w = stacked_widget->get_layer_grid(v - 1);
176 std::string m = luaL_checkstring(L, i);
177 w = stacked_widget->
find(m,
false);
180 char const *m = lua_tostring(L, i);
182 throw std::invalid_argument(
"expected a string");
184 w = w->
find(m,
false);
187 throw std::invalid_argument(
"widget not found");
218 for(
int i = 0;
i < number; ++
i) {
233 int pos = luaL_checkinteger(L, 2) - 1;
234 int number = luaL_checkinteger(L, 3);
238 list->remove_row(pos, number);
239 }
else if(
gui2::multi_page* multi_page = dynamic_cast<gui2::multi_page*>(w)) {
240 multi_page->remove_page(pos, number);
241 }
else if(
gui2::tree_view* tree_view = dynamic_cast<gui2::tree_view*>(w)) {
242 remove_treeview_node(tree_view->get_root_node(), pos, number);
244 remove_treeview_node(*tree_view_node, pos, number);
246 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
257 ERR_LUA <<
"widget was deleted";
262 ERR_LUA <<
"cannot find window in widget callback";
281 throw std::invalid_argument(
"the widget has no window assigned");
294 c->connect_click_handler(std::bind(&dialog_callback, L, wp,
"callback"));
295 }
else if( dynamic_cast<gui2::selectable_item*>(w)) {
297 }
else if(dynamic_cast<gui2::integer_selector*>(w)) {
299 }
else if(dynamic_cast<gui2::listbox*>(w)) {
301 }
else if(dynamic_cast<gui2::tree_view*>(w)) {
304 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
320 int i = luaL_checkinteger(L, 2);
323 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
327 if(i < 1 || static_cast<unsigned>(i) > cv.size()) {
328 return luaL_argerror(L, 2,
"out of bounds");
332 cv[i - 1].set_cfg(cfg);
345 wd->keyboard_capture(w);
361 const std::string node_type = luaL_checkstring(L, 2);
363 if(lua_isnumber(L, 3)) {
364 insert_pos = luaL_checkinteger(L, 3);
369 res = &twn->add_child(node_type, data, insert_pos);
371 res = &tw->get_root_node().add_child(node_type, data, insert_pos);
373 res = &
mp->add_page(node_type, insert_pos, data);
375 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
396 res = &lb->add_row(data);
398 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
415 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
421 auto& lk = lua_kernel_base::get_lua_kernel<lua_kernel_base>(L);
422 lk.add_log(
"Adding widgets module...\n");
423 static luaL_Reg
const gui_callbacks[] = {
435 {
nullptr,
nullptr },
438 luaL_setfuncs(L, gui_callbacks, 0);
Key Type Default Description window_width unsigned 0 Width of the application window.
Tmust inherit enable_lua_ptr<T>
void lua_push(lua_State *L, const T &val)
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
Definitions for the interface to Wesnoth Markup Language (WML).
std::size_t count_children() const
The number of children in this widget.
Main entry points of multiplayer mode.
std::map< std::string, t_string > widget_item
void remove_from_window_stack(window *window)
Removes a entry from the open_window_stack list.
This file contains the canvas object which is the part where the widgets draw (temporally) images on...
A tree view is a control that holds several items of the same or different types. ...
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.
int show(unsigned auto_close_timeout=0)
Shows the window, running an event loop until it should close.
tree_view_node & get_child_at(int index)
config luaW_checkconfig(lua_State *L, int index)
Converts an optional table or vconfig to a config object.
tree_view & get_tree_view()
A multi page is a control that contains several 'pages' of which only one is visible.
Standard logging facilities (interface).
std::map< std::string, widget_item > widget_data
std::unique_ptr< window > build(const builder_window::window_resolution &definition)
Builds a window.
A config object defines a single node in a WML file, with access to child nodes.
static map_location::DIRECTION n
base class of top level items, the only item which needs to store the final canvases to draw on...
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
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...