psemek/libs/ui/source/toggle_button.cpp

44 lines
774 B
C++

#include <psemek/ui/toggle_button.hpp>
namespace psemek::ui
{
element::children_range toggle_button::children() const
{
return children_range{children_};
}
toggle_button::~toggle_button()
{
release_children();
}
void toggle_button::set_label(std::shared_ptr<struct label> label)
{
if (icon())
set_icon(nullptr);
if (label_) label_->set_parent(nullptr);
label_ = std::move(label);
children_[0] = label_.get();
if (label_) label_->set_parent(this);
}
void toggle_button::set_icon(std::shared_ptr<image_view> icon)
{
if (label())
set_label(nullptr);
if (icon_) icon_->set_parent(nullptr);
icon_ = std::move(icon);
children_[0] = icon_.get();
if (icon_)
{
icon_->set_parent(this);
icon_->set_downscale(false);
}
}
}