49 #include <type_traits>
57 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
73 if(!lua_isnoneornil(L, 2)) {
87 if (!lua_isnoneornil(L, 3)) {
93 lua_pushinteger(L, v);
101 for(; !lua_isnoneornil(L,
i); ++
i)
105 int v = lua_tointeger(L,
i);
107 throw std::invalid_argument(
"negative index");
109 int n = list->get_item_count();
112 throw std::invalid_argument(
"index out of range");
116 list->add_row(dummy);
119 w = list->get_row_grid(v - 1);
121 int v = lua_tointeger(L,
i);
123 throw std::invalid_argument(
"negative index");
125 int n = multi_page->get_page_count();
128 throw std::invalid_argument(
"index out of range");
132 multi_page->add_page(dummy);
135 w = &multi_page->page_grid(v - 1);
138 if(lua_isnumber(L,
i)) {
139 int v = lua_tointeger(L,
i);
141 throw std::invalid_argument(
"negative index");
145 throw std::invalid_argument(
"index out of range");
150 std::string m = luaL_checkstring(L,
i);
151 w = tvn.
find(m,
false);
154 if(lua_isnumber(L,
i)) {
155 int v = lua_tointeger(L,
i);
157 throw std::invalid_argument(
"negative index");
159 int n = tree_view_node->count_children();
161 throw std::invalid_argument(
"index out of range");
163 w = &tree_view_node->get_child_at(v - 1);
166 std::string m = luaL_checkstring(L,
i);
167 w = tree_view_node->find(m,
false);
170 if(lua_isnumber(L,
i)) {
171 int v = lua_tointeger(L,
i);
173 throw std::invalid_argument(
"negative index");
175 int n = stacked_widget->get_layer_count();
177 throw std::invalid_argument(
"index out of range");
179 w = stacked_widget->get_layer_grid(v - 1);
181 std::string m = luaL_checkstring(L,
i);
182 w = stacked_widget->find(m,
false);
185 char const *m = lua_tostring(L,
i);
187 throw std::invalid_argument(
"expected a string");
189 w =
w->find(m,
false);
192 throw std::invalid_argument(
"widget not found");
223 for(
int i = 0;
i < number; ++
i) {
238 int pos = luaL_checkinteger(L, 2) - 1;
239 int number = luaL_checkinteger(L, 3);
243 list->remove_row(pos, number);
245 multi_page->remove_page(pos, number);
247 remove_treeview_node(tree_view->get_root_node(), pos, number);
249 remove_treeview_node(*tree_view_node, pos, number);
251 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
262 ERR_LUA <<
"widget was deleted";
267 ERR_LUA <<
"cannot find window in widget callback";
286 throw std::invalid_argument(
"the widget has no window assigned");
299 c->connect_click_handler(std::bind(&dialog_callback, L, wp,
"callback"));
309 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
325 int i = luaL_checkinteger(L, 2);
328 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
331 std::vector<gui2::canvas> &cv =
c->get_canvases();
332 if(
i < 1 ||
static_cast<unsigned>(
i) > cv.size()) {
333 return luaL_argerror(L, 2,
"out of bounds");
337 cv[
i - 1].set_cfg(cfg);
366 const std::string node_type = luaL_checkstring(L, 2);
368 if(lua_isnumber(L, 3)) {
369 insert_pos = luaL_checkinteger(L, 3);
374 res = &twn->add_child(node_type,
data, insert_pos);
376 res = &tw->get_root_node().add_child(node_type,
data, insert_pos);
378 res = &
mp->add_page(node_type, insert_pos,
data);
380 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
401 res = &lb->add_row(
data);
403 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
420 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
426 auto& lk = lua_kernel_base::get_lua_kernel<lua_kernel_base>(L);
427 lk.add_log(
"Adding widgets module...\n");
428 static luaL_Reg
const gui_callbacks[] = {
440 {
nullptr,
nullptr },
443 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.
A multi page is a control that contains several 'pages' of which only one is visible.
Small abstract helper class.
tree_view & get_tree_view()
tree_view_node & get_child_at(int index)
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
std::size_t count_children() const
The number of children in this widget.
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.
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>
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...
std::unique_ptr< window > build(const builder_window::window_resolution &definition)
Builds a window.
Main entry points of multiplayer mode.
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