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) {
197 std::shared_ptr<gui2::tree_view_node> new_node = std::make_shared<tree_view_node>(
id,
this,
get_tree_view(),
d);
198 std::shared_ptr<gui2::tree_view_node> node = *
children_.insert(
children_.end(), std::move(new_node));
205 assert(node->parent_node_ ==
this);
207 nodes.push_back(node);
218 int best_size = node->get_best_size().x;
221 int new_width = best_size > current_size.x
222 ? best_size - current_size.x
225 if(new_width > width_modification)
227 width_modification = new_width;
247 ? tree_best_size.y - current_size.y
250 assert(height_modification >= 0);
300 child_node->fold(
true);
316 child_node->unfold(
true);
326 const int width_modification = std::max(0, new_size.x - current_size.x);
327 const int height_modification = new_size.y - current_size.y;
328 assert(height_modification <= 0);
339 const int width_modification = std::max(0, new_size.x - current_size.x);
340 const int height_modification = new_size.y - current_size.y;
341 assert(height_modification >= 0);
350 int height_reduction = 0;
354 height_reduction += node->get_current_size().y;
360 if(height_reduction == 0) {
370 template<
class W,
class It>
373 for(It it = begin; it != end; ++it) {
386 const bool must_be_active)
396 return find_at_aux<W>(
403 return tree_view_node_implementation::find_at<widget>(*
this,
coordinate, must_be_active);
408 return tree_view_node_implementation::find_at<const widget>(*
this,
coordinate, must_be_active);
424 result =
child->find(
id, must_be_active);
446 result =
child->find(
id, must_be_active);
481 point node_size = node->get_current_size();
483 size.y += node_size.y;
484 size.x = std::max(
size.x, node_size.x);
512 point node_size = node->get_current_size(
true);
514 size.y += node_size.y;
515 size.x = std::max(
size.x, node_size.x);
526 if(indentation_level > 0) {
527 best_size.x += indentation_level * indentation_step_size;
537 const point node_size = node->calculate_best_size(indentation_level + 1, indentation_step_size);
540 best_size.y += node_size.y;
543 best_size.x = std::max(best_size.x, node_size.x);
572 const unsigned offset = origin.y;
579 origin.x += indentation_step_size;
580 assert(width >= indentation_step_size);
581 width -= indentation_step_size;
584 origin.y += best_size.y;
588 return origin.y - offset;
593 origin.y += node->place(indentation_step_size, origin, width);
600 return origin.y - offset;
615 node->set_visible_rectangle(rectangle);
628 node->impl_draw_children();
663 halt = handled =
true;
681 for(
unsigned row = 0; row <
g->get_rows(); ++row) {
682 for(
unsigned col = 0; col <
g->get_cols(); ++col) {
683 widget* wgt =
g->get_widget(row, col);
690 }
else if(
grid* child_grid =
dynamic_cast<grid*
>(wgt)) {
693 auto itor =
data.find(control->id());
695 if(itor ==
data.end()) {
696 itor =
data.find(
"");
699 if(itor !=
data.end()) {
700 control->set_members(itor->second);
712 static const std::string
type =
"tree_view_node";
725 return std::vector<int>();
736 assert(!
"tree_view_node was not found in parent nodes children");
737 throw "assertion ignored";
748 if(node.get() ==
this) {
752 res += node->get_current_size(
true).y;
789 throw std::domain_error(
790 "tree_view_node::get_node_above(): Cannot determine which node is this line, or which "
791 "node is the line above this one, if any.");
808 for(std::size_t
i = 0;
i <
parent.count_children(); ++
i) {
809 if(
parent.children_[
i].get() == cur) {
810 if(
i <
parent.count_children() - 1) {
811 return parent.children_[
i + 1].get();
829 }
while(above !=
nullptr && above->
label_ ==
nullptr);
839 }
while(below !=
nullptr && below->
label_ ==
nullptr);
876 child->layout_initialize(full_initialization);
882 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.
A panel is a visible container to hold multiple widgets.
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
Class for a toggle button.
grid grid_
Grid holding our contents.
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.
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()
void signal_handler_left_button_click(const event::ui_event event)
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()
std::vector< int > describe_path()
Calculates the node indices needed to get from the root node to this node.
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.
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_
tree_view_node * selected_item_
static const std::string root_node_id
tree_view_node & get_root_node()
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)
#define FAIL_WITH_DEV_MESSAGE(message, dev_message)