Skip to content

Commit

Permalink
GUI2/Scrollbar Container: manage content grid with a unique ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Aug 26, 2017
1 parent ca0a9b2 commit 74935c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/gui/widgets/scrollbar_container.cpp
Expand Up @@ -417,7 +417,7 @@ void scrollbar_container::place(const point& origin, const point& size)
vertical_scrollbar_mode_,
content_grid_->get_height(),
content_->get_height(),
content_grid_
content_grid_.get()
);

// Set horizontal scrollbar
Expand All @@ -427,7 +427,7 @@ void scrollbar_container::place(const point& origin, const point& size)
horizontal_scrollbar_mode_,
content_grid_->get_width(),
content_->get_width(),
content_grid_
content_grid_.get()
);

// Update the buttons.
Expand Down Expand Up @@ -766,7 +766,8 @@ void scrollbar_container::finalize_setup()
/***** Setup the content *****/
content_ = build_single_widget_instance<spacer>("spacer");

content_grid_ = dynamic_cast<grid*>(get_grid().swap_child("_content_grid", content_, true).release());
// TODO: possibly move this unique_ptr casting functionality to a helper function.
content_grid_.reset(dynamic_cast<grid*>(get_grid().swap_child("_content_grid", content_, true).release()));
assert(content_grid_);

content_grid_->set_parent(this);
Expand Down
7 changes: 3 additions & 4 deletions src/gui/widgets/scrollbar_container.hpp
Expand Up @@ -54,7 +54,6 @@ class scrollbar_container : public container_base

~scrollbar_container()
{
delete content_grid_;
}

/** The way to handle the showing or hiding of the scrollbar. */
Expand Down Expand Up @@ -160,12 +159,12 @@ class scrollbar_container : public container_base

grid* content_grid()
{
return content_grid_;
return content_grid_.get();
}

const grid* content_grid() const
{
return content_grid_;
return content_grid_.get();
}

const SDL_Rect& content_visible_area() const
Expand Down Expand Up @@ -479,7 +478,7 @@ class scrollbar_container : public container_base
scrollbar_base *vertical_scrollbar_, *horizontal_scrollbar_;

/** The grid that holds the content. */
grid* content_grid_;
std::unique_ptr<grid> content_grid_;

/** Dummy spacer to hold the contents location. */
spacer* content_;
Expand Down

0 comments on commit 74935c4

Please sign in to comment.