2021-08-06 14:22:56 +02:00
|
|
|
#ifndef BWIDGETS_BUTTON_HPP
|
|
|
|
#define BWIDGETS_BUTTON_HPP
|
2021-07-18 18:26:12 +02:00
|
|
|
|
2021-08-01 11:12:54 +02:00
|
|
|
#include <functional>
|
2021-07-18 18:26:12 +02:00
|
|
|
#include <string>
|
|
|
|
|
2021-08-06 14:22:56 +02:00
|
|
|
#include <basic_widgets/core/type/color.hpp>
|
2021-07-18 18:26:12 +02:00
|
|
|
#include <basic_widgets/w/caption.hpp>
|
|
|
|
#include <basic_widgets/w/feat/mouse_handler.hpp>
|
|
|
|
|
2021-08-06 14:22:56 +02:00
|
|
|
namespace bwidgets
|
2021-07-18 18:26:12 +02:00
|
|
|
{
|
2021-07-29 16:06:03 +02:00
|
|
|
class Button : public Widget,
|
|
|
|
public FontHandler,
|
|
|
|
public MouseHandler
|
2021-07-18 18:26:12 +02:00
|
|
|
{
|
2021-07-29 16:06:03 +02:00
|
|
|
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-06 14:22:56 +02:00
|
|
|
void _handle_font_color_change(const Color&, const 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;
|
2021-07-30 20:41:47 +02:00
|
|
|
void _handle_rendering() override;
|
2021-08-01 11:12:54 +02:00
|
|
|
void _on_push(bool) override;
|
2021-07-29 16:06:03 +02:00
|
|
|
|
|
|
|
public:
|
2021-08-12 16:04:02 +02:00
|
|
|
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
|
|
|
|
2021-08-14 10:20:00 +02:00
|
|
|
std::function<Color(int, int, float)> border_gradient;
|
2021-08-06 14:22:56 +02:00
|
|
|
Size border_size {3, 3};
|
|
|
|
Color color_bg = default_color_bg;
|
|
|
|
Color color_bg_hover = default_color_bg_hover;
|
2021-07-29 16:06:03 +02:00
|
|
|
|
2021-08-08 16:00:22 +02:00
|
|
|
Button(Widget* parent = nullptr) noexcept;
|
2021-08-12 23:50:22 +02:00
|
|
|
Button(const Button&) = delete;
|
2021-08-14 09:25:28 +02:00
|
|
|
Button(Button&&) = delete;
|
|
|
|
~Button() override = default;
|
2021-08-12 23:50:22 +02:00
|
|
|
auto operator=(const Button&) = delete;
|
|
|
|
auto operator=(Button&&) = delete;
|
2021-07-29 16:06:03 +02:00
|
|
|
|
2021-08-06 14:22:56 +02:00
|
|
|
[[nodiscard]] auto size() const noexcept -> Size override;
|
|
|
|
|
2021-07-30 20:41:47 +02:00
|
|
|
[[nodiscard]] virtual auto text() const noexcept -> const std::string&;
|
|
|
|
virtual auto text(const std::string&) -> Button*;
|
2021-07-18 18:26:12 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|