The Battle for Wesnoth  1.19.0-dev
edit_text.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2024
3  by Iris Morelle <shadowm2006@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
19 
20 namespace gui2::dialogs
21 {
22 
23 /**
24  * @ingroup GUIWindowDefinitionWML
25  *
26  * Dialog for renaming units in-game.
27  * Key |Type |Mandatory|Description
28  * ------------------|--------------|---------|-----------
29  * name | text_box |yes |Input field for the unit name.
30  */
31 class edit_text : public modal_dialog
32 {
33 public:
34  /**
35  * Constructor.
36  *
37  * @param title The dialog's title.
38  * @param label Label of the text field.
39  * @param [in, out] text The parameter's usage is:
40  * - Input: The initial value of the text field.
41  * - Output: The new unit name the user entered
42  * if the dialog returns retval::OK,
43  * undefined otherwise.
44  * @param disallow_empty Whether to prevent the user from entering a string that is
45  * empty or consists only of whitespace.
46  */
47  edit_text(const std::string& title,
48  const std::string& label,
49  std::string& text,
50  bool disallow_empty = false);
51 
52  /**
53  * Executes the dialog.
54  * See @ref modal_dialog for more information.
55  *
56  * @param [in, out] text The parameter's usage is:
57  * - Input: The initial value of the unit name.
58  * - Output: The new unit name the user entered
59  * if this method returns @a true, undefined
60  * otherwise.
61  */
63 
64 private:
65  virtual const std::string& window_id() const override;
66 
67  virtual void pre_show(window& window) override;
68 
69  void on_text_change();
70 
72 };
73 } // namespace dialogs
Dialog for renaming units in-game.
Definition: edit_text.hpp:32
virtual const std::string & window_id() const override
Executes the dialog.
edit_text(const std::string &title, const std::string &label, std::string &text, bool disallow_empty=false)
Constructor.
Definition: edit_text.cpp:31
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: edit_text.cpp:43
Abstract base class for all modal dialogs.
A label displays text that can be wrapped but no scrollbars are provided.
Definition: label.hpp:56
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:63
#define DEFINE_SIMPLE_EXECUTE_WRAPPER(dialog)
Adds a bare-bonesstatic execute function to a dialog class that immediately invokes and return the re...