parent
43ac6ca037
commit
118d18ec7a
6 changed files with 41 additions and 9 deletions
|
@ -41,15 +41,9 @@
|
|||
{ \
|
||||
register_helper() \
|
||||
{ \
|
||||
register_widget(#id, \
|
||||
[](const config& cfg) { return std::make_shared<type>(cfg); }, \
|
||||
key); \
|
||||
register_widget(#id, [](const config& cfg) { return std::make_shared<type>(cfg); }, key); \
|
||||
\
|
||||
register_builder_widget( \
|
||||
#id, \
|
||||
std::bind( \
|
||||
build_widget<implementation::builder_##id>, \
|
||||
_1)); \
|
||||
register_builder_widget(#id, &build_widget<implementation::builder_##id>); \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
|
|
|
@ -478,7 +478,7 @@ static std::map<std::string, gui_definition> guis;
|
|||
static std::map<std::string, gui_definition>::const_iterator current_gui = guis.end();
|
||||
|
||||
/** Points to the default gui. */
|
||||
static std::map<std::string, gui_definition>::const_iterator default_gui = guis.end();
|
||||
static std::map<std::string, gui_definition>::iterator default_gui = guis.end();
|
||||
|
||||
void register_window(const std::string& id)
|
||||
{
|
||||
|
@ -704,4 +704,21 @@ get_window_builder(const std::string& type)
|
|||
*
|
||||
*/
|
||||
|
||||
bool add_single_widget_definition(const std::string& widget_type, const std::string& definition_id, const config& cfg)
|
||||
{
|
||||
auto& gui = default_gui->second;
|
||||
auto parser = registred_widget_type().find(widget_type);
|
||||
|
||||
if (parser == registred_widget_type().end()) {
|
||||
throw std::invalid_argument("widget '" + widget_type + "' doesn't exist");
|
||||
}
|
||||
|
||||
if (gui.control_definition[widget_type].find(definition_id) != gui.control_definition[widget_type].end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
gui.control_definition[widget_type].insert(std::make_pair(definition_id, parser->second.parser(cfg)));
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -103,6 +103,8 @@ void load_widget_definitions(
|
|||
resolution_definition_ptr get_control(const std::string& control_type,
|
||||
const std::string& definition);
|
||||
|
||||
bool add_single_widget_definition(const std::string& widget_type, const std::string& definition_id, const config& cfg);
|
||||
|
||||
/** Helper struct to signal that get_window_builder failed. */
|
||||
struct window_builder_invalid_id
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "gui/widgets/multi_page.hpp" // for tmulti_page
|
||||
#include "gui/widgets/progress_bar.hpp" // for tprogress_bar
|
||||
#include "gui/widgets/selectable_item.hpp" // for tselectable_item
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/slider.hpp" // for tslider
|
||||
#include "gui/widgets/stacked_widget.hpp"
|
||||
#include "gui/widgets/text_box.hpp" // for ttext_box
|
||||
|
@ -842,4 +843,20 @@ int intf_add_dialog_tree_node(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* - Arg 1: string, widget type
|
||||
* - Arg 3: string, id
|
||||
* - Arg 3: conifg,
|
||||
*/
|
||||
|
||||
int intf_add_widget_definition(lua_State *L)
|
||||
{
|
||||
try {
|
||||
gui2::add_single_widget_definition(luaL_checkstring(L, 1), luaL_checkstring(L, 2), luaW_checkconfig(L, 3));
|
||||
}
|
||||
catch (const std::invalid_argument& e) {
|
||||
return luaL_argerror(L, 1, e.what());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} // end namespace lua_gui2
|
||||
|
|
|
@ -33,6 +33,7 @@ int intf_set_dialog_focus(lua_State *L);
|
|||
int intf_set_dialog_active(lua_State *L);
|
||||
int intf_set_dialog_visible(lua_State *L);
|
||||
int intf_add_dialog_tree_node(lua_State *L);
|
||||
int intf_add_widget_definition(lua_State *L);
|
||||
int show_dialog(lua_State *L, CVideo & video);
|
||||
int show_message_dialog(lua_State *L, CVideo & video);
|
||||
int show_popup_dialog(lua_State *L, CVideo & video);
|
||||
|
|
|
@ -355,6 +355,7 @@ lua_kernel_base::lua_kernel_base()
|
|||
{ "set_dialog_active", &lua_gui2::intf_set_dialog_active },
|
||||
{ "set_dialog_visible", &lua_gui2::intf_set_dialog_visible },
|
||||
{ "add_dialog_tree_node", &lua_gui2::intf_add_dialog_tree_node },
|
||||
{ "add_widget_definition", &lua_gui2::intf_add_widget_definition },
|
||||
{ "set_dialog_callback", &lua_gui2::intf_set_dialog_callback },
|
||||
{ "set_dialog_canvas", &lua_gui2::intf_set_dialog_canvas },
|
||||
{ "set_dialog_focus", &lua_gui2::intf_set_dialog_focus },
|
||||
|
|
Loading…
Add table
Reference in a new issue