81 lines
2.1 KiB
C++

#pragma once
#if !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_GUI_BUTTON_HPP_INCLUDED)
#define SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_GUI_BUTTON_HPP_INCLUDED 1
#include <glm/vec4.hpp>
#include <mijin/async/signal.hpp>
#include "./widget.hpp"
namespace sdl_gpu_test
{
struct ButtonCreateArgs
{
std::string text;
glm::vec4 textColor = {1.f, 1.f, 1.f, 1.f};
glm::vec4 backgroundColor = {1.f, 0.f, 0.f, 1.f};
glm::vec4 hoveredColor = {1.f, 0.9f, 0.9f, 1.f};
int posX = 0;
int posY = 0;
int width = 256;
int height = 84;
};
class Button : public Widget
{
public:
using create_args_t = ButtonCreateArgs;
private:
std::string mText;
glm::vec4 mTextColor;
glm::vec4 mBackgroundColor;
glm::vec4 mHoveredColor;
int mPosX = 0;
int mPosY = 0;
int mWidth = 0;
int mHeight = 0;
bool mHovered = false;
UIRenderer::primitive_id_t mPrimitiveID = UIRenderer::UNSET_PRIMITIVE_ID;
public:
explicit Button(ButtonCreateArgs args);
[[nodiscard]]
const std::string& getText() const noexcept { return mText; }
[[nodiscard]]
const glm::vec4& getTextColor() const noexcept { return mTextColor; }
[[nodiscard]]
const glm::vec4& getBackgroundColor() const noexcept { return mBackgroundColor; }
[[nodiscard]]
const glm::vec4& getHoveredColor() const noexcept { return mHoveredColor; }
[[nodiscard]]
int getPosX() const noexcept { return mPosX; }
[[nodiscard]]
int getPosY() const noexcept { return mPosY; }
void setText(std::string text);
void setTextColor(const glm::vec4& color);
void setBackgroundColor(const glm::vec4& color);
void setHoveredColor(const glm::vec4& color);
void setPosX(int posX);
void setPosY(int posY);
void handleEnteredTree() override;
void handleMouseMotion(const sdlpp::MouseMotionEvent& event) override;
void handleMouseButton(const sdlpp::MouseButtonEvent&) override;
void revalidate() override;
private:
void update();
public:
mijin::Signal<> clicked;
};
} // namespace sdl_gpu_test
#endif // !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_GUI_BUTTON_HPP_INCLUDED)