Remove style from element factory

This commit is contained in:
Nikita Lisitsa 2021-02-27 10:57:30 +03:00
parent 539799814e
commit 226b862e95
3 changed files with 7 additions and 37 deletions

View file

@ -41,9 +41,9 @@ struct ui_example
auto style = std::make_shared<ui::style>();
style->font = ui::make_default_9x12_font();
style->text_scale = 2;
element_factory.set_style(style);
auto screen = element_factory.make_screen();
screen->set_style(style);
auto grid = element_factory.make_grid_layout();
grid->set_size(1, 1);

View file

@ -17,9 +17,6 @@ namespace psemek::ui
default_element_factory();
~default_element_factory();
void set_style(std::shared_ptr<struct style> st);
std::shared_ptr<struct style> style() const;
std::shared_ptr<button> make_button(std::string text);
std::shared_ptr<label> make_label(std::string text);
std::shared_ptr<frame> make_frame();

View file

@ -140,23 +140,7 @@ namespace psemek::ui
}
struct default_element_factory::impl
{
std::shared_ptr<struct style> style;
impl();
template <typename T>
std::shared_ptr<T> create()
{
auto r = std::make_shared<T>();
r->set_style(style);
return r;
}
};
default_element_factory::impl::impl()
: style{std::make_shared<struct style>()}
{}
{};
default_element_factory::default_element_factory()
: pimpl_{make_impl()}
@ -164,44 +148,33 @@ namespace psemek::ui
default_element_factory::~default_element_factory() = default;
void default_element_factory::set_style(std::shared_ptr<struct style> st)
{
impl().style = st;
}
std::shared_ptr<struct style> default_element_factory::style() const
{
return impl().style;
}
std::shared_ptr<button> default_element_factory::make_button(std::string text)
{
auto r = impl().create<button_impl>();
auto r = std::make_shared<button_impl>();
r->label()->set_text(std::move(text));
r->label()->set_style(impl().style);
return r;
}
std::shared_ptr<label> default_element_factory::make_label(std::string text)
{
auto r = impl().create<label>();
auto r = std::make_shared<label>();
r->set_text(text);
return r;
}
std::shared_ptr<frame> default_element_factory::make_frame()
{
return impl().create<frame_impl>();
return std::make_shared<frame_impl>();
}
std::shared_ptr<screen> default_element_factory::make_screen()
{
return impl().create<screen>();
return std::make_shared<screen>();
}
std::shared_ptr<grid_layout> default_element_factory::make_grid_layout()
{
return impl().create<grid_layout>();
return std::make_shared<grid_layout>();
}
}