76 lines
1.4 KiB
C++
76 lines
1.4 KiB
C++
#include <psemek/ui/default_element_factory.hpp>
|
|
|
|
#include <psemek/ui/box_shape.hpp>
|
|
|
|
namespace psemek::ui
|
|
{
|
|
|
|
namespace
|
|
{
|
|
|
|
struct button_impl
|
|
: button
|
|
{
|
|
struct shape const & shape() const override
|
|
{
|
|
return shape_;
|
|
}
|
|
|
|
void reshape(geom::box<float, 2> const & bbox) override
|
|
{
|
|
shape_.box = bbox;
|
|
}
|
|
|
|
void draw(painter & p) const override
|
|
{
|
|
gfx::color_rgba color = gfx::red;
|
|
if (state() == state_t::mouseover)
|
|
color = gfx::light(color);
|
|
else if (state() == state_t::mousedown)
|
|
color = gfx::dark(color);
|
|
p.draw_rect(shape_.box, color);
|
|
}
|
|
|
|
geom::box<float, 2> size_constraints() const override
|
|
{
|
|
return {{{100.f, 200.f}, {50.f, 100.f}}};
|
|
}
|
|
|
|
private:
|
|
box_shape shape_{{{{0.f, 0.f}, {0.f, 0.f}}}};
|
|
};
|
|
|
|
}
|
|
|
|
struct default_element_factory::impl
|
|
{
|
|
std::shared_ptr<struct font> font;
|
|
};
|
|
|
|
default_element_factory::default_element_factory()
|
|
: pimpl_{make_impl()}
|
|
{}
|
|
|
|
default_element_factory::~default_element_factory() = default;
|
|
|
|
void default_element_factory::set_font(std::shared_ptr<struct font> f)
|
|
{
|
|
impl().font = std::move(f);
|
|
}
|
|
|
|
std::shared_ptr<struct font> default_element_factory::font() const
|
|
{
|
|
return impl().font;
|
|
}
|
|
|
|
std::unique_ptr<button> default_element_factory::make_button()
|
|
{
|
|
return std::make_unique<button_impl>();
|
|
}
|
|
|
|
std::unique_ptr<screen> default_element_factory::make_screen()
|
|
{
|
|
return std::make_unique<screen>();
|
|
}
|
|
|
|
}
|