bwidgets/inc/basic_widgets/w/caption.hpp

62 lines
2 KiB
C++

#ifndef BWIDGETS_CAPTION_HPP
#define BWIDGETS_CAPTION_HPP
#include <basic_widgets/core/texture.hpp>
#include <basic_widgets/core/type/size.hpp>
#include <basic_widgets/w/base/widget.hpp>
#include <basic_widgets/w/feat/font_handler.hpp>
#include <basic_widgets/w/feat/texture_handler.hpp>
struct SDL_Surface;
namespace bwidgets
{
class Caption : public Widget,
public FontHandler,
public TextureHandler
{
protected:
Font::RenderMode _render_mode {Font::RenderMode::SHADED};
std::string _text;
std::shared_ptr<Texture> _text_texture {nullptr};
void _handle_font_change(const std::shared_ptr<Font>&) override;
void _handle_font_color_change(Color, Color)
override;
void _handle_geometry_change(const SDL_Rect&) override;
void _handle_renderer_change(const std::shared_ptr<Renderer>&) override;
void _handle_rendering() override;
void _handle_texture_update() override;
public:
enum struct Alignment
{
CENTER,
LEFT,
RIGHT
};
inline static const Color default_color_bg = {255, 255, 255, SDL_ALPHA_OPAQUE};
inline static const Color default_color_fg = {0, 0, 0, SDL_ALPHA_OPAQUE};
inline static const Size default_margins = {3, 3};
Alignment alignment {Alignment::LEFT};
Size margins {3, 3};
Caption(Widget* parent = nullptr) noexcept;
Caption(const Caption&) = delete;
Caption(Caption&&) = delete;
~Caption() override = default;
auto operator=(const Caption&) = delete;
auto operator=(Caption&&) = delete;
virtual auto render_mode(Font::RenderMode) -> Caption*;
[[nodiscard]] virtual auto text() const noexcept -> const std::string&;
virtual auto text(const std::string&) -> Caption*;
[[nodiscard]] auto size() const noexcept -> Size override;
};
}
#endif