Update widgets module. Raster example initial.

This commit is contained in:
IlyaShurupov 2024-04-12 15:27:40 +03:00 committed by Ilya Shurupov
parent aa10424fbb
commit 90244934d9
48 changed files with 1169 additions and 530 deletions

View file

@ -7,40 +7,15 @@ namespace tp {
template <typename Events, typename Canvas>
class ButtonWidget : public Widget<Events, Canvas> {
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");
}
ButtonWidget() { this->mArea = { 0, 0, 100, 100 }; }
ButtonWidget(const std::string& label, const tp::RectF& aArea) {
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 {
this->mArea = aArea;
this->mVisible = areaParent.isOverlap(aArea);
if (!this->mVisible) return;
mIsHover = false;
if (!areaParent.isOverlap(aArea)) {
mIsReleased = false;
mIsPressed = false;
return;
}
mIsHover = aArea.isInside(events.getPointer());
void procBody(const Events& events) {
mIsHover = this->mArea.isInside(events.getPointer());
if (events.isPressed(InputID::MOUSE1) && mIsHover) {
mIsPressed = true;
@ -53,26 +28,46 @@ namespace tp {
if (!mIsHover) mIsPressed = false;
mLabel.proc(events, aArea, aArea);
mLabel.proc(events, this->mArea, this->mArea);
}
void draw(Canvas& canvas) override {
if (!this->mVisible) return;
void drawBody(Canvas& canvas) override {
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 updateConfigCache(WidgetManager& wm) override {
wm.setActiveId("Button");
pressedColor = wm.getColor("Pressed", "Action");
hoveredColor = wm.getColor("Hovered", "Interaction");
accentColor = wm.getColor("Default", "Accent");
rounding = wm.getNumber("Rounding", "Rounding");
// mPressEvent = wm.getEventState("Activate", { { InputID::MOUSE1, InputState::PRESSED } });
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;
InputState mPressEvent;
};
}