This commit is contained in:
IlyaShurupov 2024-05-03 15:09:26 +03:00
parent 86a41c1876
commit e2072d257f
14 changed files with 594 additions and 341 deletions

View file

@ -9,22 +9,13 @@ namespace tp {
public:
ButtonWidget() {
this->mArea = { 0, 0, 100, 100 };
this->createConfig("Button");
this->addColor("Pressed", "Action");
this->addColor("Hovered", "Interaction");
this->addColor("Default", "Accent");
this->addValue("Rounding", "Rounding");
this->mId = "Button";
}
ButtonWidget(const std::string& label, const tp::RectF& aArea) {
this->mId = "Button";
this->mArea = aArea;
this->mLabel.mLabel = label;
this->createConfig("Button");
this->addColor("Pressed", "Action");
this->addColor("Hovered", "Interaction");
this->addColor("Default", "Accent");
this->addValue("Rounding", "Rounding");
}
void proc(const Events& events, const tp::RectF& areaParent, const tp::RectF& aArea) override {
@ -60,19 +51,45 @@ namespace tp {
if (!this->mVisible) return;
if (mIsPressed) {
canvas.rect(this->mArea, this->getColor("Pressed"), this->getValue("Rounding"));
canvas.rect(this->mArea, pressedColor, rounding);
} else if (mIsHover) {
canvas.rect(this->mArea, this->getColor("Hovered"), this->getValue("Rounding"));
canvas.rect(this->mArea, hoveredColor, rounding);
} else {
canvas.rect(this->mArea, this->getColor("Default"), this->getValue("Rounding"));
canvas.rect(this->mArea, accentColor, rounding);
}
mLabel.draw(canvas);
}
public:
void setupConfig(WidgetManager& wm) {
if (!wm.createWidgetConfig(this->mId)) return;
wm.addReference(this->mId, "Pressed", "Action");
wm.addReference(this->mId, "Hovered", "Interaction");
wm.addReference(this->mId, "Default", "Accent");
wm.addReference(this->mId, "Rounding", "Rounding");
mLabel.setupConfig(wm);
}
void updateConfigCache(const WidgetManager& wm) override {
pressedColor = wm.getColor(this->mId, "Pressed");
hoveredColor = wm.getColor(this->mId, "Hovered");
accentColor = wm.getColor(this->mId, "Default");
rounding = wm.getNumber(this->mId, "Rounding");
mLabel.updateConfigCache(wm);
}
public:
LabelWidget<Events, Canvas> mLabel;
bool mIsHover = false;
bool mIsPressed = false;
bool mIsReleased = false;
RGBA pressedColor;
RGBA hoveredColor;
RGBA accentColor;
halnf rounding = 0;
};
}