bwidgets/inc/basic_widgets/w/button.hpp

52 lines
1.8 KiB
C++

#ifndef BWIDGETS_BUTTON_HPP
#define BWIDGETS_BUTTON_HPP
#include <functional>
#include <string>
#include <basic_widgets/core/type/color.hpp>
#include <basic_widgets/w/caption.hpp>
#include <basic_widgets/w/feat/mouse_handler.hpp>
namespace bwidgets
{
class Button : public Widget,
public FontHandler,
public MouseHandler
{
protected:
Caption _caption;
SDL_Rect _caption_area {};
Color _color_foreground = default_color_fg;
void _handle_focus_change(bool) override {}
void _handle_font_change(Font*) override;
void _handle_font_color_change(const Color&, const Color&) override;
void _handle_geometry_change(const SDL_Rect&) noexcept override;
void _handle_renderer_change(Renderer*) override;
void _handle_rendering() override;
void _on_push(bool) override;
public:
inline static const Color default_color_bg {150, 150, 150, SDL_ALPHA_OPAQUE};
inline static const Color default_color_bg_hover {175, 175, 175,
SDL_ALPHA_OPAQUE};
inline static const Color default_color_fg {0, 0, 0, SDL_ALPHA_OPAQUE};
std::function<Color(int, int)> border_gradient;
std::function<Color(int, int)> border_gradient_pushed;
Size border_size {3, 3};
Color color_bg = default_color_bg;
Color color_bg_hover = default_color_bg_hover;
Button(Widget* parent = nullptr);
[[nodiscard]] auto size() const noexcept -> Size override;
[[nodiscard]] virtual auto text() const noexcept -> const std::string&;
virtual auto text(const std::string&) -> Button*;
};
}
#endif