Add ui::container_impl::empty and resize
This commit is contained in:
parent
390df41f30
commit
e3ab6d42b6
2 changed files with 22 additions and 7 deletions
|
|
@ -15,12 +15,14 @@ namespace psemek::ui
|
|||
|
||||
element::children_range children() const;
|
||||
|
||||
bool empty() const;
|
||||
std::size_t size() const;
|
||||
void resize(std::size_t new_size);
|
||||
|
||||
std::size_t add(std::shared_ptr<element> c);
|
||||
void add(std::shared_ptr<element> c, std::size_t index);
|
||||
|
||||
element * get(std::size_t index) const;
|
||||
std::shared_ptr<element> get(std::size_t index) const;
|
||||
std::optional<std::size_t> find(element * c) const;
|
||||
|
||||
std::shared_ptr<element> remove(element * c);
|
||||
|
|
|
|||
|
|
@ -8,11 +8,27 @@ namespace psemek::ui
|
|||
return element::children_range{children_range_.data(), children_range_.data() + children_range_.size()};
|
||||
}
|
||||
|
||||
bool container_impl::empty() const
|
||||
{
|
||||
return children_.empty();
|
||||
}
|
||||
|
||||
std::size_t container_impl::size() const
|
||||
{
|
||||
return children_.size();
|
||||
}
|
||||
|
||||
void container_impl::resize(std::size_t new_size)
|
||||
{
|
||||
auto old_size = children_.size();
|
||||
for (std::size_t i = new_size; i < old_size; ++i)
|
||||
remove(i);
|
||||
children_.resize(new_size);
|
||||
children_range_.resize(new_size);
|
||||
for (std::size_t i = old_size; i < new_size; ++i)
|
||||
children_range_[i] = nullptr;
|
||||
}
|
||||
|
||||
std::size_t container_impl::add(std::shared_ptr<element> c)
|
||||
{
|
||||
std::size_t index = 0;
|
||||
|
|
@ -24,20 +40,17 @@ namespace psemek::ui
|
|||
void container_impl::add(std::shared_ptr<element> c, std::size_t index)
|
||||
{
|
||||
if (index >= children_.size())
|
||||
{
|
||||
children_.resize(index + 1);
|
||||
children_range_.resize(index + 1);
|
||||
}
|
||||
resize(index + 1);
|
||||
|
||||
children_[index] = std::move(c);
|
||||
if (children_[index]) children_[index]->set_parent(parent_);
|
||||
children_range_[index] = children_[index].get();
|
||||
}
|
||||
|
||||
element * container_impl::get(std::size_t index) const
|
||||
std::shared_ptr<element> container_impl::get(std::size_t index) const
|
||||
{
|
||||
if (index < children_.size())
|
||||
return children_[index].get();
|
||||
return children_[index];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue