bwidgets/inc/basic_widgets/w/button.hpp

56 lines
1.8 KiB
C++
Raw Normal View History

2021-08-06 14:22:56 +02:00
#ifndef BWIDGETS_BUTTON_HPP
#define BWIDGETS_BUTTON_HPP
#include <functional>
#include <string>
2021-08-06 14:22:56 +02:00
#include <basic_widgets/core/type/color.hpp>
#include <basic_widgets/w/caption.hpp>
#include <basic_widgets/w/feat/mouse_handler.hpp>
2021-08-06 14:22:56 +02:00
namespace bwidgets
{
class Button : public Widget,
public FontHandler,
public MouseHandler
{
protected:
2021-08-06 14:22:56 +02:00
Caption _caption;
SDL_Rect _caption_area {};
Color _color_foreground = default_color_fg;
void _handle_focus_change(bool) override {}
2021-08-10 23:48:19 +02:00
void _handle_font_change(const std::shared_ptr<Font>&) override;
2021-08-14 16:37:02 +02:00
void _handle_font_color_change(Color, Color)
override;
2021-08-08 16:00:22 +02:00
void _handle_geometry_change(const SDL_Rect&) override;
2021-08-10 23:48:19 +02:00
void _handle_renderer_change(const std::shared_ptr<Renderer>&) override;
void _handle_rendering() override;
void _on_push(bool) override;
public:
static const Color default_color_bg;
static const Color default_color_bg_hover;
static const Color default_color_fg;
2021-08-06 14:22:56 +02:00
std::function<Color(int, int, float)> border_gradient;
2021-08-14 16:37:02 +02:00
Size border_size {3, 3};
Color color_bg = default_color_bg;
Color color_bg_hover = default_color_bg_hover;
2021-08-08 16:00:22 +02:00
Button(Widget* parent = nullptr) noexcept;
Button(const Button&) = delete;
2021-08-14 09:25:28 +02:00
Button(Button&&) = delete;
~Button() override = default;
auto operator=(const Button&) = delete;
auto operator=(Button&&) = delete;
2021-08-06 14:22:56 +02:00
[[nodiscard]] auto size() const noexcept -> Size override;
[[nodiscard]] virtual auto text() const noexcept -> const std::string&;
virtual auto text(const std::string&) -> Button*;
};
}
#endif