15 #define GETTEXT_DOMAIN "wesnoth-lib"
28 #define LOG_SCOPE_HEADER \
29 get_control_type() + " [" + tree_view().id() + "] " + __func__
30 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
37 const std::vector<tnode_definition>& node_definitions,
40 const std::map<std::string /* widget id */, string_map>&
data)
42 , parent_node_(parent_node)
43 , tree_view_(parent_tree_view)
46 , node_definitions_(node_definitions)
50 , callback_state_change_()
51 , callback_state_to_folded_()
52 , callback_state_to_unfolded_()
59 if(node_definition.id ==
id) {
60 node_definition.builder->build(&
grid_);
77 if(node_definition.unfolded) {
88 twidget* widget = find_widget<twidget>(
89 &
grid_,
"tree_view_node_label",
false,
false);
105 signal_handler_label_left_button_click,
114 label_->set_value(
true);
122 VALIDATE(
false,
_(
"Unknown builder id for tree view node."));
131 if(
tree_view().selected_item_ ==
this) {
138 const std::map<std::string /* widget id */, string_map>&
data,
144 if(static_cast<size_t>(index) <
children_.size()) {
165 tpoint best_size = itor->get_best_size();
167 const unsigned width_modification
168 = best_size.
x > current_width ? best_size.
x - current_width : 0;
171 const int height_modification = best_size.
y;
172 assert(height_modification > 0);
250 const int width_modification = std::max(0, new_size.
x - current_size.
x);
251 const int height_modification = new_size.
y - current_size.
y;
252 assert(height_modification <= 0);
267 const int width_modification = std::max(0, new_size.
x - current_size.
x);
268 const int height_modification = new_size.
y - current_size.
y;
269 assert(height_modification >= 0);
282 int height_reduction = 0;
287 height_reduction += node.get_current_size().y;
293 if(height_reduction == 0) {
303 template <
class W,
class It>
307 const bool must_be_active)
309 for(It it = begin; it !=
end; ++it) {
310 if(W* widget = it->find_at(coordinate, must_be_active)) {
320 W>::reference tree_view_node,
322 const bool must_be_active)
325 = tree_view_node.grid_.find_at(coordinate, must_be_active)) {
330 if(tree_view_node.is_folded()) {
334 return find_at_aux<W>(tree_view_node.children_.begin(),
335 tree_view_node.children_.end(),
342 const bool must_be_active)
344 return ttree_view_node_implementation::find_at<twidget>(
345 *
this, coordinate, must_be_active);
349 const bool must_be_active)
const
351 return ttree_view_node_implementation::find_at<const twidget>(
352 *
this, coordinate, must_be_active);
358 return result ? result :
grid_.
find(
id, must_be_active);
362 const bool must_be_active)
const
365 return result ? result :
grid_.
find(
id, must_be_active);
369 twindow& caller,
const std::vector<twidget*>& call_stack)
371 std::vector<twidget*> child_call_stack = call_stack;
380 std::vector<twidget*> child_call_stack = call_stack;
381 node.impl_populate_dirty_list(caller, child_call_stack);
406 for(boost::ptr_vector<ttree_view_node>::const_iterator
itor
419 size.
y += node_size.
y;
420 size.
x = std::max(size.
x, node_size.
x);
444 for(boost::ptr_vector<ttree_view_node>::const_iterator
itor
457 size.
y += node_size.
y;
458 size.
x = std::max(size.
x, node_size.
x);
465 const unsigned indention_step_size)
471 if(indention_level > 0) {
472 best_size.
x += indention_level * indention_step_size;
477 for(boost::ptr_vector<ttree_view_node>::const_iterator
itor
489 indention_step_size);
492 best_size.
y += node_size.
y;
494 best_size.x = std::max(best_size.x, node_size.
x);
525 const unsigned offset = origin.
y;
531 origin.x += indention_step_size;
532 assert(width >= indention_step_size);
533 width -= indention_step_size;
535 origin.y += best_size.
y;
545 origin.y += node.place(indention_step_size, origin, width);
568 node.set_visible_rectangle(rectangle);
584 node.impl_draw_children(frame_buffer, x_offset, y_offset);
623 halt = handled =
true;
632 if(
tree_view().selection_change_callback_) {
640 const std::map<std::string /* widget id */, string_map>&
data)
645 for(
unsigned col = 0; col < grid->
get_cols(); ++col) {
649 tgrid* child_grid =
dynamic_cast<tgrid*
>(widget);
657 }
else if(child_grid) {
660 std::map<std::string, string_map>::const_iterator
itor
661 = data.find(ctrl->
id());
663 if(itor == data.end()) {
664 itor = data.find(
"");
666 if(itor != data.end()) {
686 assert(static_cast<size_t>(index) <
children_.size());
693 return std::vector<int>();
698 for(
int i = 0,
size = parents_childs.size();
i <
size; ++
i) {
699 if(&parents_childs[
i] ==
this) {
704 assert(!
"tree_view_node was not found in parent nodes children");
705 throw "assertion ignored";
718 res += node.get_current_size(
true).y;
762 for(
size_t i = 0;
i < parent.
size(); ++
i) {
764 if(
i < parent.
size() - 1) {
781 }
while(above !=
nullptr && above->
label_ ==
nullptr);
789 }
while(below !=
nullptr && below->
label_ ==
nullptr);
804 if(
tree_view().selection_change_callback_) {
818 child.layout_initialise(full_initialisation);
Define the common log macros for the gui toolkit.
std::vector< int > describe_path()
calculates the node indicies that we need to get from the root node to this node. ...
tgrid grid_
Grid holding our contents.
ttree_view_node * get_selectable_node_above()
void signal_handler_label_left_button_click(const event::tevent event, bool &handled, bool &halt)
size_t size() const
The "size" of the widget.
ttree_view_node & parent_node()
Returns the parent node.
unsigned indention_step_size_
tselectable_ * toggle_
The toggle for the folded state.
virtual unsigned get_value() const =0
Is the control selected?
const std::vector< tnode_definition > & node_definitions_
The node definitions known to use.
bool is_folded() const
Is the node folded?
GLuint GLuint GLsizei GLenum type
virtual void request_reduce_width(const unsigned maximum_width) override
See twidget::request_reduce_width.
unsigned int get_rows() const
lg::log_domain log_gui_layout("gui/layout")
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
GLint GLint GLint GLint GLint GLint y
ttree_view_node * selected_item_
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
boost::enable_if< boost::mpl::has_key< tset_event, boost::mpl::int_< E > > >::type connect_signal(const tsignal_function &signal, const tposition position=back_child)
Connect a signal for callback in tset_event.
tpoint get_current_size(bool assume_visible=false) const
ttree_view_node & add_child(const std::string &id, const std::map< std::string, string_map > &data, const int index=-1)
Adds a child item to the list of child nodes.
tpoint get_unfolded_size() const
virtual void set_value(const unsigned)=0
Select the control.
ttree_view_node * get_selectable_node_below()
A left mouse button click event for a widget.
base class of top level items, the only item which needs to store the final canvases to draw on ...
A class inherited from ttext_box that displays its input as stars.
std::function< void(twidget &)> selection_change_callback_
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
static UNUSEDNOWARN std::string _(const char *str)
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See twidget::set_visible_rectangle.
static W * find_at_aux(It begin, It end, const tpoint &coordinate, const bool must_be_active)
bool get_value_bool() const
boost::ptr_vector< ttree_view_node > children_
Our children.
void signal_handler_left_button_click(const event::tevent event)
void impl_populate_dirty_list(twindow &caller, const std::vector< twidget * > &call_stack)
"Inherited" from twidget.
#define log_scope2(domain, description)
std::function< void(twidget &)> callback_state_to_unfolded_
See tselectable_::set_callback_state_change.
tevent
The event send to the dispatcher.
std::function< void(twidget &)> callback_state_change_
See tselectable_::set_callback_state_change.
ttree_view_node * get_node_above()
Small abstract helper class.
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See twidget::set_visible_rectangle.
static W * find_at(typename utils::tconst_clone< ttree_view_node, W >::reference tree_view_node, const tpoint &coordinate, const bool must_be_active)
void init_grid(tgrid *grid, const std::map< std::string, string_map > &data)
std::map< std::string, tfilter >::iterator itor
ttree_view_node * get_node_below()
tselectable_ * label_
The label to show our selected state.
unsigned get_indention_level() const
The indention level of the node.
GLint GLint GLint GLint GLint x
Helper struct to clone the constness of one type to another.
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
bool is_root_node() const
Is this node the root node?
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
Base class for all visible items.
void set_child_members(const std::map< std::string, string_map > &data)
Sets the members of the child controls.
twidget * find(const std::string &id, const bool must_be_active) override
See twidget::find.
ttree_view & tree_view_
The tree view that owns us.
GLenum GLenum GLvoid * row
tpoint get_folded_size() const
virtual void set_members(const string_map &data)
Sets the members of the control.
bool disable_click_dismiss() const override
See twidget::disable_click_dismiss.
const std::string & get_control_type() const
Returns the control_type of the ttree_view_node.
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
std::function< void(twidget &)> callback_state_to_folded_
See tselectable_::set_callback_state_change.
virtual void layout_initialise(const bool full_initialisation) override
See twidget::layout_initialise.
ttree_view_node * parent_node_
Our parent node.
twidget * find(const std::string &id, const bool must_be_active) override
See twidget::find.
GLint GLint GLint GLint GLint GLint GLsizei width
const twidget * widget(const unsigned row, const unsigned col) const
Returns the widget in the selected cell.
void set_value_bool(const bool value)
ttree_view_node & get_child_at(int index)
Class for a toggle button.
ttree_view_node * get_last_visible_parent_node()
virtual void layout_children() override
See twidget::layout_children.
unsigned int get_cols() const
ttree_view_node(const std::string &id, const std::vector< tnode_definition > &node_definitions, ttree_view_node *parent_node, ttree_view &parent_tree_view, const std::map< std::string, string_map > &data)
GLsizei const GLcharARB ** string
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.
virtual void impl_draw_children(surface &frame_buffer, int x_offset, int y_offset) override
See twidget::impl_draw_children.
void clear()
Removes all child items from the widget.
void layout_initialise(const bool full_initialisation)
How the layout engine works.