mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-03 08:43:48 +00:00
ttext_box: added support for defining a maximum input length
This commit is contained in:
parent
3baba9235e
commit
fb0285c27f
@ -1801,6 +1801,11 @@
|
|||||||
type="string"
|
type="string"
|
||||||
default=""
|
default=""
|
||||||
[/key]
|
[/key]
|
||||||
|
[key]
|
||||||
|
name="max_input_length"
|
||||||
|
type="int"
|
||||||
|
default=0
|
||||||
|
[/key]
|
||||||
[key]
|
[key]
|
||||||
name="label"
|
name="label"
|
||||||
type="t_string"
|
type="t_string"
|
||||||
|
@ -27,7 +27,9 @@ namespace implementation
|
|||||||
{
|
{
|
||||||
|
|
||||||
tbuilder_text_box::tbuilder_text_box(const config& cfg)
|
tbuilder_text_box::tbuilder_text_box(const config& cfg)
|
||||||
: tbuilder_control(cfg), history(cfg["history"])
|
: tbuilder_control(cfg)
|
||||||
|
, history(cfg["history"])
|
||||||
|
, max_input_length(cfg["max_input_length"])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +46,8 @@ twidget* tbuilder_text_box::build() const
|
|||||||
widget->set_history(history);
|
widget->set_history(history);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
widget->set_max_input_length(max_input_length);
|
||||||
|
|
||||||
DBG_GUI_G << "Window builder: placed text box '" << id
|
DBG_GUI_G << "Window builder: placed text box '" << id
|
||||||
<< "' with definition '" << definition << "'.\n";
|
<< "' with definition '" << definition << "'.\n";
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ public:
|
|||||||
twidget* build() const;
|
twidget* build() const;
|
||||||
|
|
||||||
std::string history;
|
std::string history;
|
||||||
|
|
||||||
|
size_t max_input_length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,6 +99,7 @@ std::string ttext_history::get_value() const
|
|||||||
ttext_box::ttext_box()
|
ttext_box::ttext_box()
|
||||||
: ttext_()
|
: ttext_()
|
||||||
, history_()
|
, history_()
|
||||||
|
, max_input_length_(0)
|
||||||
, text_x_offset_(0)
|
, text_x_offset_(0)
|
||||||
, text_y_offset_(0)
|
, text_y_offset_(0)
|
||||||
, text_height_(0)
|
, text_height_(0)
|
||||||
@ -124,6 +125,10 @@ void ttext_box::place(const tpoint& origin, const tpoint& size)
|
|||||||
set_maximum_width(get_text_maximum_width());
|
set_maximum_width(get_text_maximum_width());
|
||||||
set_maximum_height(get_text_maximum_height(), false);
|
set_maximum_height(get_text_maximum_height(), false);
|
||||||
|
|
||||||
|
if(max_input_length_ != 0) {
|
||||||
|
set_maximum_length(max_input_length_);
|
||||||
|
}
|
||||||
|
|
||||||
update_offsets();
|
update_offsets();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +140,9 @@ void ttext_box::update_canvas()
|
|||||||
const unsigned start = get_selection_start();
|
const unsigned start = get_selection_start();
|
||||||
const int length = get_selection_length();
|
const int length = get_selection_length();
|
||||||
|
|
||||||
|
if(max_input_length_ != 0) {
|
||||||
|
set_maximum_length(max_input_length_);
|
||||||
|
}
|
||||||
|
|
||||||
PangoEllipsizeMode ellipse_mode = PANGO_ELLIPSIZE_NONE;
|
PangoEllipsizeMode ellipse_mode = PANGO_ELLIPSIZE_NONE;
|
||||||
if(!can_wrap()) {
|
if(!can_wrap()) {
|
||||||
|
@ -131,6 +131,11 @@ public:
|
|||||||
history_ = ttext_history::get_history(id, true);
|
history_ = ttext_history::get_history(id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_max_input_length(const size_t length)
|
||||||
|
{
|
||||||
|
max_input_length_ = length;
|
||||||
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
set_value("");
|
set_value("");
|
||||||
@ -171,6 +176,9 @@ private:
|
|||||||
/** The history text for this widget. */
|
/** The history text for this widget. */
|
||||||
ttext_history history_;
|
ttext_history history_;
|
||||||
|
|
||||||
|
/** The maximum length of the text input. */
|
||||||
|
size_t max_input_length_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x offset in the widget where the text starts.
|
* The x offset in the widget where the text starts.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user