63 lines
1.4 KiB
C++
63 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "ButtonData.h"
|
|
#include "Widget.h"
|
|
#include "Color.h"
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
|
|
class PaintEvent;
|
|
class MouseEvent;
|
|
class TextNode;
|
|
|
|
class Button : public Widget
|
|
{
|
|
public:
|
|
using clickFunc = std::function<void(Widget* self)>;
|
|
|
|
Button(ButtonData::Component component = ButtonData::Component::Elevated);
|
|
|
|
~Button();
|
|
|
|
static std::unique_ptr<Button> Create(ButtonData::Component component = ButtonData::Component::Elevated);
|
|
|
|
void setLabel(const std::string& text);
|
|
|
|
void setEnabled(bool isEnabled);
|
|
|
|
void setOnClickFunction(clickFunc func);
|
|
|
|
protected:
|
|
void onMyMouseEvent(const MouseEvent* event) override;
|
|
|
|
bool isDirty() const override;
|
|
void doPaint(const PaintEvent* event) override;
|
|
|
|
void setLabelTextColor(Theme::Sys::Color color);
|
|
void setLabelTextOpacity(float opacity);
|
|
void setLabelTextTypescale(Theme::Sys::Typescale typescale);
|
|
|
|
void updateLabel(const PaintEvent* event);
|
|
|
|
void setState(ButtonData::State state);
|
|
void resetState();
|
|
void updateState() override;
|
|
|
|
private:
|
|
ButtonData mStyle;
|
|
|
|
std::string mLabel;
|
|
Theme::Sys::Color mLabelTextColor;
|
|
Theme::Sys::Typescale mLabelTextTypescale;
|
|
float mLabelOpacity{ 1.0 };
|
|
|
|
clickFunc mClickFunc;
|
|
|
|
std::unique_ptr<TextNode> mTextNode;
|
|
bool mContentDirty{true};
|
|
|
|
bool mEnabled{ true };
|
|
};
|
|
|
|
using ButtonUPtr = std::unique_ptr<Button>;
|