Add ui::element_factory interface

This commit is contained in:
Nikita Lisitsa 2021-03-03 12:25:04 +03:00
parent a362dafee3
commit 336bdde8d2
4 changed files with 63 additions and 25 deletions

View file

@ -1,6 +1,7 @@
#pragma once
#include <psemek/ui/style.hpp>
#include <psemek/ui/element_factory.hpp>
#include <psemek/ui/button.hpp>
#include <psemek/ui/label.hpp>
#include <psemek/ui/frame.hpp>
@ -16,17 +17,15 @@ namespace psemek::ui
{
struct default_element_factory
: element_factory
{
default_element_factory();
~default_element_factory();
std::shared_ptr<button> make_button(std::string text);
std::shared_ptr<button> make_button(std::shared_ptr<gfx::texture_2d> icon);
std::shared_ptr<label> make_label(std::string text);
std::shared_ptr<frame> make_frame();
std::shared_ptr<window> make_window(std::string caption);
std::shared_ptr<screen> make_screen();
std::shared_ptr<grid_layout> make_grid_layout();
std::shared_ptr<button> make_button(std::string text) override;
std::shared_ptr<button> make_button(std::shared_ptr<gfx::texture_2d> icon) override;
std::shared_ptr<frame> make_frame() override;
std::shared_ptr<window> make_window(std::string caption) override;
private:
psemek_declare_pimpl

View file

@ -0,0 +1,28 @@
#pragma once
#include <psemek/ui/button.hpp>
#include <psemek/ui/label.hpp>
#include <psemek/ui/frame.hpp>
#include <psemek/ui/window.hpp>
#include <psemek/ui/screen.hpp>
#include <psemek/ui/grid_layout.hpp>
#include <psemek/gfx/texture.hpp>
namespace psemek::ui
{
struct element_factory
{
virtual std::shared_ptr<button> make_button(std::string text);
virtual std::shared_ptr<button> make_button(std::shared_ptr<gfx::texture_2d> icon);
virtual std::shared_ptr<label> make_label(std::string text);
virtual std::shared_ptr<frame> make_frame();
virtual std::shared_ptr<window> make_window(std::string caption);
virtual std::shared_ptr<screen> make_screen();
virtual std::shared_ptr<grid_layout> make_grid_layout();
virtual ~element_factory() {}
};
}

View file

@ -351,13 +351,6 @@ namespace psemek::ui
return std::make_shared<button_impl>(std::move(icon));
}
std::shared_ptr<label> default_element_factory::make_label(std::string text)
{
auto r = std::make_shared<label>();
r->set_text(text);
return r;
}
std::shared_ptr<frame> default_element_factory::make_frame()
{
return std::make_shared<frame_impl>();
@ -371,14 +364,4 @@ namespace psemek::ui
return r;
}
std::shared_ptr<screen> default_element_factory::make_screen()
{
return std::make_shared<screen>();
}
std::shared_ptr<grid_layout> default_element_factory::make_grid_layout()
{
return std::make_shared<grid_layout>();
}
}

View file

@ -0,0 +1,28 @@
#include <psemek/ui/element_factory.hpp>
namespace psemek::ui
{
std::shared_ptr<button> element_factory::make_button(std::string) { return nullptr; }
std::shared_ptr<button> element_factory::make_button(std::shared_ptr<gfx::texture_2d>) { return nullptr; }
std::shared_ptr<label> element_factory::make_label(std::string text)
{
return std::make_shared<label>(std::move(text));
}
std::shared_ptr<frame> element_factory::make_frame() { return nullptr; }
std::shared_ptr<window> element_factory::make_window(std::string) { return nullptr; }
std::shared_ptr<screen> element_factory::make_screen()
{
return std::make_shared<screen>();
}
std::shared_ptr<grid_layout> element_factory::make_grid_layout()
{
return std::make_shared<grid_layout>();
}
}