Don't use optional_child for widget state definitions when it's mandatory (#7600)

This commit is contained in:
Celtic Minstrel 2023-05-06 19:54:28 -04:00 committed by GitHub
parent 8dea67d323
commit f5be4cffb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 96 additions and 85 deletions

View File

@ -25,11 +25,9 @@
namespace gui2
{
state_definition::state_definition(optional_const_config cfg)
: canvas_cfg_(cfg ? cfg->child_or_empty("draw") : config())
{
VALIDATE(cfg && cfg->has_child("draw"), _("No state or draw section defined."));
}
state_definition::state_definition(const config& cfg)
: canvas_cfg_(VALIDATE_WML_CHILD(cfg, "draw", _("No draw section defined for state.")))
{}
resolution_definition::resolution_definition(const config& cfg)
: window_width(cfg["window_width"])

View File

@ -35,7 +35,7 @@ namespace gui2
*/
struct state_definition
{
explicit state_definition(optional_const_config cfg);
explicit state_definition(const config& cfg);
config canvas_cfg_;
};

View File

@ -26,6 +26,8 @@
#include "gui/core/register_widget.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "wml_exception.hpp"
#include "gettext.hpp"
#include "sound.hpp"
@ -159,10 +161,10 @@ button_definition::resolution::resolution(const config& cfg)
: resolution_definition(cfg)
{
// Note the order should be the same as the enum state_t in button.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(cfg.optional_child("state_disabled"));
state.emplace_back(cfg.optional_child("state_pressed"));
state.emplace_back(cfg.optional_child("state_focused"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for button")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for button")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_pressed", _("Missing required state for button")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for button")));
}
// }---------- BUILDER -----------{

View File

@ -38,6 +38,7 @@
#include "preferences/game.hpp"
#include "preferences/lobby.hpp"
#include "scripting/plugins/manager.hpp"
#include "wml_exception.hpp"
static lg::log_domain log_lobby("lobby");
#define DBG_LB LOG_STREAM(debug, log_lobby)
@ -653,13 +654,11 @@ chatbox_definition::chatbox_definition(const config& cfg)
chatbox_definition::resolution::resolution(const config& cfg)
: resolution_definition(cfg), grid()
{
state.emplace_back(cfg.optional_child("background"));
state.emplace_back(cfg.optional_child("foreground"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "background", _("Missing required background for chatbox")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "foreground", _("Missing required foreground for chatbox")));
auto child = cfg.optional_child("grid");
VALIDATE(child, _("No grid defined."));
grid = std::make_shared<builder_grid>(*child);
auto child = VALIDATE_WML_CHILD(cfg, "grid", _("Missing required grid for chatbox"));
grid = std::make_shared<builder_grid>(child);
}
// }---------- BUILDER -----------{

View File

@ -24,6 +24,7 @@
#include "gui/widgets/settings.hpp"
#include "wml_exception.hpp"
#include "gettext.hpp"
#include <functional>
@ -129,10 +130,10 @@ horizontal_scrollbar_definition::resolution::resolution(const config& cfg)
"minimum_positioner_length"));
// Note the order should be the same as the enum state_t is scrollbar.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(cfg.optional_child("state_disabled"));
state.emplace_back(cfg.optional_child("state_pressed"));
state.emplace_back(cfg.optional_child("state_focused"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for horizontal scrollbar")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for horizontal scrollbar")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_pressed", _("Missing required state for horizontal scrollbar")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for horizontal scrollbar")));
}
// }---------- BUILDER -----------{

View File

@ -24,6 +24,8 @@
#include "gui/core/log.hpp"
#include "gui/core/register_widget.hpp"
#include "gui/widgets/settings.hpp"
#include "wml_exception.hpp"
#include "gettext.hpp"
#include <functional>
@ -110,7 +112,7 @@ image_definition::resolution::resolution(const config& cfg)
: resolution_definition(cfg)
{
// Note the order should be the same as the enum state_t in image.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for image control")));
}
// }---------- BUILDER -----------{

View File

