16 #define GETTEXT_DOMAIN "wesnoth-lib"
30 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
31 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
103 , max_input_length_(0)
111 connect_signal<event::MOUSE_MOTION>(std::bind(
113 connect_signal<event::LEFT_BUTTON_DOWN>(std::bind(
115 connect_signal<event::LEFT_BUTTON_UP>(std::bind(
117 connect_signal<event::LEFT_BUTTON_DOUBLE_CLICK>(std::bind(
120 const auto conf = cast_config_to<text_box_definition>();
156 PangoEllipsizeMode ellipse_mode = PANGO_ELLIPSIZE_NONE;
159 ellipse_mode = PANGO_ELLIPSIZE_START;
161 ellipse_mode = PANGO_ELLIPSIZE_END;
167 unsigned start_offset = 0;
168 unsigned end_offset = 0;
171 }
else if(length > 0) {
180 unsigned comp_start_offset = 0;
181 unsigned comp_end_offset = 0;
182 if(edit_length == 0) {
184 }
else if(edit_length > 0) {
203 tmp.set_variable(
"text_maximum_width",
wfl::variant(max_width));
204 tmp.set_variable(
"text_maximum_height",
wfl::variant(max_height));
208 tmp.set_variable(
"cursor_offset",
211 tmp.set_variable(
"selection_offset",
wfl::variant(start_offset));
212 tmp.set_variable(
"selection_width",
wfl::variant(end_offset - start_offset));
213 tmp.set_variable(
"text_wrap_mode",
wfl::variant(ellipse_mode));
215 tmp.set_variable(
"composition_offset",
wfl::variant(comp_start_offset));
216 tmp.set_variable(
"composition_width",
wfl::variant(comp_end_offset - comp_start_offset));
280 const auto conf = cast_config_to<text_box_definition>();
332 if(modifier & KMOD_CTRL) {
333 if(!(modifier & KMOD_SHIFT)) {
400 load_resolutions<resolution>(cfg);
405 , text_x_offset(cfg[
"text_x_offset"])
406 , text_y_offset(cfg[
"text_y_offset"])
420 builder_text_box::builder_text_box(
const config& cfg)
422 , history(cfg[
"history"])
423 , max_input_length(cfg[
"max_input_length"].to_size_t())
424 , hint_text(cfg[
"hint_text"].t_str())
425 , hint_image(cfg[
"hint_image"])
426 , editable(cfg[
"editable"].to_bool(true))
432 auto widget = std::make_unique<text_box>(*
this);
445 DBG_GUI_G <<
"Window builder: placed text box '" <<
id
446 <<
"' with definition '" <<
definition <<
"'.";
A config object defines a single node in a WML file, with access to child nodes.
void set_wants_mouse_left_double_click(const bool click=true)
Abstract base class for text items.
std::size_t get_length() const
Wrapper function, returns length of the text in pango column offsets.
void set_font_size(const unsigned font_size)
point get_column_line(const point &position) const
std::string get_value() const
std::size_t get_composition_start() const
size_t get_composition_length() const
Get length of composition text by IME.
point get_cursor_position(const unsigned column, const unsigned line=0) const
void set_font_style(const font::pango_text::FONT_STYLE font_style)
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
std::size_t get_selection_length() const
void set_maximum_height(const int height, const bool multiline)
void set_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
virtual void set_cursor(const std::size_t offset, const bool select)
Moves the cursor at the wanted position.
void set_maximum_width(const int width)
bool is_editable() const
Check whether text can be edited or not.
std::size_t get_selection_start() const
void set_selection_length(const int selection_length)
void set_maximum_length(const std::size_t maximum_length)
void select_all()
Selects all text.
virtual void place(const point &origin, const point &size) override
See widget::place.
std::size_t max_input_length_
The maximum length of the text input.
void handle_key_clear_line(SDL_Keymod modifier, bool &handled) override
Inherited from text_box_base.
text_history history_
The history text for this widget.
bool history_down()
Goes one item down in the history.
std::string hint_image_
Image (such as a magnifying glass) that accompanies the help text.
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
void signal_handler_mouse_motion(const event::ui_event event, bool &handled, const point &coordinate)
void delete_char(const bool before_cursor) override
Inherited from text_box_base.
void signal_handler_left_button_down(const event::ui_event event, bool &handled)
unsigned text_height_
The height of the text itself.
std::string hint_text_
Helper text to display (such as "Search") if the text box is empty.
bool history_up()
Goes one item up in the history.
void handle_key_tab(SDL_Keymod modifier, bool &handled) override
Inherited from text_box_base.
void handle_mouse_selection(point mouse, const bool start_selection)
void signal_handler_left_button_double_click(const event::ui_event event, bool &handled)
bool dragging_
Is the mouse in dragging mode, this affects selection in mouse move.
void update_offsets()
Updates text_x_offset_ and text_y_offset_.
text_box(const implementation::builder_styled_widget &builder)
void delete_selection() override
Inherited from text_box_base.
void signal_handler_left_button_up(const event::ui_event event, bool &handled)
unsigned text_y_offset_
The y offset in the widget where the text starts.
virtual void update_canvas() override
See styled_widget::update_canvas.
unsigned text_x_offset_
The x offset in the widget where the text starts.
Class for text input history.
unsigned pos_
The current position in the history.
std::string get_value() const
Gets the current history value.
std::string down(const std::string &text="")
One step down in the history.
bool enabled_
Is the history enabled.
std::vector< std::string > * history_
The items in the history.
void push(const std::string &text)
Push string into the history.
std::string up(const std::string &text="")
One step up in the history.
void keyboard_capture(widget *widget)
void mouse_capture(const bool capture=true)
std::vector< std::string > * get_history(const std::string &id)
Returns a pointer to the history vector associated with given id making a new one if it doesn't exist...
Define the common log macros for the gui toolkit.
void point(int x, int y)
Draw a single point.
EXIT_STATUS start(bool clear_id, const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
int get_max_height(unsigned size, font::family_class fclass, pango_text::FONT_STYLE style)
Returns the maximum glyph height of a font, in pixels.
ui_event
The event sent to the dispatcher.
point get_mouse_position()
Returns the current mouse position.
Contains the implementation details for lexical_cast and shouldn't be used directly.
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
std::string & erase(std::string &str, const std::size_t start, const std::size_t len)
Erases a portion of a UTF-8 string.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
This file contains the settings handling of the widget library.
std::size_t max_input_length
virtual std::unique_ptr< widget > build() const override
std::vector< state_definition > state
resolution(const config &cfg)
text_box_definition(const config &cfg)
std::string missing_mandatory_wml_tag(const std::string §ion, const std::string &tag)
Returns a standard message for a missing wml child (tag).
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE_WML_CHILD(cfg, key, message)