#include #include namespace psemek::ui { namespace { struct button_impl : button { struct shape const & shape() const override { return shape_; } void reshape(geom::box const & bbox) override { shape_.box = bbox; } void draw(painter & p) const override { auto s = style(); if (!s) return; if (s->shadow_offset != geom::vector{0, 0}) p.draw_rect(shape_.box + geom::cast(s->shadow_offset), s->shadow_color); if (s->border_width > 0) p.draw_rect(shape_.box, s->border_color); gfx::color_rgba color = s->fg_color; if (state() == state_t::mouseover) color = s->highlight_color; else if (state() == state_t::mousedown) color = s->action_color; p.draw_rect(geom::shrink(shape_.box, 1.f * s->border_width), color); } geom::box 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 style; impl(); template std::unique_ptr create() { auto r = std::make_unique(); r->set_style(style); return r; } }; default_element_factory::impl::impl() : style{std::make_shared()} {} default_element_factory::default_element_factory() : pimpl_{make_impl()} {} default_element_factory::~default_element_factory() = default; void default_element_factory::set_style(std::shared_ptr st) { impl().style = st; } std::shared_ptr default_element_factory::style() const { return impl().style; } std::unique_ptr