@ -30,6 +30,7 @@
#include "desktop/clipboard.hpp"
#include "desktop/open.hpp"
#include "gettext.hpp"
#include "wml_exception.hpp"
#include <functional>
#include <string>
@ -237,8 +238,8 @@ label_definition::resolution::resolution(const config& cfg)
, link_color(cfg["link_color"].empty() ? color_t::from_hex_string("ffff00") : color_t::from_rgba_string(cfg["link_color"].str()))
{
// Note the order should be the same as the enum state_t is label.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(cfg.optional_child("state_disabled"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for text label control")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for text label control")));
}
// }---------- BUILDER -----------{

View File

@ -32,6 +32,7 @@
#include "gui/widgets/widget_helpers.hpp"
#include "gui/widgets/window.hpp"
#include "sdl/rect.hpp"
#include "wml_exception.hpp"
#include <functional>
#include <optional>
@ -706,11 +707,10 @@ listbox_definition::resolution::resolution(const config& cfg)
, grid(nullptr)
{
// Note the order should be the same as the enum state_t in listbox.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(cfg.optional_child("state_disabled"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for listbox")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for listbox")));
auto child = VALIDATE_WML_CHILD(cfg, "grid", _("No grid defined."));
grid = std::make_shared<builder_grid>(child);
}

View File

@ -188,8 +188,8 @@ matrix_definition::resolution::resolution(const config& cfg)
, content(new builder_grid(VALIDATE_WML_CHILD(cfg, "content", _("Missing [content] in [matrix_definition]"))))
{
// Note the order should be the same as the enum state_t in matrix.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(cfg.optional_child("state_disabled"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for matrix definition")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for matrix definition")));
}
// }---------- BUILDER -----------{

View File

@ -25,6 +25,8 @@
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "sound.hpp"
#include "wml_exception.hpp"
#include "gettext.hpp"
#include <functional>
@ -229,10 +231,10 @@ menu_button_definition::resolution::resolution(const config& cfg)
: resolution_definition(cfg)
{
// Note the order should be the same as the enum state_t in menu_button.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(cfg.optional_child("state_disabled"));
state.emplace_back(cfg.optional_child("state_pressed"));
state.emplace_back(cfg.optional_child("state_focused"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for menu button")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for menu button")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_pressed", _("Missing required state for menu button")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for menu button")));
}
// }---------- BUILDER -----------{

View File

@ -26,6 +26,8 @@
#include "map/map.hpp"
#include "map/exception.hpp"
#include "sdl/rect.hpp"
#include "wml_exception.hpp"
#include "gettext.hpp"
#include "../../minimap.hpp" // We want the file in src/
#include <functional>
@ -112,7 +114,7 @@ minimap_definition::resolution::resolution(const config& cfg)
: resolution_definition(cfg)
{
// Note the order should be the same as the enum state_t in minimap.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for minimap control")));
}
// }---------- BUILDER -----------{

View File

@ -29,6 +29,7 @@
#include "formula/string_utils.hpp"
#include <functional>
#include "gettext.hpp"
#include "wml_exception.hpp"
#define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
#define LOG_HEADER LOG_SCOPE_HEADER + ':'
@ -252,10 +253,10 @@ multimenu_button_definition::resolution::resolution(const config& cfg)
: resolution_definition(cfg)
{
// Note the order should be the same as the enum state_t in multimenu_button.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(cfg.optional_child("state_disabled"));
state.emplace_back(cfg.optional_child("state_pressed"));
state.emplace_back(cfg.optional_child("state_focused"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for multimenu button")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for multimenu button")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_pressed", _("Missing required state for multimenu button")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for multimenu button")));
}
// }---------- BUILDER -----------{

View File

@ -108,8 +108,8 @@ panel_definition::resolution::resolution(const config& cfg)
, right_border(cfg["right_border"])
{
// The panel needs to know the order.
state.emplace_back(cfg.optional_child("background"));
state.emplace_back(cfg.optional_child("foreground"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "background", _("Missing required background for panel definition")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "foreground", _("Missing required foreground for panel definition")));
}
// }---------- BUILDER -----------{

View File

