16 #define GETTEXT_DOMAIN "wesnoth-lib"
28 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
29 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
39 , node_definitions_(builder.
nodes)
40 , indentation_step_size_(0)
43 , selected_item_(
nullptr)
45 connect_signal<event::LEFT_BUTTON_DOWN>(
69 auto node_itor = std::find_if(siblings.begin(), siblings.end(), [node](
const auto&
c) { return c.get() == node; });
71 assert(node_itor != siblings.end());
73 auto old_node = std::move(*node_itor);
74 old_node->parent_node_ =
nullptr;
76 const int position = std::distance(siblings.begin(), node_itor);
78 siblings.erase(node_itor);
85 return std::pair(std::move(old_node), position);
110 const int height_modification,
111 const int width_modification_pos,
112 const int height_modification_pos)
115 << width_modification <<
" height_modification " << height_modification <<
".";
120 width_modification_pos,
121 height_modification_pos
125 size.x += width_modification;
126 size.y += height_modification;
134 if(width_modification < 0 || height_modification < 0) {
178 template<tree_view_node* (tree_view_node::*func)()>
194 template<tree_view_node* (tree_view_node::*func)()>
200 SDL_Rect
rect = next->get_grid().get_rectangle();
212 if(handle_up_down_arrow<&tree_view_node::get_selectable_node_above>()) {
221 if(handle_up_down_arrow<&tree_view_node::get_selectable_node_below>()) {
259 load_resolutions<resolution>(cfg);
272 grid = std::make_shared<builder_grid>(child);
279 builder_tree_view::builder_tree_view(
const config& cfg)
283 , indentation_step_size(cfg[
"indentation_step_size"].to_unsigned())
287 nodes.emplace_back(node);
299 auto widget = std::make_unique<tree_view>(*
this);
306 DBG_GUI_G <<
"Window builder: placed tree_view '" <<
id <<
"' with definition '" <<
definition <<
"'.";
311 widget->init_grid(*conf->grid);
319 , unfolded(cfg[
"unfolded"].to_bool(false))
328 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)
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.
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.
const tree_view_node & get_root_node() const
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 * 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.
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)
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_tag(const std::string §ion, const std::string &tag)
Returns a standard message for a missing wml child (tag).
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 (attribute).
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.