16 #define GETTEXT_DOMAIN "wesnoth-lib"
29 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
30 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
42 , max_input_length_(builder.max_input_length)
46 , hint_text_(builder.hint_text)
47 , hint_image_(builder.hint_image)
51 values_.emplace_back(
"label", this->get_label());
53 set_wants_mouse_left_double_click();
55 connect_signal<event::MOUSE_MOTION>(std::bind(
57 connect_signal<event::LEFT_BUTTON_DOWN>(std::bind(
59 connect_signal<event::LEFT_BUTTON_UP>(std::bind(
61 connect_signal<event::LEFT_BUTTON_DOUBLE_CLICK>(std::bind(
63 connect_signal<event::MOUSE_ENTER>(
66 const auto conf = cast_config_to<combobox_definition>();
69 set_font_size(get_text_font_size());
70 set_font_style(conf->text_font_style);
102 PangoEllipsizeMode ellipse_mode = PANGO_ELLIPSIZE_NONE;
105 ellipse_mode = PANGO_ELLIPSIZE_START;
107 ellipse_mode = PANGO_ELLIPSIZE_END;
113 unsigned start_offset = 0;
114 unsigned end_offset = 0;
117 }
else if(length > 0) {
126 unsigned comp_start_offset = 0;
127 unsigned comp_end_offset = 0;
128 if(edit_length == 0) {
130 }
else if(edit_length > 0) {
149 tmp.set_variable(
"text_maximum_width",
wfl::variant(max_width));
150 tmp.set_variable(
"text_maximum_height",
wfl::variant(max_height));
152 tmp.set_variable(
"cursor_offset",
155 tmp.set_variable(
"selection_offset",
wfl::variant(start_offset));
156 tmp.set_variable(
"selection_width",
wfl::variant(end_offset - start_offset));
157 tmp.set_variable(
"text_wrap_mode",
wfl::variant(ellipse_mode));
159 tmp.set_variable(
"composition_offset",
wfl::variant(comp_start_offset));
160 tmp.set_variable(
"composition_width",
wfl::variant(comp_end_offset - comp_start_offset));
223 const auto conf = cast_config_to<combobox_definition>();
234 static_cast<int>(conf->text_x_offset(variables)),
235 static_cast<int>(conf->text_y_offset(variables))
275 return row_cfg.has_attribute(
"value") ? row_cfg[
"value"] : row_cfg[
"label"];
280 assert(selected <
values.size());
297 return value == last_selected ?
selected_ : -1;
302 assert(selected <
values_.size());
322 if ((mouse_x <= right_border) && (mouse_x >= right_border-
ICON_SIZE)) {
363 if ((mouse_x <= right_border) && (mouse_x >= right_border-
ICON_SIZE)) {
367 if(droplist.
show()) {
414 load_resolutions<resolution>(
cfg);
419 , text_x_offset(
cfg[
"text_x_offset"])
420 , text_y_offset(
cfg[
"text_y_offset"])
436 , max_input_length(
cfg[
"max_input_length"].to_size_t())
437 , hint_text(
cfg[
"hint_text"].t_str())
438 , hint_image(
cfg[
"hint_image"])
448 auto widget = std::make_unique<combobox>(*
this);
457 DBG_GUI_G <<
"Window builder: placed text box '" <<
id
458 <<
"' with definition '" <<
definition <<
"'.";
A config object defines a single node in a WML file, with access to child nodes.
child_itors child_range(std::string_view key)
void signal_handler_mouse_enter(const event::ui_event, bool &)
void signal_handler_left_button_up(const event::ui_event event, bool &handled)
std::size_t max_input_length_
The maximum length of the text input.
std::string get_preset_value(const size_t index) const
Get the index-th value from the preset values that area shown in the dropdown.
void update_mouse_cursor()
Update the mouse cursor based on whether it is over button area or text area.
void delete_selection() override
Deletes the current selection.
void update_offsets()
Updates text_x_offset_ and text_y_offset_.
bool dragging_
Is the mouse in dragging mode, this affects selection in mouse move.
void signal_handler_mouse_motion(const event::ui_event event, bool &handled, const point &coordinate)
void handle_mouse_selection(point mouse, const bool start_selection)
virtual void update_canvas() override
Updates the canvas(ses).
unsigned const ICON_SIZE
Size of the dropdown icon TODO : Should be dynamically loaded from image.
void handle_key_clear_line(SDL_Keymod modifier, bool &handled) override
Inherited from text_box_base.
std::string hint_image_
Image (such as a magnifying glass) that accompanies the help text.
void handle_key_down_arrow(SDL_Keymod, bool &handled) override
Inherited from text_box_base.
void set_values(const std::vector<::config > &values, unsigned selected=0)
int get_selected() const
Returned last selected entry's index or -1 if typed value that does not matches any preset value.
void signal_handler_left_button_down(const event::ui_event event, bool &handled)
void delete_char(const bool before_cursor) override
Deletes the character.
std::vector<::config > values_
point text_offset_
The x, y offset in the widget where the text starts.
void signal_handler_left_button_double_click(const event::ui_event event, bool &handled)
void set_selected(unsigned selected, bool fire_event=true)
void handle_key_up_arrow(SDL_Keymod, bool &handled) override
Inherited from text_box_base.
std::string hint_text_
Helper text to display (such as "Search") if the combo box is empty.
unsigned text_height_
The height of the text itself.
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
virtual void place(const point &origin, const point &size) override
See widget::place.
bool show(const unsigned auto_close_time=0)
Shows the window.
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
Abstract base class for text items.
std::size_t get_composition_length() const
Get length of composition text by IME.
std::size_t get_length() const
Wrapper function, see font::pango_text::get_length.
point get_column_line(const point &position) const
std::string get_value() const
std::size_t get_composition_start() const
point get_cursor_position(const unsigned column, const unsigned line=0) const
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)
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.
void keyboard_capture(widget *widget)
void mouse_capture(const bool capture=true)
Define the common log macros for the gui toolkit.
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
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.
bool fire_event(const ui_event event, const std::vector< std::pair< widget *, ui_event >> &event_chain, widget *dispatcher, widget *w, F &&... params)
Helper function for fire_event.
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(std::string_view str)
Length in characters of a UTF-8 string.
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
resolution(const config &cfg)
combobox_definition(const config &cfg)
std::vector<::config > options_
virtual std::unique_ptr< widget > build() const override
std::vector< state_definition > state
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)