Add ui::element_factory interface
This commit is contained in:
parent
a362dafee3
commit
336bdde8d2
4 changed files with 63 additions and 25 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <psemek/ui/style.hpp>
|
#include <psemek/ui/element_factory.hpp>
|
||||||
|
|
||||||
#include <psemek/ui/button.hpp>
|
#include <psemek/ui/button.hpp>
|
||||||
#include <psemek/ui/label.hpp>
|
#include <psemek/ui/label.hpp>
|
||||||
#include <psemek/ui/frame.hpp>
|
#include <psemek/ui/frame.hpp>
|
||||||
|
|
@ -16,17 +17,15 @@ namespace psemek::ui
|
||||||
{
|
{
|
||||||
|
|
||||||
struct default_element_factory
|
struct default_element_factory
|
||||||
|
: element_factory
|
||||||
{
|
{
|
||||||
default_element_factory();
|
default_element_factory();
|
||||||
~default_element_factory();
|
~default_element_factory();
|
||||||
|
|
||||||
std::shared_ptr<button> make_button(std::string text);
|
std::shared_ptr<button> make_button(std::string text) override;
|
||||||
std::shared_ptr<button> make_button(std::shared_ptr<gfx::texture_2d> icon);
|
std::shared_ptr<button> make_button(std::shared_ptr<gfx::texture_2d> icon) override;
|
||||||
std::shared_ptr<label> make_label(std::string text);
|
std::shared_ptr<frame> make_frame() override;
|
||||||
std::shared_ptr<frame> make_frame();
|
std::shared_ptr<window> make_window(std::string caption) override;
|
||||||
std::shared_ptr<window> make_window(std::string caption);
|
|
||||||
std::shared_ptr<screen> make_screen();
|
|
||||||
std::shared_ptr<grid_layout> make_grid_layout();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
psemek_declare_pimpl
|
psemek_declare_pimpl
|
||||||
|
|
|
||||||
28
libs/ui/include/psemek/ui/element_factory.hpp
Normal file
28
libs/ui/include/psemek/ui/element_factory.hpp
Normal 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() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -351,13 +351,6 @@ namespace psemek::ui
|
||||||
return std::make_shared<button_impl>(std::move(icon));
|
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()
|
std::shared_ptr<frame> default_element_factory::make_frame()
|
||||||
{
|
{
|
||||||
return std::make_shared<frame_impl>();
|
return std::make_shared<frame_impl>();
|
||||||
|
|
@ -371,14 +364,4 @@ namespace psemek::ui
|
||||||
return r;
|
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>();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
libs/ui/source/element_factory.cpp
Normal file
28
libs/ui/source/element_factory.cpp
Normal 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>();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue