bwidgets/inc/basic_widgets/w/base/widget.hpp

40 lines
1.2 KiB
C++
Raw Normal View History

2021-08-06 14:22:56 +02:00
#ifndef BWIDGETS_WIDGET_HPP
#define BWIDGETS_WIDGET_HPP
2021-06-03 19:14:02 +02:00
2021-08-10 23:48:19 +02:00
#include <memory>
#include <basic_widgets/core/renderer.hpp>
#include <basic_widgets/core/type/size.hpp>
2021-08-17 17:59:34 +02:00
#include <basic_widgets/w/feat/event_handler.hpp>
2021-06-03 19:14:02 +02:00
union SDL_Event;
2021-07-16 17:18:13 +02:00
2021-07-10 19:55:53 +02:00
struct SDL_Renderer;
2021-08-06 14:22:56 +02:00
namespace bwidgets
2021-06-03 19:14:02 +02:00
{
2021-08-17 17:59:34 +02:00
class Widget : public virtual EventHandler
2021-06-13 15:44:11 +02:00
{
public:
2021-08-23 23:50:14 +02:00
// Parent widget for bidirectional message passing between widgets.
2021-08-27 01:21:25 +02:00
// Currently not used by this lib.
Widget* parent;
2021-08-15 20:04:53 +02:00
explicit Widget(Widget* p = nullptr) noexcept : parent {p} {}
2021-08-06 14:22:56 +02:00
2021-08-23 23:50:14 +02:00
// Render widget on current renderer target.
virtual void render() = 0;
2021-08-23 23:50:14 +02:00
// Set widget renderer.
virtual void renderer(std::shared_ptr<Renderer>) = 0;
2021-08-23 23:50:14 +02:00
// Get prefered or minimal widget size.
[[nodiscard]] virtual auto size() const noexcept -> Size = 0;
2021-08-27 01:21:25 +02:00
// Set the viewport delimiting the widget rendering area and the origin
2021-08-23 23:50:14 +02:00
// for relative coordinates.
virtual void viewport(const SDL_Rect&) = 0;
2021-08-23 23:50:14 +02:00
// Get current viewport.
[[nodiscard]] virtual auto viewport() const -> const SDL_Rect& = 0;
2021-07-10 19:55:53 +02:00
};
}
2021-06-03 19:14:02 +02:00
#endif