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)()>
188 if(visible != selected) {
192 return (selected->*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>()) {
244 if(!selected || !selected->
is_folded()) {
260 load_resolutions<resolution>(cfg);
268 state.emplace_back(cfg.
child(
"state_enabled"));
269 state.emplace_back(cfg.
child(
"state_disabled"));
274 grid = std::make_shared<builder_grid>(child);
281 builder_tree_view::builder_tree_view(
const config& cfg)
285 , indentation_step_size(cfg[
"indentation_step_size"])
289 nodes.emplace_back(node);
301 auto widget = std::make_unique<tree_view>(*this);
308 DBG_GUI_G <<
"Window builder: placed tree_view '" <<
id <<
"' with definition '" <<
definition <<
"'.";
313 widget->init_grid(*conf->grid);
321 , unfolded(cfg[
"unfolded"].to_bool(false))
329 const config& node_definition = cfg.
child(
"node_definition");
331 VALIDATE(node_definition,
_(
"No node defined."));
333 builder = std::make_shared<builder_grid>(node_definition);
Define the common log macros for the gui toolkit.
Base class of a resolution, contains the common keys for a resolution.
void keyboard_capture(widget *widget)
virtual void finalize_setup()
Inherited from container_base.
tree_view_node * parent_node_
Our parent node.
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
std::vector< state_definition > state
const std::vector< node > & nodes
std::vector< std::shared_ptr< tree_view_node > > node_children_vector
ui_event
The event sent to the dispatcher.
unsigned indentation_step_size_
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
tree_view_node & add_node(const std::string &id, const widget_data &data, const int index=-1)
tree_view_node & get_root_node()
unsigned indentation_step_size
virtual void set_self_active(const bool active) override
See container_base::set_self_active.
child_itors child_range(config_key_type key)
void handle_key_down_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from scrollbar_container.
tree_view_node * selected_item()
scrollbar_container::scrollbar_mode vertical_scrollbar_mode
static std::string _(const char *str)
tree_view_node & add_child(const std::string &id, const widget_data &data, const int index=-1)
Constructs a new child node.
void signal_handler_left_button_down(const event::ui_event event)
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.
bool empty() const
Does the node have children?
bool is_folded() const
Is the node folded?
node_children_vector children_
Our children.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
This file contains the settings handling of the widget library.
void handle_key_up_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from scrollbar_container.
virtual std::unique_ptr< widget > build() const override
bool handle_up_down_arrow()
tree_view_node * root_node_
std::vector< tree_node > nodes
The types of nodes in the tree view.
void handle_key_left_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from scrollbar_container.
A tree view is a control that holds several items of the same or different types. ...
void fold(const bool recursive=false)
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.
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 clear()
Removes all child items from the widget.
tree_view_node * get_last_visible_parent_node()
An abstract description of a rectangle with integer coordinates.
void unfold(const bool recursive=false)
static const unsigned HORIZONTAL_GROW_SEND_TO_CLIENT
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.
static const unsigned VERTICAL_GROW_SEND_TO_CLIENT
scrollbar_mode get_scrollbar_mode(const std::string &scrollbar_mode)
Returns the scrollbar mode flags.
void set_rows_cols(const unsigned rows, const unsigned cols)
Wrapper to set_rows and set_cols.
tree_view_node * get_next_node()
void clear_before_destruct()
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See widget::set_visible_rectangle.
void point(int x, int y)
Draw a single point.
tree_view_definition(const config &cfg)
std::map< std::string, widget_item > widget_data
virtual void place(const point &origin, const point &size) override
See widget::place.
resolution(const config &cfg)
virtual void layout_children() override
See widget::layout_children.
static const std::string root_node_id
A config object defines a single node in a WML file, with access to child nodes.
void handle_key_right_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from scrollbar_container.
Contains the implementation details for lexical_cast and shouldn't be used directly.
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.
tree_node(const config &cfg)