16 #define GETTEXT_DOMAIN "wesnoth-lib"
29 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
30 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
40 , node_definitions_(builder.
nodes)
41 , indentation_step_size_(0)
44 , selected_item_(
nullptr)
46 connect_signal<event::LEFT_BUTTON_DOWN>(
70 auto node_itor = std::find_if(siblings.begin(), siblings.end(), [node](
const auto&
c) { return c.get() == node; });
72 assert(node_itor != siblings.end());
74 auto old_node = std::move(*node_itor);
75 old_node->parent_node_ =
nullptr;
77 const int position = std::distance(siblings.begin(), node_itor);
79 siblings.erase(node_itor);
86 return std::pair(std::move(old_node), position);
111 const int height_modification,
112 const int width_modification_pos,
113 const int height_modification_pos)
116 << width_modification <<
" height_modification " << height_modification <<
".";
121 width_modification_pos,
122 height_modification_pos
126 size.x += width_modification;
127 size.y += height_modification;
135 if(width_modification < 0 || height_modification < 0) {
179 template<tree_view_node* (tree_view_node::*func)()>
195 template<tree_view_node* (tree_view_node::*func)()>
201 SDL_Rect
rect = next->get_grid().get_rectangle();
213 if(handle_up_down_arrow<&tree_view_node::get_selectable_node_above>()) {
222 if(handle_up_down_arrow<&tree_view_node::get_selectable_node_below>()) {
260 load_resolutions<resolution>(cfg);
273 grid = std::make_shared<builder_grid>(child);
280 builder_tree_view::builder_tree_view(
const config& cfg)
284 , indentation_step_size(cfg[
"indentation_step_size"])
288 nodes.emplace_back(node);
300 auto widget = std::make_unique<tree_view>(*
this);
307 DBG_GUI_G <<
"Window builder: placed tree_view '" <<
id <<
"' with definition '" <<
definition <<
"'.";
312 widget->init_grid(*conf->grid);
320 , unfolded(cfg[
"unfolded"].to_bool(false))
330 VALIDATE(node_definition,
_(
"No node defined."));
332 builder = std::make_shared<builder_grid>(*node_definition);
A config object defines a single node in a WML file, with access to child nodes.
child_itors child_range(config_key_type key)
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Euivalent to mandatory_child, but returns an empty optional if the nth child was not found.
static const unsigned HORIZONTAL_GROW_SEND_TO_CLIENT
static const unsigned VERTICAL_GROW_SEND_TO_CLIENT
void set_rows_cols(const unsigned rows, const unsigned cols)
Wrapper to set_rows and set_cols.
void set_child(std::unique_ptr< widget > widget, const unsigned row, const unsigned col, const unsigned flags, const unsigned border_size)
Sets a child in the grid.
void clear()
Removes all child items from the widget.
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See widget::set_visible_rectangle.
bool empty() const
Does the node have children?
void clear_before_destruct()
tree_view_node * parent_node_
Our parent node.
node_children_vector children_
Our children.
std::vector< std::shared_ptr< tree_view_node > > node_children_vector
tree_view_node & add_child(const std::string &id, const widget_data &data, const int index=-1)
Constructs a new child node.
virtual void place(const point &origin, const point &size) override
See widget::place.
A tree view is a control that holds several items of the same or different types.
void resize_content(const int width_modification, const int height_modification, const int width_modification_pos=-1, const int height_modification_pos=-1)
Resizes the content.
unsigned indentation_step_size_
void handle_key_right_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from scrollbar_container.
virtual void set_self_active(const bool active) override
See container_base::set_self_active.
static const std::string root_node_id
tree_view_node * get_next_node()
tree_view_node & get_root_node()
tree_view_node * root_node_
virtual void finalize_setup()
Inherited from container_base.
void handle_key_up_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from scrollbar_container.
void handle_key_left_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from scrollbar_container.
tree_view_node & add_node(const std::string &id, const widget_data &data, const int index=-1)
void signal_handler_left_button_down(const event::ui_event event)
tree_view_node * selected_item()
void handle_key_down_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from scrollbar_container.
virtual void layout_children() override
See widget::layout_children.
bool handle_up_down_arrow()
std::pair< std::shared_ptr< tree_view_node >, int > remove_node(tree_view_node *node)
Removes the given node as a child of its parent node.
void keyboard_capture(widget *widget)
const std::vector< node > & nodes
static std::string _(const char *str)
Define the common log macros for the gui toolkit.
std::string id
Text to match against addon_info.tags()
void point(int x, int y)
Draw a single point.
ui_event
The event sent to the dispatcher.
scrollbar_mode get_scrollbar_mode(const std::string &scrollbar_mode)
Returns the scrollbar mode flags.
std::map< std::string, widget_item > widget_data
Contains the implementation details for lexical_cast and shouldn't be used directly.
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in 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.
unsigned indentation_step_size
std::vector< tree_node > nodes
The types of nodes in the tree view.
scrollbar_container::scrollbar_mode vertical_scrollbar_mode
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode
virtual std::unique_ptr< widget > build() const override
tree_node(const config &cfg)
Base class of a resolution, contains the common keys for a resolution.
std::vector< state_definition > state
resolution(const config &cfg)
tree_view_definition(const config &cfg)
An abstract description of a rectangle with integer coordinates.
std::string missing_mandatory_wml_key(const std::string §ion, const std::string &key, const std::string &primary_key, const std::string &primary_value)
Returns a standard message for a missing wml key.
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)
#define VALIDATE(cond, message)
The macro to use for the validation of WML.