GUI2: remove standalone window build functions

The only place that used these was the lua show_dialog implementation. We can just construct the window object directly instead. Since this skips out on the finalize_build step (which in the case of modal/modeless_dialog was being called by those respective ctors), I've removed that function and merged it into the window ctor. No need to do it separately.

Builds on work in af81bba53b and 247e5ff055
This commit is contained in:
Charles Dang 2024-10-14 01:44:52 -04:00
parent 0eb8dc4540
commit a96ce07e35
7 changed files with 22 additions and 65 deletions

View file

@ -33,25 +33,6 @@
namespace gui2
{
std::unique_ptr<window> build(const builder_window::window_resolution& definition)
{
// We set the values from the definition since we can only determine the
// best size (if needed) after all widgets have been placed.
auto win = std::make_unique<window>(definition);
assert(win);
win->finish_build(definition);
return win;
}
std::unique_ptr<window> build(const std::string& type)
{
const builder_window::window_resolution& definition = get_window_builder(type);
auto window = build(definition);
window->set_id(type);
return window;
}
builder_widget::builder_widget(const config& cfg)
: id(cfg["id"])
, linked_group(cfg["linked_group"])

View file

@ -218,17 +218,4 @@ private:
std::string description_;
};
/**
* Builds a window.
*
* @param type The type id string of the window, this window
* must be registered at startup.
*/
std::unique_ptr<window> build(const std::string& type);
/**
* Builds a window.
*/
std::unique_ptr<window> build(const builder_window::window_resolution& res);
} // namespace gui2

View file

@ -42,7 +42,6 @@ modal_dialog::modal_dialog(const std::string& window_id)
, allow_plugin_skip_(true)
, show_even_without_video_(false)
{
window::finish_build(get_window_builder(window_id));
widget::set_id(window_id);
}

View file

@ -26,7 +26,6 @@ namespace gui2::dialogs
modeless_dialog::modeless_dialog(const std::string& window_id)
: window(get_window_builder(window_id))
{
window::finish_build(get_window_builder(window_id));
widget::set_id(window_id);
}

View file

@ -273,7 +273,7 @@ window::window(const builder_window::window_resolution& definition)
, functions_(definition.functions)
, tooltip_(definition.tooltip)
, helptip_(definition.helptip)
, click_dismiss_(false)
, click_dismiss_(definition.click_dismiss)
, enter_disabled_(false)
, escape_disabled_(false)
, linked_size_()
@ -288,6 +288,26 @@ window::window(const builder_window::window_resolution& definition)
connect();
for(const auto& lg : definition.linked_groups) {
if(has_linked_size_group(lg.id)) {
FAIL(VGETTEXT("Linked $id group has multiple definitions.", {{"id", lg.id}}));
}
init_linked_size_group(lg.id, lg.fixed_width, lg.fixed_height);
}
const auto conf = cast_config_to<window_definition>();
assert(conf);
if(conf->grid) {
init_grid(*conf->grid);
finalize(*definition.grid);
} else {
init_grid(*definition.grid);
}
add_to_keyboard_chain(this);
connect_signal<event::SDL_VIDEO_RESIZE>(std::bind(
&window::signal_handler_sdl_video_resize, this, std::placeholders::_2, std::placeholders::_3, std::placeholders::_5));
@ -415,33 +435,6 @@ retval window::get_retval_by_id(const std::string& id)
}
}
void window::finish_build(const builder_window::window_resolution& definition)
{
for(const auto& lg : definition.linked_groups) {
if(has_linked_size_group(lg.id)) {
t_string msg = VGETTEXT("Linked $id group has multiple definitions.", {{"id", lg.id}});
FAIL(msg);
}
init_linked_size_group(lg.id, lg.fixed_width, lg.fixed_height);
}
set_click_dismiss(definition.click_dismiss);
const auto conf = cast_config_to<window_definition>();
assert(conf);
if(conf->grid) {
init_grid(*conf->grid);
finalize(*definition.grid);
} else {
init_grid(*definition.grid);
}
add_to_keyboard_chain(this);
}
void window::show_tooltip(/*const unsigned auto_close_timeout*/)
{
// Unhide in any case.

View file

@ -82,8 +82,6 @@ public:
/** Gets the retval for the default buttons. */
static retval get_retval_by_id(const std::string& id);
void finish_build(const builder_window::window_resolution&);
/**
* Shows the window, running an event loop until it should close.
*

View file

@ -56,7 +56,7 @@ int intf_show_dialog(lua_State* L)
config def_cfg = luaW_checkconfig(L, 1);
gui2::builder_window::window_resolution def(def_cfg);
std::unique_ptr<gui2::window> wp(gui2::build(def));
auto wp = std::make_unique<gui2::window>(def);
if(!lua_isnoneornil(L, 2)) {
lua_pushvalue(L, 2);