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