16 #define GETTEXT_DOMAIN "wesnoth-lib"
30 #define LOG_SCOPE_HEADER get_control_type() + " [" + get_tree_view().id() + "] " + __func__
31 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
40 , parent_node_(parent_node)
41 , tree_view_(&parent_tree_view)
56 if(
const auto opt =
get_tree_view().get_node_definition(
id)) {
57 const auto& node_definition = **opt;
59 node_definition.builder->build(
grid_);
66 if(node_definition.unfolded) {
121 child->clear_before_destruct();
159 const int width_modification = best_size.x > current_size.x
160 ? best_size.x - current_size.x
174 ? tree_best_size.y - current_size.y
177 assert(height_modification >= 0);
187 std::vector<std::shared_ptr<gui2::tree_view_node>>
nodes;
190 if(
data.size() == 0) {
194 int width_modification = 0;
196 for(
const auto&
d :
data) {
204 assert(node->parent_node_ ==
this);
206 nodes.push_back(node);
217 int best_size = node->get_best_size().x;
220 int new_width = best_size > current_size.x
221 ? best_size - current_size.x
224 if(new_width > width_modification)
226 width_modification = new_width;
246 ? tree_best_size.y - current_size.y
249 assert(height_modification >= 0);
299 child_node->fold(
true);
315 child_node->unfold(
true);
341 const int width_modification = std::max(0, new_size.x - current_size.x);
342 const int height_modification = new_size.y - current_size.y;
343 assert(height_modification <= 0);
356 const int width_modification = std::max(0, new_size.x - current_size.x);
357 const int height_modification = new_size.y - current_size.y;
358 assert(height_modification >= 0);
366 int height_reduction = 0;
370 height_reduction += node->get_current_size().y;
376 if(height_reduction == 0) {
386 template<
class W,
class It>
389 for(It it = begin; it != end; ++it) {
402 const bool must_be_active)
412 return find_at_aux<W>(
419 return tree_view_node_implementation::find_at<widget>(*
this,
coordinate, must_be_active);
424 return tree_view_node_implementation::find_at<const widget>(*
this,
coordinate, must_be_active);
440 result =
child->find(
id, must_be_active);
462 result =
child->find(
id, must_be_active);
497 point node_size = node->get_current_size();
499 size.y += node_size.y;
500 size.x = std::max(
size.x, node_size.x);
528 point node_size = node->get_current_size(
true);
530 size.y += node_size.y;
531 size.x = std::max(
size.x, node_size.x);
542 if(indentation_level > 0) {
543 best_size.x += indentation_level * indentation_step_size;
553 const point node_size = node->calculate_best_size(indentation_level + 1, indentation_step_size);
556 best_size.y += node_size.y;
559 best_size.x = std::max(best_size.x, node_size.x);
588 const unsigned offset = origin.y;
595 origin.x += indentation_step_size;
596 assert(width >= indentation_step_size);
597 width -= indentation_step_size;
600 origin.y += best_size.y;
604 return origin.y - offset;
609 origin.y += node->place(indentation_step_size, origin, width);
616 return origin.y - offset;
631 node->set_visible_rectangle(rectangle);
644 node->impl_draw_children();
679 halt = handled =
true;
697 for(
unsigned row = 0; row <
g->get_rows(); ++row) {
698 for(
unsigned col = 0; col <
g->get_cols(); ++col) {
699 widget* wgt =
g->get_widget(row, col);
706 }
else if(
grid* child_grid =
dynamic_cast<grid*
>(wgt)) {
709 auto itor =
data.find(control->id());
711 if(itor ==
data.end()) {
712 itor =
data.find(
"");
715 if(itor !=
data.end()) {
716 control->set_members(itor->second);
728 static const std::string
type =
"tree_view_node";
741 return std::vector<int>();
752 assert(!
"tree_view_node was not found in parent nodes children");
753 throw "assertion ignored";
764 if(node.get() ==
this) {
768 res += node->get_current_size(
true).y;
805 throw std::domain_error(
806 "tree_view_node::get_node_above(): Cannot determine which node is this line, or which "
807 "node is the line above this one, if any.");
824 for(std::size_t
i = 0;
i <
parent.count_children(); ++
i) {
825 if(
parent.children_[
i].get() == cur) {
826 if(
i <
parent.count_children() - 1) {
827 return parent.children_[
i + 1].get();
845 }
while(above !=
nullptr && above->
label_ ==
nullptr);
855 }
while(below !=
nullptr && below->
label_ ==
nullptr);
892 child->layout_initialize(full_initialization);
898 return std::make_unique<gui2::iteration::tree_node>(*
this,
children_);
void connect_signal(const F &func, const queue_position position=back_child)
Adds a callback to the appropriate queue based on event type.
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
virtual void place(const point &origin, const point &size) override
See widget::place.
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See widget::set_visible_rectangle.
virtual widget * find_at(const point &coordinate, const bool must_be_active) override
See widget::find_at.
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
virtual void layout_initialize(const bool full_initialization) override
See widget::layout_initialize.
Small abstract helper class.
void set_value_bool(bool value, bool fire_event=false)
virtual void set_value(unsigned value, bool fire_event=false)=0
Select the styled_widget.
virtual unsigned get_value() const =0
Is the styled_widget selected?
bool get_value_bool() const
grid grid_
Grid holding our contents.
std::vector< int > describe_path() const
Calculates the node indices needed to get from the root node to this node.
point get_current_size(bool assume_visible=false) const
void signal_handler_label_left_button_click(const event::ui_event event, bool &handled, bool &halt)
void clear()
Removes all child items from the widget.
selectable_item * toggle_
The toggle for the folded state.
tree_view & get_tree_view()
tree_view_node & get_child_at(int index)
tree_view * tree_view_
The tree view that owns us.
void fold(const bool recursive=false)
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See widget::set_visible_rectangle.
bool is_folded() const
Is the node folded?
point get_folded_size() const
bool is_root_node() const
Is this node the root node?
void select_node(bool expand_parents=false)
virtual void set_origin(const point &origin) override
See widget::set_origin.
void signal_handler_toggle_left_click(const event::ui_event event)
tree_view_node & parent_node()
Returns the parent node.
std::vector< std::shared_ptr< gui2::tree_view_node > > replace_children(const std::string &id, const std::vector< widget_data > &data)
Replaces all children of this tree with new children.
void clear_before_destruct()
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
const std::string & get_control_type() const
Returns the control_type of the tree_view_node.
selectable_item * label_
The label to show our selected state.
tree_view_node * get_selectable_node_above()
tree_view_node * parent_node_
Our parent node.
virtual iteration::walker_ptr create_walker() override
See widget::create_walker.
void unfold(const bool recursive=false)
tree_view_node & add_child_impl(std::shared_ptr< tree_view_node > &&new_node, const int index)
Implementation detail for add_child.
tree_view_node(const std::string &id, tree_view_node *parent_node, tree_view &parent_tree_view, const widget_data &data)
virtual widget * find_at(const point &coordinate, const bool must_be_active) override
See widget::find_at.
node_children_vector children_
Our children.
point get_unfolded_size() const
tree_view_node * get_node_above()
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
unsigned get_indentation_level() const
The indentation level of the node.
std::size_t count_children() const
The number of children in this widget.
void init_grid(grid *grid, const widget_data &data)
void layout_initialize(const bool full_initialization) override
How the layout engine works.
virtual point calculate_best_size() const override
See widget::calculate_best_size.
tree_view_node * get_last_visible_parent_node()
virtual void impl_draw_children() override
See widget::impl_draw_children.
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
tree_view_node * get_node_below()
tree_view_node * get_selectable_node_below()
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_
tree_view_node * selected_item_
static const std::string root_node_id
virtual void layout_children() override
See widget::layout_children.
const std::vector< node > & nodes
static std::string _(const char *str)
Define the common log macros for the gui toolkit.
#define log_scope2(domain, description)
void point(int x, int y)
Draw a single point.
ui_event
The event sent to the dispatcher.
std::unique_ptr< class walker_base > walker_ptr
std::map< std::string, widget_item > widget_data
lg::log_domain log_gui_layout("gui/layout")
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
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.
typename const_clone< D, S >::reference const_clone_ref
Contains the SDL_Rect helper code.
static W * find_at(utils::const_clone_ref< tree_view_node, W > tree_view_node, const point &coordinate, const bool must_be_active)
static W * find_at_aux(It begin, It end, const point &coordinate, const bool must_be_active)
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define FAIL_WITH_DEV_MESSAGE(message, dev_message)