Make layout_children a virtual function.

This allows the window the call the routine shortly before updating the
dirty list. The tree view is the only widget that really uses it (the
others simply forward the call), but others will follow later.
This commit is contained in:
Mark de Wever 2010-02-21 10:43:59 +00:00
parent 3e8d48a870
commit 42424afdb5
11 changed files with 53 additions and 7 deletions

View file

@ -123,6 +123,11 @@ void tcontainer_::impl_draw_children(surface& frame_buffer)
grid_.draw_children(frame_buffer);
}
void tcontainer_::layout_children()
{
grid_.layout_children();
}
void tcontainer_::child_populate_dirty_list(twindow& caller,
const std::vector<twidget*>& call_stack)
{

View file

@ -109,6 +109,9 @@ public:
protected:
/** Inherited from twidget. */
void layout_children();
/** Inherited from twidget. */
void child_populate_dirty_list(twindow& caller,
const std::vector<twidget*>& call_stack);

View file

@ -553,6 +553,14 @@ void tgrid::set_visible_area(const SDL_Rect& area)
}
}
void tgrid::layout_children()
{
foreach(tchild& child, children_) {
assert(child.widget());
child.widget()->layout_children();
}
}
void tgrid::child_populate_dirty_list(twindow& caller,
const std::vector<twidget*>& call_stack)
{

View file

@ -244,6 +244,9 @@ public:
/** Inherited from twidget. */
void set_visible_area(const SDL_Rect& area);
/** Inherited from twidget. */
void layout_children();
/** Inherited from twidget. */
void child_populate_dirty_list(twindow& caller,
const std::vector<twidget*>& call_stack);

View file

@ -754,6 +754,15 @@ void tscrollbar_container::impl_draw_children(surface& frame_buffer)
content_grid_->draw_children(frame_buffer);
}
void tscrollbar_container::layout_children()
{
// Inherited.
tcontainer_::layout_children();
assert(content_grid_);
content_grid_->layout_children();
}
void tscrollbar_container::child_populate_dirty_list(twindow& caller,
const std::vector<twidget*>& call_stack)
{

View file

@ -449,6 +449,9 @@ private:
*/
virtual void finalize_subclass() {}
/** Inherited from tcontainer_. */
void layout_children();
/** Inherited from tcontainer_. */
void impl_draw_children(surface& frame_buffer);

View file

@ -81,8 +81,6 @@ void ttree_view::child_populate_dirty_list(twindow& caller
// Inherited.
tscrollbar_container::child_populate_dirty_list(caller, call_stack);
layout_children(false);
assert(root_node_);
root_node_->impl_populate_dirty_list(caller, call_stack);
}
@ -92,6 +90,11 @@ bool ttree_view::empty() const
return root_node_->empty();
}
void ttree_view::layout_children()
{
layout_children(false);
}
void ttree_view::resize_content(
const int width_modification
, const int height_modification)

View file

@ -63,6 +63,9 @@ public:
bool empty() const;
/** Inherited from tscrollbar_container. */
void layout_children();
/***** ***** ***** setters / getters for members ***** ****** *****/
void set_indention_step_size(const unsigned indention_step_size)

View file

@ -444,10 +444,6 @@ void ttree_view_node::set_visible_area(const SDL_Rect& area)
void ttree_view_node::impl_draw_children(surface& frame_buffer)
{
if(is_root_node()) {
parent_widget_->layout_children(false);
}
grid_.draw_children(frame_buffer);
if(is_folded()) {

View file

@ -477,6 +477,16 @@ public:
*/
void draw_foreground(surface& frame_buffer);
/**
* Allows a widget to update its children.
*
* Before the window is populating the dirty list the widgets can update
* their content, which allows delayed initialization. This delayed
* initialization is only allowed if the widget resizes itself, not when
* being placed.
*/
virtual void layout_children() {}
/**
* Adds a widget to the dirty list if it is dirty.
*

View file

@ -545,7 +545,10 @@ void twindow::draw()
dirty_list_.push_back(std::vector<twidget*>(1, this));
} else {
// Find the widgets that are dirty.
// Let widgets update themselves, which might dirty some things.
layout_children();
// Now find the widgets that are dirty.
std::vector<twidget*> call_stack;
populate_dirty_list(*this, call_stack);
}