@ -20,6 +20,8 @@
#include "gui/core/log.hpp"
#include "gui/core/register_widget.hpp"
#include "gui/widgets/settings.hpp"
#include "wml_exception.hpp"
#include "gettext.hpp"
#include <functional>
@ -91,7 +93,7 @@ progress_bar_definition::resolution::resolution(const config& cfg)
: resolution_definition(cfg)
{
// Note the order should be the same as the enum state_t in progress_bar.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for progress bar")));
}
// }---------- BUILDER -----------{

View File

@ -23,6 +23,8 @@
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "sound.hpp"
#include "wml_exception.hpp"
#include "gettext.hpp"
#include <functional>
@ -179,10 +181,10 @@ repeating_button_definition::resolution::resolution(const config& cfg)
{
// Note the order should be the same as the enum state_t in
// repeating_button.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(cfg.optional_child("state_disabled"));
state.emplace_back(cfg.optional_child("state_pressed"));
state.emplace_back(cfg.optional_child("state_focused"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for repeating button")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for repeating button")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_pressed", _("Missing required state for repeating button")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for repeating button")));
}
// }---------- BUILDER -----------{

View File

@ -27,6 +27,7 @@
#include "gui/widgets/spacer.hpp"
#include "gui/widgets/window.hpp"
#include "gettext.hpp"
#include "wml_exception.hpp"
#include <functional>
@ -176,13 +177,11 @@ scroll_label_definition::resolution::resolution(const config& cfg)
: resolution_definition(cfg), grid(nullptr)
{
// Note the order should be the same as the enum state_t is scroll_label.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(cfg.optional_child("state_disabled"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for scroll label control")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for scroll label control")));
auto child = cfg.optional_child("grid");
VALIDATE(child, _("No grid defined."));
grid = std::make_shared<builder_grid>(*child);
auto child = VALIDATE_WML_CHILD(cfg, "grid", _("No grid defined for scroll label control"));
grid = std::make_shared<builder_grid>(child);
}
// }---------- BUILDER -----------{

View File

@ -67,13 +67,11 @@ scrollbar_panel_definition::resolution::resolution(const config& cfg)
: resolution_definition(cfg), grid()
{
// The panel needs to know the order.
state.emplace_back(cfg.optional_child("background"));
state.emplace_back(cfg.optional_child("foreground"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "background", _("Missing required background for scrollbar panel")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "foreground", _("Missing required foreground for scrollbar panel")));
auto child = cfg.optional_child("grid");
VALIDATE(child, _("No grid defined."));
grid = std::make_shared<builder_grid>(*child);
auto child = VALIDATE_WML_CHILD(cfg, "grid", _("Missing required grid for scrollbar panel"));
grid = std::make_shared<builder_grid>(child);
}
// }---------- BUILDER -----------{

View File

@ -310,10 +310,10 @@ slider_definition::resolution::resolution(const config& cfg)
VALIDATE(positioner_length, missing_mandatory_wml_key("resolution", "minimum_positioner_length"));
// Note the order should be the same as the enum state_t is slider.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(cfg.optional_child("state_disabled"));
state.emplace_back(cfg.optional_child("state_pressed"));
state.emplace_back(cfg.optional_child("state_focused"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for slider")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for slider")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_pressed", _("Missing required state for slider")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for slider")));
}
// }---------- BUILDER -----------{

View File

@ -24,6 +24,8 @@
#include "preferences/game.hpp"
#include "serialization/unicode.hpp"
#include <functional>
#include "wml_exception.hpp"
#include "gettext.hpp"
#define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
#define LOG_HEADER LOG_SCOPE_HEADER + ':'
@ -406,10 +408,10 @@ text_box_definition::resolution::resolution(const config& cfg)
, text_y_offset(cfg["text_y_offset"])
{
// Note the order should be the same as the enum state_t in text_box.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(cfg.optional_child("state_disabled"));
state.emplace_back(cfg.optional_child("state_focused"));
state.emplace_back(cfg.optional_child("state_hovered"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for editable text box")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for editable text box")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for editable text box")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_hovered", _("Missing required state for editable text box")));
}
// }---------- BUILDER -----------{

