separate widget interface-implementation
This commit is contained in:
parent
9e6e0a1d4c
commit
bb934d4f86
|
@ -5,14 +5,14 @@
|
|||
|
||||
#include <basic_widgets/core/math.hpp>
|
||||
#include <basic_widgets/core/renderer.hpp>
|
||||
#include <basic_widgets/w/base/widget.hpp>
|
||||
#include <basic_widgets/w/base/widget_impl.hpp>
|
||||
|
||||
using bwidgets::Color;
|
||||
using bwidgets::rect_margin;
|
||||
using bwidgets::Size;
|
||||
using bwidgets::Widget;
|
||||
using bwidgets::WidgetImpl;
|
||||
|
||||
class Example final : public Widget
|
||||
class Example final : public WidgetImpl
|
||||
{
|
||||
void _handle_geometry_change(const SDL_Rect& vp) noexcept override
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ public:
|
|||
unsigned int cycle_g {3500}; // NOLINT(readability-magic-numbers)
|
||||
unsigned int cycle_b {3500}; // NOLINT(readability-magic-numbers)
|
||||
|
||||
using Widget::Widget;
|
||||
using WidgetImpl::WidgetImpl;
|
||||
Example(Example&&) = delete;
|
||||
Example(const Example&) = delete;
|
||||
auto operator=(Example&&) = delete;
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace bwidgets
|
|||
{
|
||||
|
||||
template<typename T>
|
||||
class Input : public Widget,
|
||||
class Input : public WidgetImpl,
|
||||
public FontHandler,
|
||||
public KeyboardHandlerImpl,
|
||||
public MouseHandlerImpl
|
||||
|
@ -28,7 +28,7 @@ namespace bwidgets
|
|||
protected:
|
||||
Caption _input_caption;
|
||||
|
||||
Input(Widget* parent = nullptr) : Widget {parent}, _input_caption {this}
|
||||
Input(Widget* parent = nullptr) : WidgetImpl {parent}, _input_caption {this}
|
||||
{
|
||||
FocusHandlerImpl::focus_handler([this](bool focus) {
|
||||
if (focus) {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include <basic_widgets/core/type/size.hpp>
|
||||
#include <basic_widgets/w/base/widget.hpp>
|
||||
#include <basic_widgets/w/base/widget_impl.hpp>
|
||||
|
||||
namespace bwidgets
|
||||
{
|
||||
|
@ -14,7 +14,7 @@ namespace bwidgets
|
|||
|
||||
namespace bwidgets
|
||||
{
|
||||
class Layout : public Widget
|
||||
class Layout : public WidgetImpl
|
||||
{
|
||||
protected:
|
||||
std::vector<std::unique_ptr<Widget>> _widgets;
|
||||
|
@ -30,7 +30,7 @@ namespace bwidgets
|
|||
|
||||
Size margins = default_margins;
|
||||
|
||||
using Widget::Widget;
|
||||
using WidgetImpl::WidgetImpl;
|
||||
|
||||
Layout(const Layout&) = delete;
|
||||
Layout(Layout&&) = delete;
|
||||
|
|
|
@ -15,15 +15,6 @@ namespace bwidgets
|
|||
{
|
||||
class Widget : public virtual EventHandlerImpl
|
||||
{
|
||||
protected:
|
||||
std::shared_ptr<Renderer> _renderer;
|
||||
SDL_Rect _viewport {0, 0, 0, 0};
|
||||
SDL_Rect _widget_area {0, 0, 0, 0};
|
||||
|
||||
virtual void _handle_geometry_change(const SDL_Rect&) = 0;
|
||||
virtual void _handle_renderer_change(const std::shared_ptr<Renderer>&) {}
|
||||
virtual void _handle_rendering() = 0;
|
||||
|
||||
public:
|
||||
Widget* parent;
|
||||
|
||||
|
@ -31,10 +22,10 @@ namespace bwidgets
|
|||
|
||||
[[nodiscard]] virtual auto size() const noexcept -> Size = 0;
|
||||
|
||||
virtual auto render() -> Widget* final;
|
||||
virtual auto renderer(std::shared_ptr<Renderer>) -> Widget* final;
|
||||
virtual auto viewport(const SDL_Rect&) -> Widget* final;
|
||||
[[nodiscard]] virtual auto viewport() const -> const SDL_Rect& final;
|
||||
virtual void render() = 0;
|
||||
virtual void renderer(std::shared_ptr<Renderer>) = 0;
|
||||
virtual void viewport(const SDL_Rect&) = 0;
|
||||
[[nodiscard]] virtual auto viewport() const -> const SDL_Rect& = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef BWIDGETS_WIDGET_IMPL_HPP
|
||||
#define BWIDGETS_WIDGET_IMPL_HPP
|
||||
|
||||
#include <basic_widgets/w/base/widget.hpp>
|
||||
|
||||
namespace bwidgets
|
||||
{
|
||||
class WidgetImpl : public virtual Widget
|
||||
{
|
||||
public:
|
||||
void render() override;
|
||||
void renderer(std::shared_ptr<Renderer>) override;
|
||||
void viewport(const SDL_Rect&) override;
|
||||
[[nodiscard]] auto viewport() const -> const SDL_Rect& override;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Renderer> _renderer;
|
||||
SDL_Rect _viewport {0, 0, 0, 0};
|
||||
SDL_Rect _widget_area {0, 0, 0, 0};
|
||||
|
||||
using Widget::Widget;
|
||||
|
||||
virtual void _handle_geometry_change(const SDL_Rect&) = 0;
|
||||
virtual void _handle_renderer_change(const std::shared_ptr<Renderer>&) {}
|
||||
virtual void _handle_rendering() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
namespace bwidgets
|
||||
{
|
||||
class Button : public virtual Widget,
|
||||
class Button : public virtual WidgetImpl,
|
||||
public virtual FontHandler,
|
||||
public virtual MouseHandlerImpl
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ namespace bwidgets
|
|||
using FocusHandlerImpl::focus;
|
||||
using FocusHandlerImpl::focus_handler;
|
||||
|
||||
Button(Widget* parent = nullptr) noexcept;
|
||||
Button(WidgetImpl* parent = nullptr) noexcept;
|
||||
Button(const Button&) = delete;
|
||||
Button(Button&&) = delete;
|
||||
~Button() override = default;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <basic_widgets/core/texture.hpp>
|
||||
#include <basic_widgets/core/type/size.hpp>
|
||||
#include <basic_widgets/w/base/widget.hpp>
|
||||
#include <basic_widgets/w/base/widget_impl.hpp>
|
||||
#include <basic_widgets/w/feat/font_handler.hpp>
|
||||
#include <basic_widgets/w/feat/texture_handler.hpp>
|
||||
|
||||
|
@ -11,7 +11,7 @@ struct SDL_Surface;
|
|||
|
||||
namespace bwidgets
|
||||
{
|
||||
class Caption : public Widget,
|
||||
class Caption : public WidgetImpl,
|
||||
public FontHandler,
|
||||
public TextureHandler
|
||||
{
|
||||
|
@ -43,7 +43,7 @@ namespace bwidgets
|
|||
Alignment alignment {Alignment::LEFT};
|
||||
Size margins {3, 3};
|
||||
|
||||
Caption(Widget* parent = nullptr) noexcept;
|
||||
Caption(WidgetImpl* parent = nullptr) noexcept;
|
||||
Caption(const Caption&) = delete;
|
||||
Caption(Caption&&) = delete;
|
||||
~Caption() override = default;
|
||||
|
|
|
@ -47,19 +47,19 @@ namespace bwidgets
|
|||
const int spacing = center_line(button_area_width, widest_button);
|
||||
const int field_width = vp.w - 2 * button_area_width;
|
||||
|
||||
Widget::_widget_area.x = Widget::_widget_area.x + button_area_width;
|
||||
Widget::_widget_area.w = field_width;
|
||||
WidgetImpl::_widget_area.x = WidgetImpl::_widget_area.x + button_area_width;
|
||||
WidgetImpl::_widget_area.w = field_width;
|
||||
|
||||
Input<T>::_input_caption.viewport(
|
||||
rect_offset(rect_margin(Widget::_widget_area,
|
||||
rect_offset(rect_margin(WidgetImpl::_widget_area,
|
||||
{Input<T>::border_width, Input<T>::border_width}),
|
||||
vp));
|
||||
_decrement_button_area = {spacing, Widget::_widget_area.y,
|
||||
_decrement_button_area = {spacing, WidgetImpl::_widget_area.y,
|
||||
_decrement_button.size().w,
|
||||
_decrement_button.size().h};
|
||||
|
||||
_increment_button_area = {vp.w - spacing - _increment_button.size().w,
|
||||
Widget::_widget_area.y, _increment_button.size().w,
|
||||
WidgetImpl::_widget_area.y, _increment_button.size().w,
|
||||
_increment_button.size().h};
|
||||
|
||||
_increment_button.viewport(rect_offset(_increment_button_area, vp));
|
||||
|
@ -83,7 +83,7 @@ namespace bwidgets
|
|||
public:
|
||||
T button_step = 1;
|
||||
|
||||
NumericInput(Widget* parent = nullptr)
|
||||
NumericInput(WidgetImpl* parent = nullptr)
|
||||
: Input<T>(parent), _increment_button(this), _decrement_button(this)
|
||||
{
|
||||
Input<T>::_input_caption.alignment = Caption::Alignment::RIGHT;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include <basic_widgets/w/base/widget.hpp>
|
||||
#include <basic_widgets/w/base/widget_impl.hpp>
|
||||
|
||||
using namespace bwidgets;
|
||||
|
||||
auto Widget::render() -> Widget*
|
||||
void WidgetImpl::render()
|
||||
{
|
||||
if (_renderer == nullptr) return this;
|
||||
if (_renderer == nullptr) return;
|
||||
|
||||
#ifdef BWIDGETS_DEBUG
|
||||
_renderer
|
||||
|
@ -17,27 +17,23 @@ auto Widget::render() -> Widget*
|
|||
|
||||
_renderer->viewport(_viewport);
|
||||
_handle_rendering();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
auto Widget::renderer(std::shared_ptr<Renderer> r) -> Widget*
|
||||
void WidgetImpl::renderer(std::shared_ptr<Renderer> r)
|
||||
{
|
||||
if (r != _renderer) {
|
||||
_handle_renderer_change(r);
|
||||
_renderer = r;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
auto Widget::viewport(const SDL_Rect& vp) -> Widget*
|
||||
void WidgetImpl::viewport(const SDL_Rect& vp)
|
||||
{
|
||||
_handle_geometry_change(vp);
|
||||
_viewport = vp;
|
||||
return this;
|
||||
}
|
||||
|
||||
auto Widget::viewport() const -> const SDL_Rect&
|
||||
auto WidgetImpl::viewport() const -> const SDL_Rect&
|
||||
{
|
||||
return _viewport;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ const Color Button::default_color_bg {150, 150, 150, SDL_ALPHA_OPAQUE};
|
|||
const Color Button::default_color_bg_hover {175, 175, 175, SDL_ALPHA_OPAQUE};
|
||||
const Color Button::default_color_fg {0, 0, 0, SDL_ALPHA_OPAQUE};
|
||||
|
||||
Button::Button(Widget* parent) noexcept : Widget {parent}, _caption {this}
|
||||
Button::Button(WidgetImpl* parent) noexcept : WidgetImpl {parent}, _caption {this}
|
||||
{
|
||||
enable_mouse_handler(&_widget_area, &_viewport);
|
||||
_caption.alignment = Caption::Alignment::CENTER;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
using namespace bwidgets;
|
||||
|
||||
Caption::Caption(Widget* parent) noexcept : Widget {parent}
|
||||
Caption::Caption(WidgetImpl* parent) noexcept : WidgetImpl {parent}
|
||||
{
|
||||
_font_color_bg = default_font_color_bg;
|
||||
_font_color_fg = default_font_color_fg;
|
||||
|
|
Loading…
Reference in New Issue