45 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
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");
211 for(
int i = 0;
i < number; ++
i) {
226 int pos = luaL_checkinteger(L, 2) - 1;
227 int number = luaL_checkinteger(L, 3);
231 list->remove_row(pos, number);
233 multi_page->remove_page(pos, number);
235 remove_treeview_node(tree_view->get_root_node(), pos, number);
237 remove_treeview_node(*tree_view_node, pos, number);
239 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
250 ERR_LUA <<
"widget was deleted";
255 ERR_LUA <<
"cannot find window in widget callback";
274 throw std::invalid_argument(
"the widget has no window assigned");
276 if(!lua_isfunction(L, 2)) {
277 return luaL_argerror(L, 2,
"callback must be a function");
290 c->connect_click_handler(std::bind(&dialog_callback, L, wp,
"callback"));
300 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
316 int i = luaL_checkinteger(L, 2);
319 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
322 std::vector<gui2::canvas> &cv =
c->get_canvases();
323 if(
i < 1 ||
static_cast<unsigned>(
i) > cv.size()) {
324 return luaL_argerror(L, 2,
"out of bounds");
328 cv[
i - 1].set_cfg(cfg);
357 const std::string node_type = luaL_checkstring(L, 2);
359 if(lua_isnumber(L, 3)) {
360 insert_pos = luaL_checkinteger(L, 3);
365 res = &twn->add_child(node_type,
data, insert_pos);
367 res = &tw->get_root_node().add_child(node_type,
data, insert_pos);
369 res = &
mp->add_page(node_type, insert_pos,
data);
371 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
392 res = &lb->add_row(
data);
394 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
411 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
417 auto& lk = lua_kernel_base::get_lua_kernel<lua_kernel_base>(L);
418 lk.add_log(
"Adding widgets module...\n");
419 static luaL_Reg
const gui_callbacks[] = {
431 {
nullptr,
nullptr },
434 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