View File

@ -23,6 +23,8 @@
#include "gui/core/log.hpp"
#include "gui/core/window_builder/helper.hpp"
#include "sound.hpp"
#include "wml_exception.hpp"
#include "gettext.hpp"
#include <functional>
@ -209,9 +211,9 @@ toggle_button_definition::resolution::resolution(const config& cfg)
// toggle_button.hpp.
for(const auto& c : cfg.child_range("state"))
{
state.emplace_back(c.optional_child("enabled"));
state.emplace_back(c.optional_child("disabled"));
state.emplace_back(c.optional_child("focused"));
state.emplace_back(VALIDATE_WML_CHILD(c, "enabled", _("Missing required state for toggle button")));
state.emplace_back(VALIDATE_WML_CHILD(c, "disabled", _("Missing required state for toggle button")));
state.emplace_back(VALIDATE_WML_CHILD(c, "focused", _("Missing required state for toggle button")));
}
}

View File

@ -299,9 +299,9 @@ toggle_panel_definition::resolution::resolution(const config& cfg)
// Note the order should be the same as the enum state_t in toggle_panel.hpp.
for(const auto& c : cfg.child_range("state"))
{
state.emplace_back(c.optional_child("enabled"));
state.emplace_back(c.optional_child("disabled"));
state.emplace_back(c.optional_child("focused"));
state.emplace_back(VALIDATE_WML_CHILD(c, "enabled", _("Missing required state for toggle panel")));
state.emplace_back(VALIDATE_WML_CHILD(c, "disabled", _("Missing required state for toggle panel")));
state.emplace_back(VALIDATE_WML_CHILD(c, "focused", _("Missing required state for toggle panel")));
}
}

View File

@ -265,13 +265,12 @@ tree_view_definition::resolution::resolution(const config& cfg)
, grid(nullptr)
{
// Note the order should be the same as the enum state_t is listbox.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(cfg.optional_child("state_disabled"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for tree view")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for tree view")));
auto child = cfg.optional_child("grid");
VALIDATE(child, _("No grid defined."));
auto child = VALIDATE_WML_CHILD(cfg, "grid", _("No grid defined for tree view"));
grid = std::make_shared<builder_grid>(*child);
grid = std::make_shared<builder_grid>(child);
}
// }---------- BUILDER -----------{

View File

@ -608,13 +608,11 @@ unit_preview_pane_definition::unit_preview_pane_definition(const config& cfg)
unit_preview_pane_definition::resolution::resolution(const config& cfg)
: resolution_definition(cfg), grid()
{
state.emplace_back(cfg.optional_child("background"));
state.emplace_back(cfg.optional_child("foreground"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "background", _("Missing required background for unit preview pane")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "foreground", _("Missing required foreground for unit preview pane")));
auto child = cfg.optional_child("grid");
VALIDATE(child, _("No grid defined."));
grid = std::make_shared<builder_grid>(*child);
auto child = VALIDATE_WML_CHILD(cfg, "grid", _("Missing required grid for unit preview pane"));
grid = std::make_shared<builder_grid>(child);
}
// }---------- BUILDER -----------{

View File

@ -19,6 +19,7 @@
#include "gui/core/register_widget.hpp"
#include "gui/widgets/settings.hpp"
#include "wml_exception.hpp"
#include "gettext.hpp"
#include <functional>
@ -119,10 +120,10 @@ vertical_scrollbar_definition::resolution::resolution(const config& cfg)
"minimum_positioner_length"));
// Note the order should be the same as the enum state_t in scrollbar.hpp.
state.emplace_back(cfg.optional_child("state_enabled"));
state.emplace_back(cfg.optional_child("state_disabled"));
state.emplace_back(cfg.optional_child("state_pressed"));
state.emplace_back(cfg.optional_child("state_focused"));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for vertical scrollbar")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for vertical scrollbar")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_pressed", _("Missing required state for vertical scrollbar")));
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for vertical scrollbar")));
}
// }---------- BUILDER -----------{